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