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