removed include
[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 static INLINE int
147 __is_ir_graph(void *thing) {
148   return (get_kind(thing) == k_ir_graph);
149 }
150
151 /** Returns the start block of a graph. */
152 static INLINE ir_node *
153 __get_irg_start_block(ir_graph *irg)
154 {
155   return irg->start_block;
156 }
157
158 static INLINE void
159 __set_irg_start_block(ir_graph *irg, ir_node *node)
160 {
161   irg->start_block = node;
162 }
163
164 static INLINE ir_node *
165 __get_irg_start(ir_graph *irg)
166 {
167   return irg->start;
168 }
169
170 static INLINE void
171 __set_irg_start(ir_graph *irg, ir_node *node)
172 {
173   irg->start = node;
174 }
175
176 static INLINE ir_node *
177 __get_irg_end_block(ir_graph *irg)
178 {
179   return irg->end_block;
180 }
181
182 static INLINE void
183 __set_irg_end_block(ir_graph *irg, ir_node *node)
184 {
185   irg->end_block = node;
186 }
187
188 static INLINE ir_node *
189 __get_irg_end(ir_graph *irg)
190 {
191   return irg->end;
192 }
193
194 static INLINE void
195 __set_irg_end(ir_graph *irg, ir_node *node)
196 {
197   irg->end = node;
198 }
199
200 static INLINE ir_node *
201 __get_irg_end_reg(ir_graph *irg) {
202   return irg->end_reg;
203 }
204
205 static INLINE ir_node *
206 __get_irg_end_except (ir_graph *irg) {
207   return irg->end_except;
208 }
209
210 static INLINE ir_node *
211 __get_irg_cstore(ir_graph *irg)
212 {
213   return irg->cstore;
214 }
215
216 static INLINE void
217 __set_irg_cstore(ir_graph *irg, ir_node *node)
218 {
219   irg->cstore = node;
220 }
221
222 static INLINE ir_node *
223 __get_irg_frame(ir_graph *irg)
224 {
225   return irg->frame;
226 }
227
228 static INLINE void
229 __set_irg_frame(ir_graph *irg, ir_node *node)
230 {
231   irg->frame = node;
232 }
233
234 static INLINE ir_node *
235 __get_irg_globals(ir_graph *irg)
236 {
237   return irg->globals;
238 }
239
240 static INLINE void
241 __set_irg_globals(ir_graph *irg, ir_node *node)
242 {
243   irg->globals = node;
244 }
245
246 static INLINE ir_node *
247 __get_irg_initial_mem(ir_graph *irg)
248 {
249   return irg->initial_mem;
250 }
251
252 static INLINE void
253 __set_irg_initial_mem(ir_graph *irg, ir_node *node)
254 {
255   irg->initial_mem = node;
256 }
257
258 static INLINE ir_node *
259 __get_irg_args(ir_graph *irg)
260 {
261   return irg->args;
262 }
263
264 static INLINE void
265 __set_irg_args(ir_graph *irg, ir_node *node)
266 {
267   irg->args = node;
268 }
269
270 static INLINE ir_node *
271 __get_irg_bad(ir_graph *irg)
272 {
273   return irg->bad;
274 }
275
276 static INLINE void
277 __set_irg_bad(ir_graph *irg, ir_node *node)
278 {
279   irg->bad = node;
280 }
281
282 static INLINE ir_node *
283 __get_irg_current_block(ir_graph *irg)
284 {
285   return irg->current_block;
286 }
287
288 static INLINE void
289 __set_irg_current_block(ir_graph *irg, ir_node *node)
290 {
291   irg->current_block = node;
292 }
293
294 static INLINE entity *
295 __get_irg_ent(ir_graph *irg)
296 {
297   assert(irg && irg->ent);
298   return irg->ent;
299 }
300
301 static INLINE void
302 __set_irg_ent(ir_graph *irg, entity *ent)
303 {
304   irg->ent = ent;
305 }
306
307 static INLINE type *
308 __get_irg_frame_type(ir_graph *irg)
309 {
310   assert(irg && irg->frame_type);
311   return irg->frame_type;
312 }
313
314 static INLINE void
315 __set_irg_frame_type(ir_graph *irg, type *ftp)
316 {
317   assert(is_class_type(ftp));
318   irg->frame_type = ftp;
319 }
320
321 static INLINE struct obstack *
322 __get_irg_obstack(ir_graph *irg) {
323   return irg->obst;
324 }
325
326
327 static INLINE irg_phase_state
328 __get_irg_phase_state(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(ir_graph *irg) {
339   return irg->op_pin_state_pinned;
340 }
341
342 static INLINE irg_outs_state
343 __get_irg_outs_state(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(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(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(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(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(ir_graph *irg) {
411   return irg->link;
412 }
413
414 static INLINE unsigned long
415 __get_irg_visited(ir_graph *irg)
416 {
417   return irg->visited;
418 }
419
420 static INLINE unsigned long
421 __get_irg_block_visited(ir_graph *irg)
422 {
423   return irg->block_visited;
424 }
425
426 static INLINE void
427 __set_irg_block_visited(ir_graph *irg, unsigned long visited)
428 {
429   irg->block_visited = visited;
430 }
431
432 static INLINE void
433 __inc_irg_block_visited(ir_graph *irg)
434 {
435   ++irg->block_visited;
436 }
437
438 #define is_ir_graph(thing)                 __is_ir_graph(thing)
439 #define get_irg_start_block(irg)           __get_irg_start_block(irg)
440 #define set_irg_start_block(irg, node)     __set_irg_start_block(irg, node)
441 #define get_irg_start(irg)                 __get_irg_start(irg)
442 #define set_irg_start(irg, node)           __set_irg_start(irg, node)
443 #define get_irg_end_block(irg)             __get_irg_end_block(irg)
444 #define set_irg_end_block(irg, node)       __set_irg_end_block(irg, node)
445 #define get_irg_end(irg)                   __get_irg_end(irg)
446 #define set_irg_end(irg, node)             __set_irg_end(irg, node)
447 #define get_irg_end_reg(irg)               __get_irg_end_reg(irg)
448 #define get_irg_end_except(irg)            __get_irg_end_except(irg)
449 #define get_irg_cstore(irg)                __get_irg_cstore(irg)
450 #define set_irg_cstore(irg, node)          __set_irg_cstore(irg, node)
451 #define get_irg_frame(irg)                 __get_irg_frame(irg)
452 #define set_irg_frame(irg, node)           __set_irg_frame(irg, node)
453 #define get_irg_globals(irg)               __get_irg_globals(irg)
454 #define set_irg_globals(irg, node)         __set_irg_globals(irg, node)
455 #define get_irg_initial_mem(irg)           __get_irg_initial_mem(irg)
456 #define set_irg_initial_mem(irg, node)     __set_irg_initial_mem(irg, node)
457 #define get_irg_args(irg)                  __get_irg_args(irg)
458 #define set_irg_args(irg, node)            __set_irg_args(irg, node)
459 #define get_irg_bad(irg)                   __get_irg_bad(irg)
460 #define set_irg_bad(irg, node)             __set_irg_bad(irg, node)
461 #define get_irg_current_block(irg)         __get_irg_current_block(irg)
462 #define set_irg_current_block(irg, node)   __set_irg_current_block(irg, node)
463 #define get_irg_entity(irg)                   __get_irg_ent(irg)
464 #define set_irg_entity(irg, ent)              __set_irg_ent(irg, ent)
465 #define get_irg_frame_type(irg)            __get_irg_frame_type(irg)
466 #define set_irg_frame_type(irg, ftp)       __set_irg_frame_type(irg, ftp)
467 #define get_irg_obstack(irg)               __get_irg_obstack(irg)
468 #define get_irg_phase_state(irg)           __get_irg_phase_state(irg)
469 #define set_irg_phase_low(irg)             __set_irg_phase_low(irg)
470 #define get_irg_pinned(irg)                __get_irg_pinned(irg)
471 #define get_irg_outs_state(irg)            __get_irg_outs_state(irg)
472 #define set_irg_outs_inconsistent(irg)     __set_irg_outs_inconsistent(irg)
473 #define get_irg_dom_state(irg)             __get_irg_dom_state(irg)
474 #define set_irg_dom_inconsistent(irg)      __set_irg_dom_inconsistent(irg)
475 #define get_irg_loopinfo_state(irg)        __get_irg_loopinfo_state(irg)
476 #define set_irg_loopinfo_state(irg, s)     __set_irg_loopinfo_state(irg, s)
477 #define set_irg_pinned(irg, p)             __set_irg_pinned(irg, p)
478 #define get_irg_callee_info_state(irg)     __get_irg_callee_info_state(irg)
479 #define set_irg_callee_info_state(irg, s)  __set_irg_callee_info_state(irg, s)
480 #define get_irg_inline_property(irg)       __get_irg_inline_property(irg)
481 #define set_irg_inline_property(irg, s)    __set_irg_inline_property(irg, s)
482 #define set_irg_link(irg, thing)           __set_irg_link(irg, thing)
483 #define get_irg_link(irg)                  __get_irg_link(irg)
484 #define get_irg_visited(irg)               __get_irg_visited(irg)
485 #define get_irg_block_visited(irg)         __get_irg_block_visited(irg)
486 #define set_irg_block_visited(irg, v)      __set_irg_block_visited(irg, v)
487 #define inc_irg_block_visited(irg)         __inc_irg_block_visited(irg)
488
489 # endif /* _IRGRAPH_T_H_ */