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