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