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