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"
38 #define FRAME_TP_SUFFIX "frame_tp"
40 /** ir_graph holds all information for a procedure */
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
64 struct ir_node *no_mem; /**< NoMem node of this ir_graph, the one and
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
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 */
82 /* -- Fields for construction -- */
83 #if USE_EXPLICIT_PHI_IN_STACK
84 struct Phi_in_stack *Phi_in_stack; /**< needed for automatic Phi construction */
86 int n_loc; /**< number of local variable in this
87 procedure including procedure parameters. */
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. */
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
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 */
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
116 unsigned long block_visited; /**< same as visited, for a complete block */
118 int graph_nr; /**< a unique graph number for each graph to make output
124 * Initializes the graph construction module
126 void init_irgraph(void);
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);
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);
136 * Set the op_pin_state_pinned state of a graph.
138 * @param irg the IR graph
139 * @param p new pin state
142 set_irg_pinned (ir_graph *irg, op_pin_state p);
144 /** Returns the obstack associated with the graph. */
145 struct obstack *get_irg_obstack(const ir_graph *irg);
148 * Returns true if the node n is allocated on the storage of graph irg.
150 * @param irg the IR graph
151 * @param n the IR node
153 int node_is_in_irgs_storage(ir_graph *irg, ir_node *n);
155 /*-------------------------------------------------------------------*/
156 /* inline functions for graphs */
157 /*-------------------------------------------------------------------*/
159 extern int __interprocedural_view;
162 _get_interprocedural_view(void) {
163 return __interprocedural_view;
167 _is_ir_graph(const void *thing) {
168 return (get_kind(thing) == k_ir_graph);
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;
178 _set_irg_start_block(ir_graph *irg, ir_node *node) {
179 irg->start_block = node;
182 static INLINE ir_node *
183 _get_irg_start(const ir_graph *irg) {
188 _set_irg_start(ir_graph *irg, ir_node *node) {
192 static INLINE ir_node *
193 _get_irg_end_block(const ir_graph *irg) {
194 return irg->end_block;
198 _set_irg_end_block(ir_graph *irg, ir_node *node) {
199 irg->end_block = node;
202 static INLINE ir_node *
203 _get_irg_end(const ir_graph *irg) {
208 _set_irg_end(ir_graph *irg, ir_node *node) {
212 static INLINE ir_node *
213 _get_irg_end_reg(const ir_graph *irg) {
217 static INLINE ir_node *
218 _get_irg_end_except (const ir_graph *irg) {
219 return irg->end_except;
222 static INLINE ir_node *
223 _get_irg_cstore(const ir_graph *irg) {
228 _set_irg_cstore(ir_graph *irg, ir_node *node) {
232 static INLINE ir_node *
233 _get_irg_frame(const ir_graph *irg) {
238 _set_irg_frame(ir_graph *irg, ir_node *node) {
242 static INLINE ir_node *
243 _get_irg_globals(const ir_graph *irg) {
248 _set_irg_globals(ir_graph *irg, ir_node *node) {
252 static INLINE ir_node *
253 _get_irg_initial_mem(const ir_graph *irg) {
254 return irg->initial_mem;
258 _set_irg_initial_mem(ir_graph *irg, ir_node *node) {
259 irg->initial_mem = node;
262 static INLINE ir_node *
263 _get_irg_args(const ir_graph *irg) {
268 _set_irg_args(ir_graph *irg, ir_node *node) {
272 static INLINE ir_node **
273 _get_irg_proj_args(const ir_graph *irg) {
274 return irg->proj_args;
278 _set_irg_proj_args(ir_graph *irg, ir_node **nodes) {
279 irg->proj_args = nodes;
282 static INLINE ir_node *
283 _get_irg_bad(const ir_graph *irg) {
288 _set_irg_bad(ir_graph *irg, ir_node *node) {
292 static INLINE ir_node *
293 _get_irg_no_mem(const ir_graph *irg) {
298 _set_irg_no_mem(ir_graph *irg, ir_node *node) {
301 static INLINE ir_node *
302 _get_irg_current_block(const ir_graph *irg) {
303 return irg->current_block;
307 _set_irg_current_block(ir_graph *irg, ir_node *node) {
308 irg->current_block = node;
311 static INLINE entity *
312 _get_irg_entity(const ir_graph *irg) {
313 assert(irg && irg->ent);
318 _set_irg_entity(ir_graph *irg, entity *ent) {
323 _get_irg_frame_type(const ir_graph *irg) {
324 assert(irg && irg->frame_type);
325 return irg->frame_type;
329 _set_irg_frame_type(ir_graph *irg, type *ftp) {
330 assert(is_Class_type(ftp));
331 irg->frame_type = ftp;
334 static INLINE struct obstack *
335 _get_irg_obstack(const ir_graph *irg) {
340 static INLINE irg_phase_state
341 _get_irg_phase_state(const ir_graph *irg) {
342 return irg->phase_state;
346 _set_irg_phase_low(ir_graph *irg) {
347 irg->phase_state = phase_low;
350 static INLINE op_pin_state
351 _get_irg_pinned(const ir_graph *irg) {
352 return irg->op_pin_state_pinned;
355 static INLINE irg_outs_state
356 _get_irg_outs_state(const ir_graph *irg) {
357 return irg->outs_state;
361 _set_irg_outs_inconsistent(ir_graph *irg) {
362 irg->outs_state = outs_inconsistent;
365 static INLINE irg_dom_state
366 _get_irg_dom_state(const ir_graph *irg) {
367 return irg->dom_state;
371 _set_irg_dom_inconsistent(ir_graph *irg) {
372 irg->dom_state = dom_inconsistent;
375 static INLINE irg_loopinfo_state
376 _get_irg_loopinfo_state(const ir_graph *irg) {
377 return irg->loopinfo_state;
381 _set_irg_loopinfo_state(ir_graph *irg, irg_loopinfo_state s) {
382 irg->loopinfo_state = s;
386 _set_irg_pinned(ir_graph *irg, op_pin_state p) {
387 irg->op_pin_state_pinned = p;
390 static INLINE irg_callee_info_state
391 _get_irg_callee_info_state(const ir_graph *irg) {
392 return irg->callee_info_state;
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();
399 irg->callee_info_state = s;
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);
407 static INLINE irg_inline_property
408 _get_irg_inline_property(const ir_graph *irg) {
409 return irg->inline_property;
413 _set_irg_inline_property(ir_graph *irg, irg_inline_property s) {
414 irg->inline_property = s;
418 _set_irg_link(ir_graph *irg, void *thing) {
423 _get_irg_link(const ir_graph *irg) {
427 static INLINE unsigned long
428 _get_irg_visited(const ir_graph *irg) {
432 static INLINE unsigned long
433 _get_irg_block_visited(const ir_graph *irg) {
434 return irg->block_visited;
438 _set_irg_block_visited(ir_graph *irg, unsigned long visited) {
439 irg->block_visited = visited;
443 _inc_irg_block_visited(ir_graph *irg) {
444 ++irg->block_visited;
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)
501 # endif /* _IRGRAPH_T_H_ */