Update NEWS.
[libfirm] / firmjni / auxilliary / Heapanal.c
1 /* -*- c -*- */
2
3 # include "Heapanal.h"
4
5 # include "firm.h"
6 # include "irsimpletype.h"
7 # include "heapanal/heapanal.h"
8
9 /*  boilerplate stuff: */
10 #include "irvrfy.h"
11 #include "trvrfy.h"
12 #include "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     char *suffix = "-fe";
74     dump_all_types (suffix);
75     dump_class_hierarchy (true, suffix);
76     dump_all_ir_graphs(dump_ir_block_graph, suffix);
77     dump_all_ir_graphs(dump_ir_block_graph_w_types, suffix);
78     dump_all_ir_graphs(dump_cfg, suffix);
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(1);
96         dump_ir_block_graph(get_irp_irg(i), "-1.2-intra-loop");
97         dump_loop_information(0);
98         dump_loop_tree(get_irp_irg(i), "-1.2-intra");
99       }
100     }
101
102     DDMG (get_irp_main_irg ());
103     assert(get_irp_main_irg());
104     assert(get_irg_entity(get_irp_main_irg()));
105
106
107     /** Do interprocedural optimizations **/
108     /* Analysis that builds the call graph and finds the free methods,
109        i.e. methods that are dereferenced.
110        Optimizes polymorphic calls.*/
111     cgana(&arr_len, &free_methods);
112     /* Remove methods that are never called. */
113     /*  gc_irgs(arr_len, free_methods); */
114     /* Build the interprocedural dataflow representation */
115     cg_construct(arr_len, free_methods);
116
117     /* Test construction of interprocedural loop information */
118     /*  construct_ip_backedges(); */
119
120     dump_loop_information(1);
121     dump_all_cg_block_graph("-1.2-inter-loop");
122     dump_loop_information(0);
123     dump_loop_tree(get_irp_main_irg(), "-1.2-inter");
124
125
126     fprintf (stdout, "HA:\n");
127     DDMG (get_irp_main_irg ());
128
129     set_max_chi_height(8);  /* change ad lib */
130     set_initial_context_depth(4);   /* change as needed */
131     ha_analyse_heap(get_irg_entity(get_irp_main_irg()), 1);
132
133     /* Remove the interprocedural dataflow representation */
134     free(free_methods);
135     cg_destruct();
136
137     /* verify optimized graphs */
138     for (i = 0; i < get_irp_n_irgs(); i++) {
139       irg_vrfy(get_irp_irg(i));
140     }
141
142     tr_vrfy();
143
144   }
145
146   set_opt_dump_abstvals (1);
147
148   /* ToDo:  Dump ??? */
149
150   fprintf (stdout, "Bye,   Heap!\n");
151 }
152
153
154
155 /*
156  * $Log$
157  * Revision 1.6  2005/03/01 16:22:39  goetz
158  * changed irdump flag
159  *
160  * Revision 1.5  2004/11/15 12:38:16  goetz
161  * we need more and more libs at linking ...
162  * changed node numbers (unknown_entity)
163  *
164  * Revision 1.4  2004/08/14 10:09:52  goetz
165  * adapted to new semantics
166  *
167  * Revision 1.3  2004/04/30 09:00:01  goetz
168  * added configure support for heap analyses
169  *
170  * Revision 1.2  2004/04/29 13:59:11  liekweg
171  * Removed C++-Style comments --flo
172  *
173  * Revision 1.1  2004/04/29 12:11:36  liekweg
174  * Moved ... to aux --flo
175  *
176  * Revision 1.1  2004/04/27 12:41:31  liekweg
177  * Fixed ir/ana/irouts.c ir/ir/ircons.h ir/ir/irdump.c --flo
178  * Added aux/Heapanal.c aux/Heapanal.java --flo
179  *
180  */