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
9 * Copyright: (c) 1998-2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
16 * ir graph construction.
18 * @author Martin Trapp, Christian Schaefer
27 #include "firm_common_t.h"
28 #include "irtypeinfo.h"
30 #include "pseudo_irg.h"
32 #include "tr_inheritance.h"
35 #include "execution_frequency.h"
41 #define FRAME_TP_SUFFIX "frame_tp"
44 * Edge info to put into an irg.
46 typedef struct _irg_edge_info_t {
48 unsigned activated : 1;
52 /** ir_graph holds all information for a procedure */
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
76 struct ir_node *no_mem; /**< NoMem node of this ir_graph, the one and
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
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. */
96 /* -- Fields for construction -- */
97 #if USE_EXPLICIT_PHI_IN_STACK
98 struct Phi_in_stack *Phi_in_stack; /**< needed for automatic Phi construction */
100 int n_loc; /**< number of local variable in this
101 procedure including procedure parameters. */
102 void **loc_descriptions; /**< storage for local variable desriptions */
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. */
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
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 */
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
131 unsigned long block_visited; /**< same as visited, for a complete block */
133 int graph_nr; /**< a unique graph number for each graph to make output
137 #if FIRM_EDGES_INPLACE
138 irg_edge_info_t edge_info; /**< edge info for automatic outs */
143 * Initializes the graph construction module
145 void init_irgraph(void);
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);
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);
155 * Set the op_pin_state_pinned state of a graph.
157 * @param irg the IR graph
158 * @param p new pin state
161 set_irg_pinned (ir_graph *irg, op_pin_state p);
163 /** Returns the obstack associated with the graph. */
164 struct obstack *get_irg_obstack(const ir_graph *irg);
167 * Returns true if the node n is allocated on the storage of graph irg.
169 * @param irg the IR graph
170 * @param n the IR node
172 int node_is_in_irgs_storage(ir_graph *irg, ir_node *n);
174 /*-------------------------------------------------------------------*/
175 /* inline functions for graphs */
176 /*-------------------------------------------------------------------*/
178 extern int __interprocedural_view;
181 _get_interprocedural_view(void) {
182 return __interprocedural_view;
186 _is_ir_graph(const void *thing) {
187 return (get_kind(thing) == k_ir_graph);
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;
197 _set_irg_start_block(ir_graph *irg, ir_node *node) {
198 irg->start_block = node;
201 static INLINE ir_node *
202 _get_irg_start(const ir_graph *irg) {
207 _set_irg_start(ir_graph *irg, ir_node *node) {
211 static INLINE ir_node *
212 _get_irg_end_block(const ir_graph *irg) {
213 return irg->end_block;
217 _set_irg_end_block(ir_graph *irg, ir_node *node) {
218 irg->end_block = node;
221 static INLINE ir_node *
222 _get_irg_end(const ir_graph *irg) {
227 _set_irg_end(ir_graph *irg, ir_node *node) {
231 static INLINE ir_node *
232 _get_irg_end_reg(const ir_graph *irg) {
236 static INLINE ir_node *
237 _get_irg_end_except (const ir_graph *irg) {
238 return irg->end_except;
241 static INLINE ir_node *
242 _get_irg_cstore(const ir_graph *irg) {
247 _set_irg_cstore(ir_graph *irg, ir_node *node) {
251 static INLINE ir_node *
252 _get_irg_frame(const ir_graph *irg) {
257 _set_irg_frame(ir_graph *irg, ir_node *node) {
261 static INLINE ir_node *
262 _get_irg_globals(const ir_graph *irg) {
267 _set_irg_globals(ir_graph *irg, ir_node *node) {
271 static INLINE ir_node *
272 _get_irg_initial_mem(const ir_graph *irg) {
273 return irg->initial_mem;
277 _set_irg_initial_mem(ir_graph *irg, ir_node *node) {
278 irg->initial_mem = node;
281 static INLINE ir_node *
282 _get_irg_args(const ir_graph *irg) {
287 _set_irg_args(ir_graph *irg, ir_node *node) {
291 static INLINE ir_node **
292 _get_irg_proj_args(const ir_graph *irg) {
293 return irg->proj_args;
297 _set_irg_proj_args(ir_graph *irg, ir_node **nodes) {
298 irg->proj_args = nodes;
301 static INLINE ir_node *
302 _get_irg_bad(const ir_graph *irg) {
307 _set_irg_bad(ir_graph *irg, ir_node *node) {
311 static INLINE ir_node *
312 _get_irg_no_mem(const ir_graph *irg) {
317 _set_irg_no_mem(ir_graph *irg, ir_node *node) {
320 static INLINE ir_node *
321 _get_irg_current_block(const ir_graph *irg) {
322 return irg->current_block;
326 _set_irg_current_block(ir_graph *irg, ir_node *node) {
327 irg->current_block = node;
330 static INLINE entity *
331 _get_irg_entity(const ir_graph *irg) {
332 assert(irg && irg->ent);
337 _set_irg_entity(ir_graph *irg, entity *ent) {
342 _get_irg_frame_type(const ir_graph *irg) {
343 assert(irg && irg->frame_type);
344 return irg->frame_type;
348 _set_irg_frame_type(ir_graph *irg, type *ftp) {
349 assert(is_Class_type(ftp));
350 irg->frame_type = ftp;
353 static INLINE struct obstack *
354 _get_irg_obstack(const ir_graph *irg) {
359 static INLINE irg_phase_state
360 _get_irg_phase_state(const ir_graph *irg) {
361 return irg->phase_state;
365 _set_irg_phase_low(ir_graph *irg) {
366 irg->phase_state = phase_low;
369 static INLINE op_pin_state
370 _get_irg_pinned(const ir_graph *irg) {
371 return irg->op_pin_state_pinned;
374 static INLINE irg_outs_state
375 _get_irg_outs_state(const ir_graph *irg) {
376 return irg->outs_state;
380 _set_irg_outs_inconsistent(ir_graph *irg) {
381 if (irg->outs_state == outs_consistent)
382 irg->outs_state = outs_inconsistent;
385 static INLINE irg_dom_state
386 _get_irg_dom_state(const ir_graph *irg) {
387 return irg->dom_state;
391 _set_irg_dom_inconsistent(ir_graph *irg) {
392 irg->dom_state = dom_inconsistent;
395 static INLINE irg_loopinfo_state
396 _get_irg_loopinfo_state(const ir_graph *irg) {
397 return irg->loopinfo_state;
401 _set_irg_loopinfo_state(ir_graph *irg, irg_loopinfo_state s) {
402 irg->loopinfo_state = s;
406 _set_irg_pinned(ir_graph *irg, op_pin_state p) {
407 irg->op_pin_state_pinned = p;
410 static INLINE irg_callee_info_state
411 _get_irg_callee_info_state(const ir_graph *irg) {
412 return irg->callee_info_state;
416 _set_irg_callee_info_state(ir_graph *irg, irg_callee_info_state s) {
417 irg_callee_info_state irp_state = get_irp_callee_info_state();
419 irg->callee_info_state = s;
421 /* I could compare ... but who knows? */
422 if ((irp_state == irg_callee_info_consistent) ||
423 ((irp_state == irg_callee_info_inconsistent) && (s == irg_callee_info_none)))
424 set_irp_callee_info_state(s);
427 static INLINE irg_inline_property
428 _get_irg_inline_property(const ir_graph *irg) {
429 return irg->inline_property;
433 _set_irg_inline_property(ir_graph *irg, irg_inline_property s) {
434 irg->inline_property = s;
438 _set_irg_link(ir_graph *irg, void *thing) {
443 _get_irg_link(const ir_graph *irg) {
447 static INLINE unsigned long
448 _get_irg_visited(const ir_graph *irg) {
452 static INLINE unsigned long
453 _get_irg_block_visited(const ir_graph *irg) {
454 return irg->block_visited;
458 _set_irg_block_visited(ir_graph *irg, unsigned long visited) {
459 irg->block_visited = visited;
463 _inc_irg_block_visited(ir_graph *irg) {
464 ++irg->block_visited;
467 #define get_interprocedural_view() _get_interprocedural_view()
468 #define is_ir_graph(thing) _is_ir_graph(thing)
469 #define get_irg_start_block(irg) _get_irg_start_block(irg)
470 #define set_irg_start_block(irg, node) _set_irg_start_block(irg, node)
471 #define get_irg_start(irg) _get_irg_start(irg)
472 #define set_irg_start(irg, node) _set_irg_start(irg, node)
473 #define get_irg_end_block(irg) _get_irg_end_block(irg)
474 #define set_irg_end_block(irg, node) _set_irg_end_block(irg, node)
475 #define get_irg_end(irg) _get_irg_end(irg)
476 #define set_irg_end(irg, node) _set_irg_end(irg, node)
477 #define get_irg_end_reg(irg) _get_irg_end_reg(irg)
478 #define get_irg_end_except(irg) _get_irg_end_except(irg)
479 #define get_irg_cstore(irg) _get_irg_cstore(irg)
480 #define set_irg_cstore(irg, node) _set_irg_cstore(irg, node)
481 #define get_irg_frame(irg) _get_irg_frame(irg)
482 #define set_irg_frame(irg, node) _set_irg_frame(irg, node)
483 #define get_irg_globals(irg) _get_irg_globals(irg)
484 #define set_irg_globals(irg, node) _set_irg_globals(irg, node)
485 #define get_irg_initial_mem(irg) _get_irg_initial_mem(irg)
486 #define set_irg_initial_mem(irg, node) _set_irg_initial_mem(irg, node)
487 #define get_irg_args(irg) _get_irg_args(irg)
488 #define set_irg_args(irg, node) _set_irg_args(irg, node)
489 #define get_irg_bad(irg) _get_irg_bad(irg)
490 #define set_irg_bad(irg, node) _set_irg_bad(irg, node)
491 #define get_irg_no_mem(irg) _get_irg_no_mem(irg)
492 #define set_irg_no_mem(irg, node) _set_irg_no_mem(irg, node)
493 #define get_irg_current_block(irg) _get_irg_current_block(irg)
494 #define set_irg_current_block(irg, node) _set_irg_current_block(irg, node)
495 #define get_irg_entity(irg) _get_irg_entity(irg)
496 #define set_irg_entity(irg, ent) _set_irg_entity(irg, ent)
497 #define get_irg_frame_type(irg) _get_irg_frame_type(irg)
498 #define set_irg_frame_type(irg, ftp) _set_irg_frame_type(irg, ftp)
499 #define get_irg_obstack(irg) _get_irg_obstack(irg)
500 #define get_irg_phase_state(irg) _get_irg_phase_state(irg)
501 #define set_irg_phase_low(irg) _set_irg_phase_low(irg)
502 #define get_irg_pinned(irg) _get_irg_pinned(irg)
503 #define get_irg_outs_state(irg) _get_irg_outs_state(irg)
504 #define set_irg_outs_inconsistent(irg) _set_irg_outs_inconsistent(irg)
505 #define get_irg_dom_state(irg) _get_irg_dom_state(irg)
506 #define set_irg_dom_inconsistent(irg) _set_irg_dom_inconsistent(irg)
507 #define get_irg_loopinfo_state(irg) _get_irg_loopinfo_state(irg)
508 #define set_irg_loopinfo_state(irg, s) _set_irg_loopinfo_state(irg, s)
509 #define set_irg_pinned(irg, p) _set_irg_pinned(irg, p)
510 #define get_irg_callee_info_state(irg) _get_irg_callee_info_state(irg)
511 #define set_irg_callee_info_state(irg, s) _set_irg_callee_info_state(irg, s)
512 #define get_irg_inline_property(irg) _get_irg_inline_property(irg)
513 #define set_irg_inline_property(irg, s) _set_irg_inline_property(irg, s)
514 #define set_irg_link(irg, thing) _set_irg_link(irg, thing)
515 #define get_irg_link(irg) _get_irg_link(irg)
516 #define get_irg_visited(irg) _get_irg_visited(irg)
517 #define get_irg_block_visited(irg) _get_irg_block_visited(irg)
518 #define set_irg_block_visited(irg, v) _set_irg_block_visited(irg, v)
519 #define inc_irg_block_visited(irg) _inc_irg_block_visited(irg)
521 # endif /* _IRGRAPH_T_H_ */