Type size can now be in bits or bytes
[libfirm] / firmjni / auxilliary / Heapanal.c
1 /* -*- c -*- */
2
3 # include "Heapanal.h"
4
5 # include "libfirm/firm.h"
6 # include "irsimpletype.h"
7 # include "heapanal/heapanal.h"
8
9 /*  boilerplate stuff: */
10 #include "libfirm/irvrfy.h"
11 #include "libfirm/trvrfy.h"
12 #include "libfirm/irdump.h"
13
14
15 /*  I/O: */
16 # include <stdio.h>
17
18 /*
19  * Class:     firmjni_Heapanal
20  * Method:    initAnal
21  * Signature: ()V
22  */
23 void Java_firmjni_Heapanal_initAnal (JNIEnv *env, jclass clazz)
24 {
25   /*  from interprete.c:  */
26   init_interprete ();
27 }
28
29 /*
30  * Class:     firmjni_Heapanal
31  * Method:    deInitAnal
32  * Signature: ()V
33  */
34 void Java_firmjni_Heapanal_deInitAnal (JNIEnv *env, jclass clazz)
35 {
36   free_interprete ();
37 }
38
39 /*
40  * Class:     firmjni_Heapanal
41  * Method:    analHeap
42  * Signature: (I)V
43  */
44 void Java_firmjni_Heapanal_analHeap__I (JNIEnv *env, jclass clazz, jint fMethod)
45 {
46   ha_analyse_heap((entity *) fMethod, 0);
47 }
48
49 /*
50  * Class:     firmjni_Heapanal
51  * Method:    analHeap
52  * Signature: ()V
53  */
54 void Java_firmjni_Heapanal_analHeap__ (JNIEnv *env, jclass clazz)
55 {
56   int n_graphs;
57   int i;
58
59   fprintf (stdout, "Hello, Heap!\n");
60
61   fprintf (stdout, "Ajacs Boilerplate:\n");
62   {
63     entity **free_methods = 0;
64     int arr_len = 0;
65
66     /* replace static constant fields by constants
67        @@@ This corrects some code that is invalid Firm!!!
68        Execute before irg_vrfy(). */
69     /* ??? */
70     /*  opt_load_const_static(); */
71
72     /* dump graphs as they come out of the front end */
73     dump_file_suffix = "-fe";
74     dump_all_types ();
75     dump_class_hierarchy (true);
76     dump_all_ir_graphs(dump_ir_block_graph);
77     dump_all_ir_graphs(dump_ir_block_graph_w_types);
78     dump_all_ir_graphs(dump_cfg);
79
80     /* verify constructed graphs */
81     for (i = 0; i < get_irp_n_irgs(); i++)
82       irg_vrfy(get_irp_irg(i));
83
84     /* verify something */
85     tr_vrfy();
86
87
88     /*
89      * test loop construction intraprocedural
90      */
91     for (i = 0; i < get_irp_n_irgs(); i++) {
92       construct_backedges(get_irp_irg(i));
93
94       if (1) {
95         dump_loop_information();
96         dump_file_suffix = "-1.2-intra-loop";
97         dump_ir_block_graph(get_irp_irg(i));
98         dont_dump_loop_information();
99         dump_loop_tree(get_irp_irg(i), "-1.2-intra");
100       }
101     }
102
103     DDMG (get_irp_main_irg ());
104     assert(get_irp_main_irg());
105     assert(get_irg_ent(get_irp_main_irg()));
106
107
108     /** Do interprocedural optimizations **/
109     /* Analysis that builds the call graph and finds the free methods,
110        i.e. methods that are dereferenced.
111        Optimizes polymorphic calls.*/
112     cgana(&arr_len, &free_methods);
113     /* Remove methods that are never called. */
114     /*  gc_irgs(arr_len, free_methods); */
115     /* Build the interprocedural dataflow representation */
116     cg_construct(arr_len, free_methods);
117
118     /* Test construction of interprocedural loop information */
119     /*  construct_ip_backedges(); */
120
121     dump_loop_information();
122     dump_file_suffix = "-1.2-inter-loop";
123     dump_all_cg_block_graph();
124     dont_dump_loop_information();
125     dump_loop_tree(get_irp_main_irg(), "-1.2-inter");
126
127
128     fprintf (stdout, "HA:\n");
129     DDMG (get_irp_main_irg ());
130
131     set_max_chi_height(8);  /* change ad lib */
132     set_initial_context_depth(4);   /* change as needed */
133     ha_analyse_heap(get_irg_ent(get_irp_main_irg()), 1);
134
135     /* Remove the interprocedural dataflow representation */
136     free(free_methods);
137     cg_destruct();
138
139     /* verify optimized graphs */
140     for (i = 0; i < get_irp_n_irgs(); i++) {
141       irg_vrfy(get_irp_irg(i));
142     }
143
144     tr_vrfy();
145
146   }
147
148   set_opt_dump_abstvals (1);
149
150   /* ToDo:  Dump ??? */
151
152   fprintf (stdout, "Bye,   Heap!\n");
153 }
154
155
156
157 /*
158  * $Log$
159  * Revision 1.3  2004/04/30 09:00:01  goetz
160  * added configure support for heap analyses
161  *
162  * Revision 1.2  2004/04/29 13:59:11  liekweg
163  * Removed C++-Style comments --flo
164  *
165  * Revision 1.1  2004/04/29 12:11:36  liekweg
166  * Moved ... to aux --flo
167  *
168  * Revision 1.1  2004/04/27 12:41:31  liekweg
169  * Fixed ir/ana/irouts.c ir/ir/ircons.h ir/ir/irdump.c --flo
170  * Added aux/Heapanal.c aux/Heapanal.java --flo
171  *
172  */