1f78f26aa8c56065fd0c2ee3dc6e2edec3fb20b1
[libfirm] / ir / ir / irgraph_t.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/ir/irgraph.c
4  * Purpose:     Entry point to the representation of procedure code -- internal header.
5  * Author:      Martin Trapp, Christian Schaefer
6  * Modified by: Goetz Lindenmaier
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1998-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13 /**
14  * @file irgraph_t.h
15  *
16  * ir graph construction.
17  *
18  * @author Martin Trapp, Christian Schaefer
19  */
20
21
22 # ifndef _IRGRAPH_T_H_
23 # define _IRGRAPH_T_H_
24 # include "obst.h"
25 # include "pset.h"
26 # include "irgraph.h"
27 # include "firm_common_t.h"
28 # include "irtypeinfo.h"
29
30 #define FRAME_TP_SUFFIX "frame_tp"
31
32 /** ir_graph holds all information for a procedure */
33 struct ir_graph {
34   firm_kind         kind;            /**<  always set to k_ir_graph*/
35   /* --  Basics of the representation -- */
36   struct entity  *ent;               /**< The entity of this procedure, i.e.,
37                     the type of the procedure and the
38                     class it belongs to. */
39   struct type    *frame_type;    /**< A class type representing the stack frame.
40                                     Can include "inner" methods. */
41   struct ir_node *start_block;   /**< block the start node will belong to */
42   struct ir_node *start;         /**< start node of this ir_graph */
43   struct ir_node *end_block;     /**< block the end node will belong to */
44   struct ir_node *end;           /**< end node of this ir_graph */
45   struct ir_node *end_reg;       /**< end node of this ir_graph */
46   struct ir_node *end_except;    /**< end node of this ir_graph */
47   struct ir_node *cstore;        /**< constant store -- no more needed!! */
48   struct ir_node *frame;         /**< method's frame */
49   struct ir_node *globals;       /**< pointer to the data segment containing all
50                                     globals as well as global procedures. */
51   struct ir_node *initial_mem;   /**< initial memory of this graph */
52   struct ir_node *args;          /**< methods arguments */
53   struct ir_node *bad;           /**< bad node of this ir_graph, the one and
54                                     only in this graph */
55   /* GL removed: we need unknown with mode for analyses. */
56   /*   struct ir_node *unknown;*/           /**< unknown node of this ir_graph */
57   struct obstack *obst;          /**< obstack where all of the ir_nodes live */
58   struct ir_node *current_block;     /**< block for newly gen_*()-erated
59                     ir_nodes */
60
61   /* -- Fields indicating different states of irgraph -- */
62   irg_phase_state phase_state;       /**< compiler phase */
63   op_pin_state op_pin_state_pinned;  /**< Flag for status of nodes */
64   irg_outs_state outs_state;         /**< Out edges. */
65   irg_dom_state dom_state;           /**< Dominator information */
66   irg_typeinfo_state typeinfo_state;       /**< Validity of type information */
67   irg_callee_info_state callee_info_state; /**< Validity of callee information */
68   irg_inline_property inline_property;     /**< How to handle inlineing. */
69   irg_loopinfo_state loopinfo_state;       /**< state of loop information */
70
71   /* -- Fields for construction -- */
72 #if USE_EXPLICIT_PHI_IN_STACK
73   struct Phi_in_stack *Phi_in_stack; /**< needed for automatic Phi construction */
74 #endif
75   int n_loc;                         /**< number of local variable in this
76                                         procedure including procedure parameters. */
77
78   /* -- Fields for optimizations / analysis information -- */
79   pset *value_table;                 /**< hash table for global value numbering (cse)
80                                         for optimizing use in iropt.c */
81   struct ir_node **outs;             /**< Space for the out arrays. */
82
83 #ifdef DEBUG_libfirm
84   int             n_outs;            /* < Size wasted for outs */
85 #endif /* defined DEBUG_libfirm */
86   struct ir_loop *loop;              /**< The outermost loop */
87   void *link;                        /**< A void* field to link any information to
88                     the node. */
89
90   ir_graph **callers;                /**< For callgraph analyses. */
91   int       *caller_isbe;            /**< For callgraph analyses: set if backedge. */
92   ir_graph **callees;                /**< For callgraph analyses. */
93   int       *callee_isbe;            /**< For callgraph analyses: set if backedge. */
94
95   /* -- Fields for Walking the graph -- */
96   unsigned long visited;             /**< this flag is an identifier for
97                                         ir walk. it will be incremented
98                                         every time someone walks through
99                                         the graph */
100   unsigned long block_visited;       /**< same as visited, for a complete block */
101 #ifdef DEBUG_libfirm
102   int graph_nr;             /**< a unique graph number for each graph to make output
103                                readable. */
104 #endif
105 };
106
107 void init_irgraph(void);
108
109 /** Make a rudimentary ir graph for the constant code.
110    Must look like a correct irg, spare everything else. */
111 ir_graph *new_const_code_irg(void);
112
113 /**
114  * Set the op_pin_state_pinned state of a graph.
115  *
116  * @irg     the IR graph
117  * @p       new pin state
118  */
119 INLINE void
120 set_irg_pinned (ir_graph *irg, op_pin_state p);
121
122 /** Returns the obstack associated with the graph. */
123 struct obstack *get_irg_obstack(ir_graph *irg);
124
125 /**
126  * Returns true if the node n is allocated on the storage of graph irg.
127  *
128  * @param irg   the IR graph
129  * @param n the IR node
130  */
131 int node_is_in_irgs_storage(ir_graph *irg, ir_node *n);
132
133 /*-------------------------------------------------------------------*/
134 /* inline functions for graphs                                       */
135 /*-------------------------------------------------------------------*/
136
137 static INLINE int
138 __is_ir_graph(void *thing) {
139   return (get_kind(thing) == k_ir_graph);
140 }
141
142 /** Returns the start block of a graph. */
143 static INLINE ir_node *
144 __get_irg_start_block(ir_graph *irg)
145 {
146   return irg->start_block;
147 }
148
149 static INLINE void
150 __set_irg_start_block(ir_graph *irg, ir_node *node)
151 {
152   irg->start_block = node;
153 }
154
155 static INLINE ir_node *
156 __get_irg_start(ir_graph *irg)
157 {
158   return irg->start;
159 }
160
161 static INLINE void
162 __set_irg_start(ir_graph *irg, ir_node *node)
163 {
164   irg->start = node;
165 }
166
167 static INLINE ir_node *
168 __get_irg_end_block(ir_graph *irg)
169 {
170   return irg->end_block;
171 }
172
173 static INLINE void
174 __set_irg_end_block(ir_graph *irg, ir_node *node)
175 {
176   irg->end_block = node;
177 }
178
179 static INLINE ir_node *
180 __get_irg_end(ir_graph *irg)
181 {
182   return irg->end;
183 }
184
185 static INLINE void
186 __set_irg_end(ir_graph *irg, ir_node *node)
187 {
188   irg->end = node;
189 }
190
191 static INLINE ir_node *
192 __get_irg_end_reg(ir_graph *irg) {
193   return irg->end_reg;
194 }
195
196 static INLINE ir_node *
197 __get_irg_end_except (ir_graph *irg) {
198   return irg->end_except;
199 }
200
201 static INLINE ir_node *
202 __get_irg_cstore(ir_graph *irg)
203 {
204   return irg->cstore;
205 }
206
207 static INLINE void
208 __set_irg_cstore(ir_graph *irg, ir_node *node)
209 {
210   irg->cstore = node;
211 }
212
213 static INLINE ir_node *
214 __get_irg_frame(ir_graph *irg)
215 {
216   return irg->frame;
217 }
218
219 static INLINE void
220 __set_irg_frame(ir_graph *irg, ir_node *node)
221 {
222   irg->frame = node;
223 }
224
225 static INLINE ir_node *
226 __get_irg_globals(ir_graph *irg)
227 {
228   return irg->globals;
229 }
230
231 static INLINE void
232 __set_irg_globals(ir_graph *irg, ir_node *node)
233 {
234   irg->globals = node;
235 }
236
237 static INLINE ir_node *
238 __get_irg_initial_mem(ir_graph *irg)
239 {
240   return irg->initial_mem;
241 }
242
243 static INLINE void
244 __set_irg_initial_mem(ir_graph *irg, ir_node *node)
245 {
246   irg->initial_mem = node;
247 }
248
249 static INLINE ir_node *
250 __get_irg_args(ir_graph *irg)
251 {
252   return irg->args;
253 }
254
255 static INLINE void
256 __set_irg_args(ir_graph *irg, ir_node *node)
257 {
258   irg->args = node;
259 }
260
261 static INLINE ir_node *
262 __get_irg_bad(ir_graph *irg)
263 {
264   return irg->bad;
265 }
266
267 static INLINE void
268 __set_irg_bad(ir_graph *irg, ir_node *node)
269 {
270   irg->bad = node;
271 }
272
273 static INLINE ir_node *
274 __get_irg_current_block(ir_graph *irg)
275 {
276   return irg->current_block;
277 }
278
279 static INLINE void
280 __set_irg_current_block(ir_graph *irg, ir_node *node)
281 {
282   irg->current_block = node;
283 }
284
285 static INLINE entity *
286 __get_irg_ent(ir_graph *irg)
287 {
288   assert(irg && irg->ent);
289   return irg->ent;
290 }
291
292 static INLINE void
293 __set_irg_ent(ir_graph *irg, entity *ent)
294 {
295   irg->ent = ent;
296 }
297
298 static INLINE type *
299 __get_irg_frame_type(ir_graph *irg)
300 {
301   assert(irg && irg->frame_type);
302   return irg->frame_type;
303 }
304
305 static INLINE void
306 __set_irg_frame_type(ir_graph *irg, type *ftp)
307 {
308   assert(is_class_type(ftp));
309   irg->frame_type = ftp;
310 }
311
312 static INLINE struct obstack *
313 __get_irg_obstack(ir_graph *irg) {
314   return irg->obst;
315 }
316
317
318 static INLINE irg_phase_state
319 __get_irg_phase_state(ir_graph *irg) {
320   return irg->phase_state;
321 }
322
323 static INLINE void
324 __set_irg_phase_low(ir_graph *irg) {
325   irg->phase_state = phase_low;
326 }
327
328 static INLINE op_pin_state
329 __get_irg_pinned(ir_graph *irg) {
330   return irg->op_pin_state_pinned;
331 }
332
333 static INLINE irg_outs_state
334 __get_irg_outs_state(ir_graph *irg) {
335   return irg->outs_state;
336 }
337
338 static INLINE void
339 __set_irg_outs_inconsistent(ir_graph *irg) {
340   irg->outs_state = outs_inconsistent;
341 }
342
343 static INLINE irg_dom_state
344 __get_irg_dom_state(ir_graph *irg) {
345   return irg->dom_state;
346 }
347
348 static INLINE void
349 __set_irg_dom_inconsistent(ir_graph *irg) {
350   irg->dom_state = dom_inconsistent;
351 }
352
353 static INLINE irg_loopinfo_state
354 __get_irg_loopinfo_state(ir_graph *irg) {
355   return irg->loopinfo_state;
356 }
357
358 static INLINE void
359 __set_irg_loopinfo_state(ir_graph *irg, irg_loopinfo_state s) {
360   irg->loopinfo_state = s;
361 }
362
363 static INLINE void
364 __set_irg_pinned(ir_graph *irg, op_pin_state p) {
365   irg->op_pin_state_pinned = p;
366 }
367
368 static INLINE irg_callee_info_state
369 __get_irg_callee_info_state(ir_graph *irg) {
370   return irg->callee_info_state;
371 }
372
373 static INLINE void
374 __set_irg_callee_info_state(ir_graph *irg, irg_callee_info_state s) {
375   irg->callee_info_state = s;
376 }
377
378 static INLINE irg_inline_property
379 __get_irg_inline_property(ir_graph *irg) {
380   return irg->inline_property;
381 }
382
383 static INLINE void
384 __set_irg_inline_property(ir_graph *irg, irg_inline_property s) {
385   irg->inline_property = s;
386 }
387
388 static INLINE void
389 __set_irg_link(ir_graph *irg, void *thing) {
390   irg->link = thing;
391 }
392
393 static INLINE void *
394 __get_irg_link(ir_graph *irg) {
395   return irg->link;
396 }
397
398 static INLINE unsigned long
399 __get_irg_visited(ir_graph *irg)
400 {
401   return irg->visited;
402 }
403
404 static INLINE unsigned long
405 __get_irg_block_visited(ir_graph *irg)
406 {
407   return irg->block_visited;
408 }
409
410 static INLINE void
411 __set_irg_block_visited(ir_graph *irg, unsigned long visited)
412 {
413   irg->block_visited = visited;
414 }
415
416 static INLINE void
417 __inc_irg_block_visited(ir_graph *irg)
418 {
419   ++irg->block_visited;
420 }
421
422 #define is_ir_graph(thing)                 __is_ir_graph(thing)
423 #define get_irg_start_block(irg)           __get_irg_start_block(irg)
424 #define set_irg_start_block(irg, node)     __set_irg_start_block(irg, node)
425 #define get_irg_start(irg)                 __get_irg_start(irg)
426 #define set_irg_start(irg, node)           __set_irg_start(irg, node)
427 #define get_irg_end_block(irg)             __get_irg_end_block(irg)
428 #define set_irg_end_block(irg, node)       __set_irg_end_block(irg, node)
429 #define get_irg_end(irg)                   __get_irg_end(irg)
430 #define set_irg_end(irg, node)             __set_irg_end(irg, node)
431 #define get_irg_end_reg(irg)               __get_irg_end_reg(irg)
432 #define get_irg_end_except(irg)            __get_irg_end_except(irg)
433 #define get_irg_cstore(irg)                __get_irg_cstore(irg)
434 #define set_irg_cstore(irg, node)          __set_irg_cstore(irg, node)
435 #define get_irg_frame(irg)                 __get_irg_frame(irg)
436 #define set_irg_frame(irg, node)           __set_irg_frame(irg, node)
437 #define get_irg_globals(irg)               __get_irg_globals(irg)
438 #define set_irg_globals(irg, node)         __set_irg_globals(irg, node)
439 #define get_irg_initial_mem(irg)           __get_irg_initial_mem(irg)
440 #define set_irg_initial_mem(irg, node)     __set_irg_initial_mem(irg, node)
441 #define get_irg_args(irg)                  __get_irg_args(irg)
442 #define set_irg_args(irg, node)            __set_irg_args(irg, node)
443 #define get_irg_bad(irg)                   __get_irg_bad(irg)
444 #define set_irg_bad(irg, node)             __set_irg_bad(irg, node)
445 #define get_irg_current_block(irg)         __get_irg_current_block(irg)
446 #define set_irg_current_block(irg, node)   __set_irg_current_block(irg, node)
447 #define get_irg_entity(irg)                   __get_irg_ent(irg)
448 #define set_irg_entity(irg, ent)              __set_irg_ent(irg, ent)
449 #define get_irg_frame_type(irg)            __get_irg_frame_type(irg)
450 #define set_irg_frame_type(irg, ftp)       __set_irg_frame_type(irg, ftp)
451 #define get_irg_obstack(irg)               __get_irg_obstack(irg)
452 #define get_irg_phase_state(irg)           __get_irg_phase_state(irg)
453 #define set_irg_phase_low(irg)             __set_irg_phase_low(irg)
454 #define get_irg_pinned(irg)                __get_irg_pinned(irg)
455 #define get_irg_outs_state(irg)            __get_irg_outs_state(irg)
456 #define set_irg_outs_inconsistent(irg)     __set_irg_outs_inconsistent(irg)
457 #define get_irg_dom_state(irg)             __get_irg_dom_state(irg)
458 #define set_irg_dom_inconsistent(irg)      __set_irg_dom_inconsistent(irg)
459 #define get_irg_loopinfo_state(irg)        __get_irg_loopinfo_state(irg)
460 #define set_irg_loopinfo_state(irg, s)     __set_irg_loopinfo_state(irg, s)
461 #define set_irg_pinned(irg, p)             __set_irg_pinned(irg, p)
462 #define get_irg_callee_info_state(irg)     __get_irg_callee_info_state(irg)
463 #define set_irg_callee_info_state(irg, s)  __set_irg_callee_info_state(irg, s)
464 #define get_irg_inline_property(irg)       __get_irg_inline_property(irg)
465 #define set_irg_inline_property(irg, s)    __set_irg_inline_property(irg, s)
466 #define set_irg_link(irg, thing)           __set_irg_link(irg, thing)
467 #define get_irg_link(irg)                  __get_irg_link(irg)
468 #define get_irg_visited(irg)               __get_irg_visited(irg)
469 #define get_irg_block_visited(irg)         __get_irg_block_visited(irg)
470 #define set_irg_block_visited(irg, v)      __set_irg_block_visited(irg, v)
471 #define inc_irg_block_visited(irg)         __inc_irg_block_visited(irg)
472
473 # endif /* _IRGRAPH_T_H_ */