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;
106 int callgraph_recursion_depth;
109 /* -- Fields for Walking the graph -- */
110 unsigned long visited; /**< this flag is an identifier for
111 ir walk. it will be incremented
112 every time someone walks through
114 unsigned long block_visited; /**< same as visited, for a complete block */
116 int graph_nr; /**< a unique graph number for each graph to make output
122 * Initializes the graph construction module
124 void init_irgraph(void);
126 /* Internal constructor that does not add to irp_irgs or the like. */
127 ir_graph *new_r_ir_graph (entity *ent, int n_loc);
129 /** Make a rudimentary ir graph for the constant code.
130 Must look like a correct irg, spare everything else. */
131 ir_graph *new_const_code_irg(void);
134 * Set the op_pin_state_pinned state of a graph.
136 * @param irg the IR graph
137 * @param p new pin state
140 set_irg_pinned (ir_graph *irg, op_pin_state p);
142 /** Returns the obstack associated with the graph. */
143 struct obstack *get_irg_obstack(const ir_graph *irg);
146 * Returns true if the node n is allocated on the storage of graph irg.
148 * @param irg the IR graph
149 * @param n the IR node
151 int node_is_in_irgs_storage(ir_graph *irg, ir_node *n);
153 /*-------------------------------------------------------------------*/
154 /* inline functions for graphs */
155 /*-------------------------------------------------------------------*/
157 extern int __interprocedural_view;
160 __get_interprocedural_view(void) {
161 return __interprocedural_view;
165 __is_ir_graph(const void *thing) {
166 return (get_kind(thing) == k_ir_graph);
169 /** Returns the start block of a graph. */
170 static INLINE ir_node *
171 __get_irg_start_block(const ir_graph *irg) {
172 return irg->start_block;
176 __set_irg_start_block(ir_graph *irg, ir_node *node) {
177 irg->start_block = node;
180 static INLINE ir_node *
181 __get_irg_start(const ir_graph *irg) {
186 __set_irg_start(ir_graph *irg, ir_node *node) {
190 static INLINE ir_node *
191 __get_irg_end_block(const ir_graph *irg) {
192 return irg->end_block;
196 __set_irg_end_block(ir_graph *irg, ir_node *node) {
197 irg->end_block = node;
200 static INLINE ir_node *
201 __get_irg_end(const ir_graph *irg) {
206 __set_irg_end(ir_graph *irg, ir_node *node) {
210 static INLINE ir_node *
211 __get_irg_end_reg(const ir_graph *irg) {
215 static INLINE ir_node *
216 __get_irg_end_except (const ir_graph *irg) {
217 return irg->end_except;
220 static INLINE ir_node *
221 __get_irg_cstore(const ir_graph *irg) {
226 __set_irg_cstore(ir_graph *irg, ir_node *node) {
230 static INLINE ir_node *
231 __get_irg_frame(const ir_graph *irg) {
236 __set_irg_frame(ir_graph *irg, ir_node *node) {
240 static INLINE ir_node *
241 __get_irg_globals(const ir_graph *irg) {
246 __set_irg_globals(ir_graph *irg, ir_node *node) {
250 static INLINE ir_node *
251 __get_irg_initial_mem(const ir_graph *irg) {
252 return irg->initial_mem;
256 __set_irg_initial_mem(ir_graph *irg, ir_node *node) {
257 irg->initial_mem = node;
260 static INLINE ir_node *
261 __get_irg_args(const ir_graph *irg) {
266 __set_irg_args(ir_graph *irg, ir_node *node) {
270 static INLINE ir_node **
271 __get_irg_proj_args(const ir_graph *irg) {
272 return irg->proj_args;
276 __set_irg_proj_args(ir_graph *irg, ir_node **nodes) {
277 irg->proj_args = nodes;
280 static INLINE ir_node *
281 __get_irg_bad(const ir_graph *irg) {
286 __set_irg_bad(ir_graph *irg, ir_node *node) {
290 static INLINE ir_node *
291 __get_irg_no_mem(const ir_graph *irg) {
296 __set_irg_no_mem(ir_graph *irg, ir_node *node) {
299 static INLINE ir_node *
300 __get_irg_current_block(const ir_graph *irg) {
301 return irg->current_block;
305 __set_irg_current_block(ir_graph *irg, ir_node *node) {
306 irg->current_block = node;
309 static INLINE entity *
310 __get_irg_entity(const ir_graph *irg) {
311 assert(irg && irg->ent);
316 __set_irg_entity(ir_graph *irg, entity *ent) {
321 __get_irg_frame_type(const ir_graph *irg) {
322 assert(irg && irg->frame_type);
323 return irg->frame_type;
327 __set_irg_frame_type(ir_graph *irg, type *ftp) {
328 assert(is_class_type(ftp));
329 irg->frame_type = ftp;
332 static INLINE struct obstack *
333 __get_irg_obstack(const ir_graph *irg) {
338 static INLINE irg_phase_state
339 __get_irg_phase_state(const ir_graph *irg) {
340 return irg->phase_state;
344 __set_irg_phase_low(ir_graph *irg) {
345 irg->phase_state = phase_low;
348 static INLINE op_pin_state
349 __get_irg_pinned(const ir_graph *irg) {
350 return irg->op_pin_state_pinned;
353 static INLINE irg_outs_state
354 __get_irg_outs_state(const ir_graph *irg) {
355 return irg->outs_state;
359 __set_irg_outs_inconsistent(ir_graph *irg) {
360 irg->outs_state = outs_inconsistent;
363 static INLINE irg_dom_state
364 __get_irg_dom_state(const ir_graph *irg) {
365 return irg->dom_state;
369 __set_irg_dom_inconsistent(ir_graph *irg) {
370 irg->dom_state = dom_inconsistent;
373 static INLINE irg_loopinfo_state
374 __get_irg_loopinfo_state(const ir_graph *irg) {
375 return irg->loopinfo_state;
379 __set_irg_loopinfo_state(ir_graph *irg, irg_loopinfo_state s) {
380 irg->loopinfo_state = s;
384 __set_irg_pinned(ir_graph *irg, op_pin_state p) {
385 irg->op_pin_state_pinned = p;
388 static INLINE irg_callee_info_state
389 __get_irg_callee_info_state(const ir_graph *irg) {
390 return irg->callee_info_state;
394 __set_irg_callee_info_state(ir_graph *irg, irg_callee_info_state s) {
395 irg_callee_info_state irp_state = get_irp_callee_info_state();
397 irg->callee_info_state = s;
399 /* I could compare ... but who knows? */
400 if ((irp_state == irg_callee_info_consistent) ||
401 ((irp_state == irg_callee_info_inconsistent) && (s == irg_callee_info_none)))
402 set_irp_callee_info_state(s);
405 static INLINE irg_inline_property
406 __get_irg_inline_property(const ir_graph *irg) {
407 return irg->inline_property;
411 __set_irg_inline_property(ir_graph *irg, irg_inline_property s) {
412 irg->inline_property = s;
416 __set_irg_link(ir_graph *irg, void *thing) {
421 __get_irg_link(const ir_graph *irg) {
425 static INLINE unsigned long
426 __get_irg_visited(const ir_graph *irg) {
430 static INLINE unsigned long
431 __get_irg_block_visited(const ir_graph *irg) {
432 return irg->block_visited;
436 __set_irg_block_visited(ir_graph *irg, unsigned long visited) {
437 irg->block_visited = visited;
441 __inc_irg_block_visited(ir_graph *irg) {
442 ++irg->block_visited;
445 #define get_interprocedural_view() __get_interprocedural_view()
446 #define is_ir_graph(thing) __is_ir_graph(thing)
447 #define get_irg_start_block(irg) __get_irg_start_block(irg)
448 #define set_irg_start_block(irg, node) __set_irg_start_block(irg, node)
449 #define get_irg_start(irg) __get_irg_start(irg)
450 #define set_irg_start(irg, node) __set_irg_start(irg, node)
451 #define get_irg_end_block(irg) __get_irg_end_block(irg)
452 #define set_irg_end_block(irg, node) __set_irg_end_block(irg, node)
453 #define get_irg_end(irg) __get_irg_end(irg)
454 #define set_irg_end(irg, node) __set_irg_end(irg, node)
455 #define get_irg_end_reg(irg) __get_irg_end_reg(irg)
456 #define get_irg_end_except(irg) __get_irg_end_except(irg)
457 #define get_irg_cstore(irg) __get_irg_cstore(irg)
458 #define set_irg_cstore(irg, node) __set_irg_cstore(irg, node)
459 #define get_irg_frame(irg) __get_irg_frame(irg)
460 #define set_irg_frame(irg, node) __set_irg_frame(irg, node)
461 #define get_irg_globals(irg) __get_irg_globals(irg)
462 #define set_irg_globals(irg, node) __set_irg_globals(irg, node)
463 #define get_irg_initial_mem(irg) __get_irg_initial_mem(irg)
464 #define set_irg_initial_mem(irg, node) __set_irg_initial_mem(irg, node)
465 #define get_irg_args(irg) __get_irg_args(irg)
466 #define set_irg_args(irg, node) __set_irg_args(irg, node)
467 #define get_irg_bad(irg) __get_irg_bad(irg)
468 #define set_irg_bad(irg, node) __set_irg_bad(irg, node)
469 #define get_irg_no_mem(irg) __get_irg_no_mem(irg)
470 #define set_irg_no_mem(irg, node) __set_irg_no_mem(irg, node)
471 #define get_irg_current_block(irg) __get_irg_current_block(irg)
472 #define set_irg_current_block(irg, node) __set_irg_current_block(irg, node)
473 #define get_irg_entity(irg) __get_irg_entity(irg)
474 #define set_irg_entity(irg, ent) __set_irg_entity(irg, ent)
475 #define get_irg_frame_type(irg) __get_irg_frame_type(irg)
476 #define set_irg_frame_type(irg, ftp) __set_irg_frame_type(irg, ftp)
477 #define get_irg_obstack(irg) __get_irg_obstack(irg)
478 #define get_irg_phase_state(irg) __get_irg_phase_state(irg)
479 #define set_irg_phase_low(irg) __set_irg_phase_low(irg)
480 #define get_irg_pinned(irg) __get_irg_pinned(irg)
481 #define get_irg_outs_state(irg) __get_irg_outs_state(irg)
482 #define set_irg_outs_inconsistent(irg) __set_irg_outs_inconsistent(irg)
483 #define get_irg_dom_state(irg) __get_irg_dom_state(irg)
484 #define set_irg_dom_inconsistent(irg) __set_irg_dom_inconsistent(irg)
485 #define get_irg_loopinfo_state(irg) __get_irg_loopinfo_state(irg)
486 #define set_irg_loopinfo_state(irg, s) __set_irg_loopinfo_state(irg, s)
487 #define set_irg_pinned(irg, p) __set_irg_pinned(irg, p)
488 #define get_irg_callee_info_state(irg) __get_irg_callee_info_state(irg)
489 #define set_irg_callee_info_state(irg, s) __set_irg_callee_info_state(irg, s)
490 #define get_irg_inline_property(irg) __get_irg_inline_property(irg)
491 #define set_irg_inline_property(irg, s) __set_irg_inline_property(irg, s)
492 #define set_irg_link(irg, thing) __set_irg_link(irg, thing)
493 #define get_irg_link(irg) __get_irg_link(irg)
494 #define get_irg_visited(irg) __get_irg_visited(irg)
495 #define get_irg_block_visited(irg) __get_irg_block_visited(irg)
496 #define set_irg_block_visited(irg, v) __set_irg_block_visited(irg, v)
497 #define inc_irg_block_visited(irg) __inc_irg_block_visited(irg)
499 # endif /* _IRGRAPH_T_H_ */