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