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"
36 #define FRAME_TP_SUFFIX "frame_tp"
38 /** ir_graph holds all information for a procedure */
40 firm_kind kind; /**< always set to k_ir_graph*/
41 /* -- Basics of the representation -- */
42 struct entity *ent; /**< The entity of this procedure, i.e.,
43 the type of the procedure and the
44 class it belongs to. */
45 struct type *frame_type; /**< A class type representing the stack frame.
46 Can include "inner" methods. */
47 struct ir_node *start_block; /**< block the start node will belong to */
48 struct ir_node *start; /**< start node of this ir_graph */
49 struct ir_node *end_block; /**< block the end node will belong to */
50 struct ir_node *end; /**< end node of this ir_graph */
51 struct ir_node *end_reg; /**< end node of this ir_graph */
52 struct ir_node *end_except; /**< end node of this ir_graph */
53 struct ir_node *cstore; /**< constant store -- no more needed!! */
54 struct ir_node *frame; /**< method's frame */
55 struct ir_node *globals; /**< pointer to the data segment containing all
56 globals as well as global procedures. */
57 struct ir_node *initial_mem; /**< initial memory of this graph */
58 struct ir_node *args; /**< methods arguments */
59 struct ir_node *bad; /**< bad node of this ir_graph, the one and
61 /* GL removed: we need unknown with mode for analyses. */
62 /* struct ir_node *unknown;*/ /**< unknown node of this ir_graph */
63 struct obstack *obst; /**< obstack where all of the ir_nodes live */
64 struct ir_node *current_block; /**< block for newly gen_*()-erated
67 /* -- Fields indicating different states of irgraph -- */
68 irg_phase_state phase_state; /**< compiler phase */
69 op_pin_state op_pin_state_pinned; /**< Flag for status of nodes */
70 irg_outs_state outs_state; /**< Out edges. */
71 irg_dom_state dom_state; /**< Dominator information */
72 irg_typeinfo_state typeinfo_state; /**< Validity of type information */
73 irg_callee_info_state callee_info_state; /**< Validity of callee information */
74 irg_inline_property inline_property; /**< How to handle inlineing. */
75 irg_loopinfo_state loopinfo_state; /**< state of loop information */
77 /* -- Fields for construction -- */
78 #if USE_EXPLICIT_PHI_IN_STACK
79 struct Phi_in_stack *Phi_in_stack; /**< needed for automatic Phi construction */
81 int n_loc; /**< number of local variable in this
82 procedure including procedure parameters. */
84 /* -- Fields for optimizations / analysis information -- */
85 pset *value_table; /**< hash table for global value numbering (cse)
86 for optimizing use in iropt.c */
87 struct ir_node **outs; /**< Space for the out arrays. */
90 int n_outs; /* < Size wasted for outs */
91 #endif /* defined DEBUG_libfirm */
92 struct ir_loop *loop; /**< The outermost loop */
93 void *link; /**< A void* field to link any information to
96 ir_graph **callers; /**< For callgraph analyses. */
97 int *caller_isbe; /**< For callgraph analyses: set if backedge. */
98 ir_graph **callees; /**< For callgraph analyses. */
99 int *callee_isbe; /**< For callgraph analyses: set if backedge. */
100 int callgraph_loop_depth;
101 int callgraph_weighted_loop_depth;
102 int callgraph_recursion_depth;
105 /* -- Fields for Walking the graph -- */
106 unsigned long visited; /**< this flag is an identifier for
107 ir walk. it will be incremented
108 every time someone walks through
110 unsigned long block_visited; /**< same as visited, for a complete block */
112 int graph_nr; /**< a unique graph number for each graph to make output
117 void init_irgraph(void);
119 /** Make a rudimentary ir graph for the constant code.
120 Must look like a correct irg, spare everything else. */
121 ir_graph *new_const_code_irg(void);
124 * Set the op_pin_state_pinned state of a graph.
130 set_irg_pinned (ir_graph *irg, op_pin_state p);
132 /** Returns the obstack associated with the graph. */
133 struct obstack *get_irg_obstack(ir_graph *irg);
136 * Returns true if the node n is allocated on the storage of graph irg.
138 * @param irg the IR graph
139 * @param n the IR node
141 int node_is_in_irgs_storage(ir_graph *irg, ir_node *n);
143 /*-------------------------------------------------------------------*/
144 /* inline functions for graphs */
145 /*-------------------------------------------------------------------*/
148 __is_ir_graph(void *thing) {
149 return (get_kind(thing) == k_ir_graph);
152 /** Returns the start block of a graph. */
153 static INLINE ir_node *
154 __get_irg_start_block(ir_graph *irg)
156 return irg->start_block;
160 __set_irg_start_block(ir_graph *irg, ir_node *node)
162 irg->start_block = node;
165 static INLINE ir_node *
166 __get_irg_start(ir_graph *irg)
172 __set_irg_start(ir_graph *irg, ir_node *node)
177 static INLINE ir_node *
178 __get_irg_end_block(ir_graph *irg)
180 return irg->end_block;
184 __set_irg_end_block(ir_graph *irg, ir_node *node)
186 irg->end_block = node;
189 static INLINE ir_node *
190 __get_irg_end(ir_graph *irg)
196 __set_irg_end(ir_graph *irg, ir_node *node)
201 static INLINE ir_node *
202 __get_irg_end_reg(ir_graph *irg) {
206 static INLINE ir_node *
207 __get_irg_end_except (ir_graph *irg) {
208 return irg->end_except;
211 static INLINE ir_node *
212 __get_irg_cstore(ir_graph *irg)
218 __set_irg_cstore(ir_graph *irg, ir_node *node)
223 static INLINE ir_node *
224 __get_irg_frame(ir_graph *irg)
230 __set_irg_frame(ir_graph *irg, ir_node *node)
235 static INLINE ir_node *
236 __get_irg_globals(ir_graph *irg)
242 __set_irg_globals(ir_graph *irg, ir_node *node)
247 static INLINE ir_node *
248 __get_irg_initial_mem(ir_graph *irg)
250 return irg->initial_mem;
254 __set_irg_initial_mem(ir_graph *irg, ir_node *node)
256 irg->initial_mem = node;
259 static INLINE ir_node *
260 __get_irg_args(ir_graph *irg)
266 __set_irg_args(ir_graph *irg, ir_node *node)
271 static INLINE ir_node *
272 __get_irg_bad(ir_graph *irg)
278 __set_irg_bad(ir_graph *irg, ir_node *node)
283 static INLINE ir_node *
284 __get_irg_current_block(ir_graph *irg)
286 return irg->current_block;
290 __set_irg_current_block(ir_graph *irg, ir_node *node)
292 irg->current_block = node;
295 static INLINE entity *
296 __get_irg_ent(ir_graph *irg)
298 assert(irg && irg->ent);
303 __set_irg_ent(ir_graph *irg, entity *ent)
309 __get_irg_frame_type(ir_graph *irg)
311 assert(irg && irg->frame_type);
312 return irg->frame_type;
316 __set_irg_frame_type(ir_graph *irg, type *ftp)
318 assert(is_class_type(ftp));
319 irg->frame_type = ftp;
322 static INLINE struct obstack *
323 __get_irg_obstack(ir_graph *irg) {
328 static INLINE irg_phase_state
329 __get_irg_phase_state(ir_graph *irg) {
330 return irg->phase_state;
334 __set_irg_phase_low(ir_graph *irg) {
335 irg->phase_state = phase_low;
338 static INLINE op_pin_state
339 __get_irg_pinned(ir_graph *irg) {
340 return irg->op_pin_state_pinned;
343 static INLINE irg_outs_state
344 __get_irg_outs_state(ir_graph *irg) {
345 return irg->outs_state;
349 __set_irg_outs_inconsistent(ir_graph *irg) {
350 irg->outs_state = outs_inconsistent;
353 static INLINE irg_dom_state
354 __get_irg_dom_state(ir_graph *irg) {
355 return irg->dom_state;
359 __set_irg_dom_inconsistent(ir_graph *irg) {
360 irg->dom_state = dom_inconsistent;
363 static INLINE irg_loopinfo_state
364 __get_irg_loopinfo_state(ir_graph *irg) {
365 return irg->loopinfo_state;
369 __set_irg_loopinfo_state(ir_graph *irg, irg_loopinfo_state s) {
370 irg->loopinfo_state = s;
374 __set_irg_pinned(ir_graph *irg, op_pin_state p) {
375 irg->op_pin_state_pinned = p;
378 static INLINE irg_callee_info_state
379 __get_irg_callee_info_state(ir_graph *irg) {
380 return irg->callee_info_state;
384 __set_irg_callee_info_state(ir_graph *irg, irg_callee_info_state s) {
385 irg_callee_info_state irp_state = get_irp_callee_info_state();
387 irg->callee_info_state = s;
389 /* I could compare ... but who knows? */
390 if ((irp_state == irg_callee_info_consistent) ||
391 ((irp_state == irg_callee_info_inconsistent) && (s == irg_callee_info_none)))
392 set_irp_callee_info_state(s);
395 static INLINE irg_inline_property
396 __get_irg_inline_property(ir_graph *irg) {
397 return irg->inline_property;
401 __set_irg_inline_property(ir_graph *irg, irg_inline_property s) {
402 irg->inline_property = s;
406 __set_irg_link(ir_graph *irg, void *thing) {
411 __get_irg_link(ir_graph *irg) {
415 static INLINE unsigned long
416 __get_irg_visited(ir_graph *irg)
421 static INLINE unsigned long
422 __get_irg_block_visited(ir_graph *irg)
424 return irg->block_visited;
428 __set_irg_block_visited(ir_graph *irg, unsigned long visited)
430 irg->block_visited = visited;
434 __inc_irg_block_visited(ir_graph *irg)
436 ++irg->block_visited;
439 #define is_ir_graph(thing) __is_ir_graph(thing)
440 #define get_irg_start_block(irg) __get_irg_start_block(irg)
441 #define set_irg_start_block(irg, node) __set_irg_start_block(irg, node)
442 #define get_irg_start(irg) __get_irg_start(irg)
443 #define set_irg_start(irg, node) __set_irg_start(irg, node)
444 #define get_irg_end_block(irg) __get_irg_end_block(irg)
445 #define set_irg_end_block(irg, node) __set_irg_end_block(irg, node)
446 #define get_irg_end(irg) __get_irg_end(irg)
447 #define set_irg_end(irg, node) __set_irg_end(irg, node)
448 #define get_irg_end_reg(irg) __get_irg_end_reg(irg)
449 #define get_irg_end_except(irg) __get_irg_end_except(irg)
450 #define get_irg_cstore(irg) __get_irg_cstore(irg)
451 #define set_irg_cstore(irg, node) __set_irg_cstore(irg, node)
452 #define get_irg_frame(irg) __get_irg_frame(irg)
453 #define set_irg_frame(irg, node) __set_irg_frame(irg, node)
454 #define get_irg_globals(irg) __get_irg_globals(irg)
455 #define set_irg_globals(irg, node) __set_irg_globals(irg, node)
456 #define get_irg_initial_mem(irg) __get_irg_initial_mem(irg)
457 #define set_irg_initial_mem(irg, node) __set_irg_initial_mem(irg, node)
458 #define get_irg_args(irg) __get_irg_args(irg)
459 #define set_irg_args(irg, node) __set_irg_args(irg, node)
460 #define get_irg_bad(irg) __get_irg_bad(irg)
461 #define set_irg_bad(irg, node) __set_irg_bad(irg, node)
462 #define get_irg_current_block(irg) __get_irg_current_block(irg)
463 #define set_irg_current_block(irg, node) __set_irg_current_block(irg, node)
464 #define get_irg_entity(irg) __get_irg_ent(irg)
465 #define set_irg_entity(irg, ent) __set_irg_ent(irg, ent)
466 #define get_irg_frame_type(irg) __get_irg_frame_type(irg)
467 #define set_irg_frame_type(irg, ftp) __set_irg_frame_type(irg, ftp)
468 #define get_irg_obstack(irg) __get_irg_obstack(irg)
469 #define get_irg_phase_state(irg) __get_irg_phase_state(irg)
470 #define set_irg_phase_low(irg) __set_irg_phase_low(irg)
471 #define get_irg_pinned(irg) __get_irg_pinned(irg)
472 #define get_irg_outs_state(irg) __get_irg_outs_state(irg)
473 #define set_irg_outs_inconsistent(irg) __set_irg_outs_inconsistent(irg)
474 #define get_irg_dom_state(irg) __get_irg_dom_state(irg)
475 #define set_irg_dom_inconsistent(irg) __set_irg_dom_inconsistent(irg)
476 #define get_irg_loopinfo_state(irg) __get_irg_loopinfo_state(irg)
477 #define set_irg_loopinfo_state(irg, s) __set_irg_loopinfo_state(irg, s)
478 #define set_irg_pinned(irg, p) __set_irg_pinned(irg, p)
479 #define get_irg_callee_info_state(irg) __get_irg_callee_info_state(irg)
480 #define set_irg_callee_info_state(irg, s) __set_irg_callee_info_state(irg, s)
481 #define get_irg_inline_property(irg) __get_irg_inline_property(irg)
482 #define set_irg_inline_property(irg, s) __set_irg_inline_property(irg, s)
483 #define set_irg_link(irg, thing) __set_irg_link(irg, thing)
484 #define get_irg_link(irg) __get_irg_link(irg)
485 #define get_irg_visited(irg) __get_irg_visited(irg)
486 #define get_irg_block_visited(irg) __get_irg_block_visited(irg)
487 #define set_irg_block_visited(irg, v) __set_irg_block_visited(irg, v)
488 #define inc_irg_block_visited(irg) __inc_irg_block_visited(irg)
490 # endif /* _IRGRAPH_T_H_ */