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