added some name convetions
[libfirm] / ir / ir / irgraph.c
1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
3 **
4 ** Authors: Martin Trapp, Christian Schaefer
5 **
6 **
7 */
8
9 # include "ircons.h"
10 # include "irgraph.h"
11 # include "irprog.h"
12 # include "iropt.h"
13 # include "array.h"
14 # include "irgmod.h"
15
16 ir_graph *current_ir_graph;
17
18 /* Allocates a list of nodes:
19     - The start block containing a start node and Proj nodes for it's four
20       results (X, M, P, Tuple).
21     - The end block containing an end node. This block is not matured after
22       new_ir_graph as predecessors need to be added to it.
23     - The current block, which is empty and also not matured.
24    Further it allocates several datastructures needed for graph construction
25    and optimization.
26 */
27 ir_graph *
28 new_ir_graph (entity *ent, int params)
29 {
30   ir_graph *res;
31   ir_node *first_block;
32   ir_node *projX;
33
34   res = (ir_graph *) malloc (sizeof (ir_graph));
35   current_ir_graph = res;
36   add_irp_irg(res);          /* remember this graph global. */
37
38   /** Internal information for graph construction either held in the graph or
39   *** initialized for each graph. **/
40   res->params = params + 1;  /* number of local variables that are never
41                                 dereferenced in this graph plus one for
42                                 the store. This is not the number of parameters
43                                 to the procedure!  */
44   res->visited = 0;     /* visited flag, for the ir walker */
45   res->block_visited=0; /* visited flag, for the 'block'-walker */
46
47 #if USE_EXPICIT_PHI_IN_STACK
48   res->Phi_in_stack = new_Phi_in_stack();  /* A stack needed for automatic Phi
49                                 generation */
50 #endif
51   res->obst      = (struct obstack *) xmalloc (sizeof (struct obstack));
52   obstack_init (res->obst);
53   res->value_table = new_identities (); /* value table for global value numbering
54                                       for optimizing use in iropt.c */
55
56   /** Type inforamtion for the procedure of the graph **/
57   res->ent = ent;
58
59   /** Nodes needed in every graph **/
60   res->end_block = new_Block ();
61   res->end       = new_End ();
62
63   res->start_block = new_Block ();
64   res->start     = new_Start ();
65   res->bad       = new_ir_node (res, res->start_block, op_Bad, mode_T, 0, NULL);
66
67   /* Proj results of start node */
68   projX        = new_Proj (res->start, mode_X, pns_initial_exec);
69   set_store (new_Proj (res->start, mode_M, pns_global_store));
70   res->frame   = new_Proj (res->start, mode_p, pns_frame_base);
71   res->globals = new_Proj (res->start, mode_p, pns_globals);
72   res->args    = new_Proj (res->start, mode_T, pns_args);
73
74   add_in_edge(res->start_block, projX);
75   // The code generation needs it. leave it in now.
76   // Use of this edge is matter of discussion, unresolved. Also possible:
77   // add_in_edge(res->start_block, res->start_block), but invalid typed.
78
79   mature_block (res->current_block);
80
81   /** Make a block to start with **/
82   first_block = new_Block ();
83   add_in_edge (first_block, projX);
84
85   return res;
86 }
87
88 /* access routines for all ir_graph attributes:
89    templates:
90    {attr type} get_irg_{attribute name} (ir_graph *irg);
91    void set_irg_{attr name} (ir_graph *irg, {attr type} {attr}); */
92
93 ir_node *
94 get_irg_start_block (ir_graph *irg)
95 {
96   return irg->start_block;
97 }
98
99 void
100 set_irg_start_block (ir_graph *irg, ir_node *node)
101 {
102   irg->start_block = node;
103 }
104
105 ir_node *
106 get_irg_start (ir_graph *irg)
107 {
108   return irg->start;
109 }
110
111 void
112 set_irg_start(ir_graph *irg, ir_node *node)
113 {
114   irg->start = node;
115 }
116
117 ir_node *
118 get_irg_end_block (ir_graph *irg)
119 {
120   return irg->end_block;
121 }
122
123 void
124 set_irg_end_block (ir_graph *irg, ir_node *node)
125 {
126   irg->end_block = node;
127 }
128
129 ir_node *
130 get_irg_end (ir_graph *irg)
131 {
132   return irg->end;
133 }
134
135 void
136 set_irg_end (ir_graph *irg, ir_node *node)
137 {
138   irg->end = node;
139 }
140
141 ir_node *
142 get_irg_cstore (ir_graph *irg)
143 {
144   return irg->cstore;
145 }
146
147 void
148 set_irg_cstore (ir_graph *irg, ir_node *node)
149 {
150   irg->cstore = node;
151 }
152
153 ir_node *
154 get_irg_frame (ir_graph *irg)
155 {
156   return irg->frame;
157 }
158
159 void
160 set_irg_frame (ir_graph *irg, ir_node *node)
161 {
162   irg->frame = node;
163 }
164
165 ir_node *
166 get_irg_globals (ir_graph *irg)
167 {
168   return irg->globals;
169 }
170
171 void
172 set_irg_globals (ir_graph *irg, ir_node *node)
173 {
174   irg->globals = node;
175 }
176
177 ir_node *
178 get_irg_args (ir_graph *irg)
179 {
180   return irg->args;
181 }
182
183 void
184 set_irg_args (ir_graph *irg, ir_node *node)
185 {
186   irg->args = node;
187 }
188
189 ir_node *
190 get_irg_bad (ir_graph *irg)
191 {
192   return irg->bad;
193 }
194
195 void
196 set_irg_bad (ir_graph *irg, ir_node *node)
197 {
198   irg->bad = node;
199 }
200
201 ir_node *
202 get_irg_current_block (ir_graph *irg)
203 {
204   return irg->current_block;
205 }
206
207 void
208 set_irg_current_block (ir_graph *irg, ir_node *node)
209 {
210   irg->current_block = node;
211 }
212
213 entity *
214 get_irg_ent (ir_graph *irg)
215 {
216   return irg->ent;
217 }
218
219 void
220 set_irg_ent (ir_graph *irg, entity *ent)
221 {
222   irg->ent = ent;
223 }
224
225 int
226 get_irg_params (ir_graph *irg)
227 {
228   return irg->params;
229 }
230
231 void
232 set_irg_params (ir_graph *irg, int params)
233 {
234   irg->params = params;
235 }
236
237 unsigned long
238 get_irg_visited (ir_graph *irg)
239 {
240   return irg->visited;
241 }
242
243 void
244 set_irg_visited (ir_graph *irg, unsigned long visited)
245 {
246   irg->visited = visited;
247 }
248
249 void
250 inc_irg_visited (ir_graph *irg)
251 {
252   irg->visited = irg->visited++;
253 }
254
255 unsigned long
256 get_irg_block_visited (ir_graph *irg)
257 {
258   return irg->block_visited;
259 }
260
261 void
262 set_irg_block_visited (ir_graph *irg, unsigned long visited)
263 {
264   irg->block_visited = visited;
265 }
266
267 void
268 inc_irg_block_visited (ir_graph *irg)
269 {
270   irg->block_visited = irg->block_visited++;
271 }