irop_flag_highlevel flag added to Confirm and Cast
[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 #include "type_t.h"
32 #include "tr_inheritance.h"
33
34 #include "irloop.h"
35 #include "execution_frequency.h"
36
37 #include "obst.h"
38 #include "pset.h"
39 #include "set.h"
40
41 #define FRAME_TP_SUFFIX "frame_tp"
42
43 /**
44  * Edge info to put into an irg.
45  */
46 typedef struct _irg_edge_info_t {
47         set *edges;
48         unsigned activated : 1;
49 } irg_edge_info_t;
50
51
52 /** ir_graph holds all information for a procedure */
53 struct ir_graph {
54   firm_kind         kind;            /**<  always set to k_ir_graph*/
55   /* --  Basics of the representation -- */
56   struct entity  *ent;               /**< The entity of this procedure, i.e.,
57                     the type of the procedure and the
58                     class it belongs to. */
59   struct type    *frame_type;    /**< A class type representing the stack frame.
60                     Can include "inner" methods. */
61   struct ir_node *start_block;   /**< block the start node will belong to */
62   struct ir_node *start;         /**< start node of this ir_graph */
63   struct ir_node *end_block;     /**< block the end node will belong to */
64   struct ir_node *end;           /**< end node of this ir_graph */
65   struct ir_node *end_reg;       /**< end node of this ir_graph */
66   struct ir_node *end_except;    /**< end node of this ir_graph */
67   struct ir_node *cstore;        /**< constant store -- no more needed!! */
68   struct ir_node *frame;         /**< method's frame */
69   struct ir_node *globals;       /**< pointer to the data segment containing all
70                     globals as well as global procedures. */
71   struct ir_node *initial_mem;   /**< initial memory of this graph */
72   struct ir_node *args;          /**< methods arguments */
73   struct ir_node **proj_args;    /**< projs of the methods arguments */
74   struct ir_node *bad;           /**< bad node of this ir_graph, the one and
75                     only in this graph */
76   struct ir_node *no_mem;        /**< NoMem node of this ir_graph, the one and
77                     only in this graph */
78   /* GL removed: we need unknown with mode for analyses. */
79   /*   struct ir_node *unknown;*/           /**< unknown node of this ir_graph */
80   struct obstack *obst;          /**< obstack where all of the ir_nodes live */
81   struct ir_node *current_block;     /**< block for newly gen_*()-erated
82                     ir_nodes */
83
84   /* -- Fields indicating different states of irgraph -- */
85   irg_phase_state phase_state;       /**< compiler phase */
86   op_pin_state op_pin_state_pinned;  /**< Flag for status of nodes */
87   irg_outs_state outs_state;         /**< Out edges. */
88   irg_dom_state dom_state;           /**< Dominator information */
89   ir_typeinfo_state typeinfo_state;        /**< Validity of type information */
90   irg_callee_info_state callee_info_state; /**< Validity of callee information */
91   irg_inline_property inline_property;     /**< How to handle inlineing. */
92   irg_loopinfo_state loopinfo_state;       /**< state of loop information */
93   exec_freq_state   execfreq_state;        /**< state of execution freqency information */
94   ir_class_cast_state class_cast_state;    /**< kind of cast operations in code. */
95
96   /* -- Fields for construction -- */
97 #if USE_EXPLICIT_PHI_IN_STACK
98   struct Phi_in_stack *Phi_in_stack; /**< needed for automatic Phi construction */
99 #endif
100   int n_loc;                         /**< number of local variable in this
101                                           procedure including procedure parameters. */
102   void **loc_descriptions;           /**< storage for local variable desriptions */
103
104   /* -- Fields for optimizations / analysis information -- */
105   pset *value_table;                 /**< hash table for global value numbering (cse)
106                     for optimizing use in iropt.c */
107   struct ir_node **outs;             /**< Space for the out arrays. */
108
109 #ifdef DEBUG_libfirm
110   int             n_outs;            /* < Size wasted for outs */
111 #endif /* defined DEBUG_libfirm */
112   struct ir_loop *loop;              /**< The outermost loop */
113   void *link;                        /**< A void* field to link any information to
114                     the node. */
115
116   ir_graph **callers;                /**< For callgraph analysis. */
117   unsigned char *caller_isbe;        /**< For callgraph analysis: set if backedge. */
118   ir_graph **callees;                /**< For callgraph analysis. */
119   unsigned char *callee_isbe;        /**< For callgraph analysis: set if backedge. */
120   int        callgraph_loop_depth;         /**< For callgraph analysis */
121   int        callgraph_recursion_depth;    /**< For callgraph analysis */
122   double     method_execution_frequency;   /**< For callgraph analysis */
123
124   ir_loop   *l;
125
126   /* -- Fields for Walking the graph -- */
127   unsigned long visited;             /**< this flag is an identifier for
128                     ir walk. it will be incremented
129                     every time someone walks through
130                     the graph */
131   unsigned long block_visited;       /**< same as visited, for a complete block */
132 #ifdef DEBUG_libfirm
133   int graph_nr;             /**< a unique graph number for each graph to make output
134                    readable. */
135 #endif
136
137 #if FIRM_EDGES_INPLACE
138   irg_edge_info_t edge_info;  /**< edge info for automatic outs */
139 #endif
140 };
141
142 /**
143  * Initializes the graph construction module
144  */
145 void init_irgraph(void);
146
147 /* Internal constructor that does not add to irp_irgs or the like. */
148 ir_graph *new_r_ir_graph (entity *ent, int n_loc);
149
150 /** Make a rudimentary ir graph for the constant code.
151    Must look like a correct irg, spare everything else. */
152 ir_graph *new_const_code_irg(void);
153
154 /**
155  * Set the op_pin_state_pinned state of a graph.
156  *
157  * @param irg     the IR graph
158  * @param p       new pin state
159  */
160 INLINE void
161 set_irg_pinned (ir_graph *irg, op_pin_state p);
162
163 /** Returns the obstack associated with the graph. */
164 struct obstack *get_irg_obstack(const ir_graph *irg);
165
166 /**
167  * Returns true if the node n is allocated on the storage of graph irg.
168  *
169  * @param irg   the IR graph
170  * @param n the IR node
171  */
172 int node_is_in_irgs_storage(ir_graph *irg, ir_node *n);
173
174 /*-------------------------------------------------------------------*/
175 /* inline functions for graphs                                       */
176 /*-------------------------------------------------------------------*/
177
178 extern int __interprocedural_view;
179
180 static INLINE int
181 _get_interprocedural_view(void) {
182   return __interprocedural_view;
183 }
184
185 static INLINE int
186 _is_ir_graph(const void *thing) {
187   return (get_kind(thing) == k_ir_graph);
188 }
189
190 /** Returns the start block of a graph. */
191 static INLINE ir_node *
192 _get_irg_start_block(const ir_graph *irg) {
193   return irg->start_block;
194 }
195
196 static INLINE void
197 _set_irg_start_block(ir_graph *irg, ir_node *node) {
198   irg->start_block = node;
199 }
200
201 static INLINE ir_node *
202 _get_irg_start(const ir_graph *irg) {
203   return irg->start;
204 }
205
206 static INLINE void
207 _set_irg_start(ir_graph *irg, ir_node *node) {
208   irg->start = node;
209 }
210
211 static INLINE ir_node *
212 _get_irg_end_block(const ir_graph *irg) {
213   return irg->end_block;
214 }
215
216 static INLINE void
217 _set_irg_end_block(ir_graph *irg, ir_node *node) {
218   irg->end_block = node;
219 }
220
221 static INLINE ir_node *
222 _get_irg_end(const ir_graph *irg) {
223   return irg->end;
224 }
225
226 static INLINE void
227 _set_irg_end(ir_graph *irg, ir_node *node) {
228   irg->end = node;
229 }
230
231 static INLINE ir_node *
232 _get_irg_end_reg(const ir_graph *irg) {
233   return irg->end_reg;
234 }
235
236 static INLINE ir_node *
237 _get_irg_end_except (const ir_graph *irg) {
238   return irg->end_except;
239 }
240
241 static INLINE ir_node *
242 _get_irg_cstore(const ir_graph *irg) {
243   return irg->cstore;
244 }
245
246 static INLINE void
247 _set_irg_cstore(ir_graph *irg, ir_node *node) {
248   irg->cstore = node;
249 }
250
251 static INLINE ir_node *
252 _get_irg_frame(const ir_graph *irg) {
253   return irg->frame;
254 }
255
256 static INLINE void
257 _set_irg_frame(ir_graph *irg, ir_node *node) {
258   irg->frame = node;
259 }
260
261 static INLINE ir_node *
262 _get_irg_globals(const ir_graph *irg) {
263   return irg->globals;
264 }
265
266 static INLINE void
267 _set_irg_globals(ir_graph *irg, ir_node *node) {
268   irg->globals = node;
269 }
270
271 static INLINE ir_node *
272 _get_irg_initial_mem(const ir_graph *irg) {
273   return irg->initial_mem;
274 }
275
276 static INLINE void
277 _set_irg_initial_mem(ir_graph *irg, ir_node *node) {
278   irg->initial_mem = node;
279 }
280
281 static INLINE ir_node *
282 _get_irg_args(const ir_graph *irg) {
283   return irg->args;
284 }
285
286 static INLINE void
287 _set_irg_args(ir_graph *irg, ir_node *node) {
288   irg->args = node;
289 }
290
291 static INLINE ir_node **
292 _get_irg_proj_args(const ir_graph *irg) {
293   return irg->proj_args;
294 }
295
296 static INLINE void
297 _set_irg_proj_args(ir_graph *irg, ir_node **nodes) {
298   irg->proj_args = nodes;
299 }
300
301 static INLINE ir_node *
302 _get_irg_bad(const ir_graph *irg) {
303   return irg->bad;
304 }
305
306 static INLINE void
307 _set_irg_bad(ir_graph *irg, ir_node *node) {
308   irg->bad = node;
309 }
310
311 static INLINE ir_node *
312 _get_irg_no_mem(const ir_graph *irg) {
313   return irg->no_mem;
314 }
315
316 static INLINE void
317 _set_irg_no_mem(ir_graph *irg, ir_node *node) {
318   irg->no_mem = node;
319 }
320 static INLINE ir_node *
321 _get_irg_current_block(const ir_graph *irg) {
322   return irg->current_block;
323 }
324
325 static INLINE void
326 _set_irg_current_block(ir_graph *irg, ir_node *node) {
327   irg->current_block = node;
328 }
329
330 static INLINE entity *
331 _get_irg_entity(const ir_graph *irg) {
332   assert(irg && irg->ent);
333   return irg->ent;
334 }
335
336 static INLINE void
337 _set_irg_entity(ir_graph *irg, entity *ent) {
338   irg->ent = ent;
339 }
340
341 static INLINE type *
342 _get_irg_frame_type(const ir_graph *irg) {
343   assert(irg && irg->frame_type);
344   return irg->frame_type;
345 }
346
347 static INLINE void
348 _set_irg_frame_type(ir_graph *irg, type *ftp) {
349   assert(is_Class_type(ftp));
350   irg->frame_type = ftp;
351 }
352
353 static INLINE struct obstack *
354 _get_irg_obstack(const ir_graph *irg) {
355   return irg->obst;
356 }
357
358
359 static INLINE irg_phase_state
360 _get_irg_phase_state(const ir_graph *irg) {
361   return irg->phase_state;
362 }
363
364 static INLINE void
365 _set_irg_phase_low(ir_graph *irg) {
366   irg->phase_state = phase_low;
367 }
368
369 static INLINE op_pin_state
370 _get_irg_pinned(const ir_graph *irg) {
371   return irg->op_pin_state_pinned;
372 }
373
374 static INLINE irg_outs_state
375 _get_irg_outs_state(const ir_graph *irg) {
376   return irg->outs_state;
377 }
378
379 static INLINE void
380 _set_irg_outs_inconsistent(ir_graph *irg) {
381   if (irg->outs_state == outs_consistent)
382     irg->outs_state = outs_inconsistent;
383 }
384
385 static INLINE irg_dom_state
386 _get_irg_dom_state(const ir_graph *irg) {
387   return irg->dom_state;
388 }
389
390 static INLINE void
391 _set_irg_dom_inconsistent(ir_graph *irg) {
392   irg->dom_state = dom_inconsistent;
393 }
394
395 static INLINE irg_loopinfo_state
396 _get_irg_loopinfo_state(const ir_graph *irg) {
397   return irg->loopinfo_state;
398 }
399
400 static INLINE void
401 _set_irg_loopinfo_state(ir_graph *irg, irg_loopinfo_state s) {
402   irg->loopinfo_state = s;
403 }
404
405 static INLINE void
406 _set_irg_loopinfo_inconsistent(ir_graph *irg) {
407   irg->loopinfo_state &= ~loopinfo_valid;
408 }
409
410 static INLINE void
411 _set_irg_pinned(ir_graph *irg, op_pin_state p) {
412   irg->op_pin_state_pinned = p;
413 }
414
415 static INLINE irg_callee_info_state
416 _get_irg_callee_info_state(const ir_graph *irg) {
417   return irg->callee_info_state;
418 }
419
420 static INLINE void
421 _set_irg_callee_info_state(ir_graph *irg, irg_callee_info_state s) {
422   irg_callee_info_state irp_state = get_irp_callee_info_state();
423
424   irg->callee_info_state = s;
425
426   /* I could compare ... but who knows? */
427   if ((irp_state == irg_callee_info_consistent)  ||
428       ((irp_state == irg_callee_info_inconsistent) && (s == irg_callee_info_none)))
429       set_irp_callee_info_state(s);
430 }
431
432 static INLINE irg_inline_property
433 _get_irg_inline_property(const ir_graph *irg) {
434   return irg->inline_property;
435 }
436
437 static INLINE void
438 _set_irg_inline_property(ir_graph *irg, irg_inline_property s) {
439   irg->inline_property = s;
440 }
441
442 static INLINE void
443 _set_irg_link(ir_graph *irg, void *thing) {
444   irg->link = thing;
445 }
446
447 static INLINE void *
448 _get_irg_link(const ir_graph *irg) {
449   return irg->link;
450 }
451
452 static INLINE unsigned long
453 _get_irg_visited(const ir_graph *irg) {
454   return irg->visited;
455 }
456
457 static INLINE unsigned long
458 _get_irg_block_visited(const ir_graph *irg) {
459   return irg->block_visited;
460 }
461
462 static INLINE void
463 _set_irg_block_visited(ir_graph *irg, unsigned long visited) {
464   irg->block_visited = visited;
465 }
466
467 static INLINE void
468 _inc_irg_block_visited(ir_graph *irg) {
469   ++irg->block_visited;
470 }
471
472 #define get_interprocedural_view()         _get_interprocedural_view()
473 #define is_ir_graph(thing)                 _is_ir_graph(thing)
474 #define get_irg_start_block(irg)           _get_irg_start_block(irg)
475 #define set_irg_start_block(irg, node)     _set_irg_start_block(irg, node)
476 #define get_irg_start(irg)                 _get_irg_start(irg)
477 #define set_irg_start(irg, node)           _set_irg_start(irg, node)
478 #define get_irg_end_block(irg)             _get_irg_end_block(irg)
479 #define set_irg_end_block(irg, node)       _set_irg_end_block(irg, node)
480 #define get_irg_end(irg)                   _get_irg_end(irg)
481 #define set_irg_end(irg, node)             _set_irg_end(irg, node)
482 #define get_irg_end_reg(irg)               _get_irg_end_reg(irg)
483 #define get_irg_end_except(irg)            _get_irg_end_except(irg)
484 #define get_irg_cstore(irg)                _get_irg_cstore(irg)
485 #define set_irg_cstore(irg, node)          _set_irg_cstore(irg, node)
486 #define get_irg_frame(irg)                 _get_irg_frame(irg)
487 #define set_irg_frame(irg, node)           _set_irg_frame(irg, node)
488 #define get_irg_globals(irg)               _get_irg_globals(irg)
489 #define set_irg_globals(irg, node)         _set_irg_globals(irg, node)
490 #define get_irg_initial_mem(irg)           _get_irg_initial_mem(irg)
491 #define set_irg_initial_mem(irg, node)     _set_irg_initial_mem(irg, node)
492 #define get_irg_args(irg)                  _get_irg_args(irg)
493 #define set_irg_args(irg, node)            _set_irg_args(irg, node)
494 #define get_irg_bad(irg)                   _get_irg_bad(irg)
495 #define set_irg_bad(irg, node)             _set_irg_bad(irg, node)
496 #define get_irg_no_mem(irg)                _get_irg_no_mem(irg)
497 #define set_irg_no_mem(irg, node)          _set_irg_no_mem(irg, node)
498 #define get_irg_current_block(irg)         _get_irg_current_block(irg)
499 #define set_irg_current_block(irg, node)   _set_irg_current_block(irg, node)
500 #define get_irg_entity(irg)                _get_irg_entity(irg)
501 #define set_irg_entity(irg, ent)           _set_irg_entity(irg, ent)
502 #define get_irg_frame_type(irg)            _get_irg_frame_type(irg)
503 #define set_irg_frame_type(irg, ftp)       _set_irg_frame_type(irg, ftp)
504 #define get_irg_obstack(irg)               _get_irg_obstack(irg)
505 #define get_irg_phase_state(irg)           _get_irg_phase_state(irg)
506 #define set_irg_phase_low(irg)             _set_irg_phase_low(irg)
507 #define get_irg_pinned(irg)                _get_irg_pinned(irg)
508 #define get_irg_outs_state(irg)            _get_irg_outs_state(irg)
509 #define set_irg_outs_inconsistent(irg)     _set_irg_outs_inconsistent(irg)
510 #define get_irg_dom_state(irg)             _get_irg_dom_state(irg)
511 #define set_irg_dom_inconsistent(irg)      _set_irg_dom_inconsistent(irg)
512 #define get_irg_loopinfo_state(irg)        _get_irg_loopinfo_state(irg)
513 #define set_irg_loopinfo_state(irg, s)     _set_irg_loopinfo_state(irg, s)
514 #define set_irg_loopinfo_inconsistent(irg) _set_irg_loopinfo_inconsistent(irg)
515 #define set_irg_pinned(irg, p)             _set_irg_pinned(irg, p)
516 #define get_irg_callee_info_state(irg)     _get_irg_callee_info_state(irg)
517 #define set_irg_callee_info_state(irg, s)  _set_irg_callee_info_state(irg, s)
518 #define get_irg_inline_property(irg)       _get_irg_inline_property(irg)
519 #define set_irg_inline_property(irg, s)    _set_irg_inline_property(irg, s)
520 #define set_irg_link(irg, thing)           _set_irg_link(irg, thing)
521 #define get_irg_link(irg)                  _get_irg_link(irg)
522 #define get_irg_visited(irg)               _get_irg_visited(irg)
523 #define get_irg_block_visited(irg)         _get_irg_block_visited(irg)
524 #define set_irg_block_visited(irg, v)      _set_irg_block_visited(irg, v)
525 #define inc_irg_block_visited(irg)         _inc_irg_block_visited(irg)
526
527 # endif /* _IRGRAPH_T_H_ */