removed never finished code
[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_weighted_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 void init_irgraph(void);
118
119 /** Make a rudimentary ir graph for the constant code.
120    Must look like a correct irg, spare everything else. */
121 ir_graph *new_const_code_irg(void);
122
123 /**
124  * Set the op_pin_state_pinned state of a graph.
125  *
126  * @irg     the IR graph
127  * @p       new pin state
128  */
129 INLINE void
130 set_irg_pinned (ir_graph *irg, op_pin_state p);
131
132 /** Returns the obstack associated with the graph. */
133 struct obstack *get_irg_obstack(ir_graph *irg);
134
135 /**
136  * Returns true if the node n is allocated on the storage of graph irg.
137  *
138  * @param irg   the IR graph
139  * @param n the IR node
140  */
141 int node_is_in_irgs_storage(ir_graph *irg, ir_node *n);
142
143 /*-------------------------------------------------------------------*/
144 /* inline functions for graphs                                       */
145 /*-------------------------------------------------------------------*/
146
147 static INLINE int
148 __is_ir_graph(void *thing) {
149   return (get_kind(thing) == k_ir_graph);
150 }
151
152 /** Returns the start block of a graph. */
153 static INLINE ir_node *
154 __get_irg_start_block(ir_graph *irg)
155 {
156   return irg->start_block;
157 }
158
159 static INLINE void
160 __set_irg_start_block(ir_graph *irg, ir_node *node)
161 {
162   irg->start_block = node;
163 }
164
165 static INLINE ir_node *
166 __get_irg_start(ir_graph *irg)
167 {
168   return irg->start;
169 }
170
171 static INLINE void
172 __set_irg_start(ir_graph *irg, ir_node *node)
173 {
174   irg->start = node;
175 }
176
177 static INLINE ir_node *
178 __get_irg_end_block(ir_graph *irg)
179 {
180   return irg->end_block;
181 }
182
183 static INLINE void
184 __set_irg_end_block(ir_graph *irg, ir_node *node)
185 {
186   irg->end_block = node;
187 }
188
189 static INLINE ir_node *
190 __get_irg_end(ir_graph *irg)
191 {
192   return irg->end;
193 }
194
195 static INLINE void
196 __set_irg_end(ir_graph *irg, ir_node *node)
197 {
198   irg->end = node;
199 }
200
201 static INLINE ir_node *
202 __get_irg_end_reg(ir_graph *irg) {
203   return irg->end_reg;
204 }
205
206 static INLINE ir_node *
207 __get_irg_end_except (ir_graph *irg) {
208   return irg->end_except;
209 }
210
211 static INLINE ir_node *
212 __get_irg_cstore(ir_graph *irg)
213 {
214   return irg->cstore;
215 }
216
217 static INLINE void
218 __set_irg_cstore(ir_graph *irg, ir_node *node)
219 {
220   irg->cstore = node;
221 }
222
223 static INLINE ir_node *
224 __get_irg_frame(ir_graph *irg)
225 {
226   return irg->frame;
227 }
228
229 static INLINE void
230 __set_irg_frame(ir_graph *irg, ir_node *node)
231 {
232   irg->frame = node;
233 }
234
235 static INLINE ir_node *
236 __get_irg_globals(ir_graph *irg)
237 {
238   return irg->globals;
239 }
240
241 static INLINE void
242 __set_irg_globals(ir_graph *irg, ir_node *node)
243 {
244   irg->globals = node;
245 }
246
247 static INLINE ir_node *
248 __get_irg_initial_mem(ir_graph *irg)
249 {
250   return irg->initial_mem;
251 }
252
253 static INLINE void
254 __set_irg_initial_mem(ir_graph *irg, ir_node *node)
255 {
256   irg->initial_mem = node;
257 }
258
259 static INLINE ir_node *
260 __get_irg_args(ir_graph *irg)
261 {
262   return irg->args;
263 }
264
265 static INLINE void
266 __set_irg_args(ir_graph *irg, ir_node *node)
267 {
268   irg->args = node;
269 }
270
271 static INLINE ir_node *
272 __get_irg_bad(ir_graph *irg)
273 {
274   return irg->bad;
275 }
276
277 static INLINE void
278 __set_irg_bad(ir_graph *irg, ir_node *node)
279 {
280   irg->bad = node;
281 }
282
283 static INLINE ir_node *
284 __get_irg_current_block(ir_graph *irg)
285 {
286   return irg->current_block;
287 }
288
289 static INLINE void
290 __set_irg_current_block(ir_graph *irg, ir_node *node)
291 {
292   irg->current_block = node;
293 }
294
295 static INLINE entity *
296 __get_irg_ent(ir_graph *irg)
297 {
298   assert(irg && irg->ent);
299   return irg->ent;
300 }
301
302 static INLINE void
303 __set_irg_ent(ir_graph *irg, entity *ent)
304 {
305   irg->ent = ent;
306 }
307
308 static INLINE type *
309 __get_irg_frame_type(ir_graph *irg)
310 {
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 {
318   assert(is_class_type(ftp));
319   irg->frame_type = ftp;
320 }
321
322 static INLINE struct obstack *
323 __get_irg_obstack(ir_graph *irg) {
324   return irg->obst;
325 }
326
327
328 static INLINE irg_phase_state
329 __get_irg_phase_state(ir_graph *irg) {
330   return irg->phase_state;
331 }
332
333 static INLINE void
334 __set_irg_phase_low(ir_graph *irg) {
335   irg->phase_state = phase_low;
336 }
337
338 static INLINE op_pin_state
339 __get_irg_pinned(ir_graph *irg) {
340   return irg->op_pin_state_pinned;
341 }
342
343 static INLINE irg_outs_state
344 __get_irg_outs_state(ir_graph *irg) {
345   return irg->outs_state;
346 }
347
348 static INLINE void
349 __set_irg_outs_inconsistent(ir_graph *irg) {
350   irg->outs_state = outs_inconsistent;
351 }
352
353 static INLINE irg_dom_state
354 __get_irg_dom_state(ir_graph *irg) {
355   return irg->dom_state;
356 }
357
358 static INLINE void
359 __set_irg_dom_inconsistent(ir_graph *irg) {
360   irg->dom_state = dom_inconsistent;
361 }
362
363 static INLINE irg_loopinfo_state
364 __get_irg_loopinfo_state(ir_graph *irg) {
365   return irg->loopinfo_state;
366 }
367
368 static INLINE void
369 __set_irg_loopinfo_state(ir_graph *irg, irg_loopinfo_state s) {
370   irg->loopinfo_state = s;
371 }
372
373 static INLINE void
374 __set_irg_pinned(ir_graph *irg, op_pin_state p) {
375   irg->op_pin_state_pinned = p;
376 }
377
378 static INLINE irg_callee_info_state
379 __get_irg_callee_info_state(ir_graph *irg) {
380   return irg->callee_info_state;
381 }
382
383 static INLINE void
384 __set_irg_callee_info_state(ir_graph *irg, irg_callee_info_state s) {
385   irg_callee_info_state irp_state = get_irp_callee_info_state();
386
387   irg->callee_info_state = s;
388
389   /* I could compare ... but who knows? */
390   if ((irp_state == irg_callee_info_consistent)  ||
391       ((irp_state == irg_callee_info_inconsistent) && (s == irg_callee_info_none)))
392       set_irp_callee_info_state(s);
393 }
394
395 static INLINE irg_inline_property
396 __get_irg_inline_property(ir_graph *irg) {
397   return irg->inline_property;
398 }
399
400 static INLINE void
401 __set_irg_inline_property(ir_graph *irg, irg_inline_property s) {
402   irg->inline_property = s;
403 }
404
405 static INLINE void
406 __set_irg_link(ir_graph *irg, void *thing) {
407   irg->link = thing;
408 }
409
410 static INLINE void *
411 __get_irg_link(ir_graph *irg) {
412   return irg->link;
413 }
414
415 static INLINE unsigned long
416 __get_irg_visited(ir_graph *irg)
417 {
418   return irg->visited;
419 }
420
421 static INLINE unsigned long
422 __get_irg_block_visited(ir_graph *irg)
423 {
424   return irg->block_visited;
425 }
426
427 static INLINE void
428 __set_irg_block_visited(ir_graph *irg, unsigned long visited)
429 {
430   irg->block_visited = visited;
431 }
432
433 static INLINE void
434 __inc_irg_block_visited(ir_graph *irg)
435 {
436   ++irg->block_visited;
437 }
438
439 #define is_ir_graph(thing)                 __is_ir_graph(thing)
440 #define get_irg_start_block(irg)           __get_irg_start_block(irg)
441 #define set_irg_start_block(irg, node)     __set_irg_start_block(irg, node)
442 #define get_irg_start(irg)                 __get_irg_start(irg)
443 #define set_irg_start(irg, node)           __set_irg_start(irg, node)
444 #define get_irg_end_block(irg)             __get_irg_end_block(irg)
445 #define set_irg_end_block(irg, node)       __set_irg_end_block(irg, node)
446 #define get_irg_end(irg)                   __get_irg_end(irg)
447 #define set_irg_end(irg, node)             __set_irg_end(irg, node)
448 #define get_irg_end_reg(irg)               __get_irg_end_reg(irg)
449 #define get_irg_end_except(irg)            __get_irg_end_except(irg)
450 #define get_irg_cstore(irg)                __get_irg_cstore(irg)
451 #define set_irg_cstore(irg, node)          __set_irg_cstore(irg, node)
452 #define get_irg_frame(irg)                 __get_irg_frame(irg)
453 #define set_irg_frame(irg, node)           __set_irg_frame(irg, node)
454 #define get_irg_globals(irg)               __get_irg_globals(irg)
455 #define set_irg_globals(irg, node)         __set_irg_globals(irg, node)
456 #define get_irg_initial_mem(irg)           __get_irg_initial_mem(irg)
457 #define set_irg_initial_mem(irg, node)     __set_irg_initial_mem(irg, node)
458 #define get_irg_args(irg)                  __get_irg_args(irg)
459 #define set_irg_args(irg, node)            __set_irg_args(irg, node)
460 #define get_irg_bad(irg)                   __get_irg_bad(irg)
461 #define set_irg_bad(irg, node)             __set_irg_bad(irg, node)
462 #define get_irg_current_block(irg)         __get_irg_current_block(irg)
463 #define set_irg_current_block(irg, node)   __set_irg_current_block(irg, node)
464 #define get_irg_entity(irg)                   __get_irg_ent(irg)
465 #define set_irg_entity(irg, ent)              __set_irg_ent(irg, ent)
466 #define get_irg_frame_type(irg)            __get_irg_frame_type(irg)
467 #define set_irg_frame_type(irg, ftp)       __set_irg_frame_type(irg, ftp)
468 #define get_irg_obstack(irg)               __get_irg_obstack(irg)
469 #define get_irg_phase_state(irg)           __get_irg_phase_state(irg)
470 #define set_irg_phase_low(irg)             __set_irg_phase_low(irg)
471 #define get_irg_pinned(irg)                __get_irg_pinned(irg)
472 #define get_irg_outs_state(irg)            __get_irg_outs_state(irg)
473 #define set_irg_outs_inconsistent(irg)     __set_irg_outs_inconsistent(irg)
474 #define get_irg_dom_state(irg)             __get_irg_dom_state(irg)
475 #define set_irg_dom_inconsistent(irg)      __set_irg_dom_inconsistent(irg)
476 #define get_irg_loopinfo_state(irg)        __get_irg_loopinfo_state(irg)
477 #define set_irg_loopinfo_state(irg, s)     __set_irg_loopinfo_state(irg, s)
478 #define set_irg_pinned(irg, p)             __set_irg_pinned(irg, p)
479 #define get_irg_callee_info_state(irg)     __get_irg_callee_info_state(irg)
480 #define set_irg_callee_info_state(irg, s)  __set_irg_callee_info_state(irg, s)
481 #define get_irg_inline_property(irg)       __get_irg_inline_property(irg)
482 #define set_irg_inline_property(irg, s)    __set_irg_inline_property(irg, s)
483 #define set_irg_link(irg, thing)           __set_irg_link(irg, thing)
484 #define get_irg_link(irg)                  __get_irg_link(irg)
485 #define get_irg_visited(irg)               __get_irg_visited(irg)
486 #define get_irg_block_visited(irg)         __get_irg_block_visited(irg)
487 #define set_irg_block_visited(irg, v)      __set_irg_block_visited(irg, v)
488 #define inc_irg_block_visited(irg)         __inc_irg_block_visited(irg)
489
490 # endif /* _IRGRAPH_T_H_ */