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