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