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