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_recursion_depth;
104 /* -- Fields for Walking the graph -- */
105 unsigned long visited; /**< this flag is an identifier for
106 ir walk. it will be incremented
107 every time someone walks through
109 unsigned long block_visited; /**< same as visited, for a complete block */
111 int graph_nr; /**< a unique graph number for each graph to make output
116 void init_irgraph(void);
118 /** Make a rudimentary ir graph for the constant code.
119 Must look like a correct irg, spare everything else. */
120 ir_graph *new_const_code_irg(void);
123 * Set the op_pin_state_pinned state of a graph.
129 set_irg_pinned (ir_graph *irg, op_pin_state p);
131 /** Returns the obstack associated with the graph. */
132 struct obstack *get_irg_obstack(ir_graph *irg);
135 * Returns true if the node n is allocated on the storage of graph irg.
137 * @param irg the IR graph
138 * @param n the IR node
140 int node_is_in_irgs_storage(ir_graph *irg, ir_node *n);
142 /*-------------------------------------------------------------------*/
143 /* inline functions for graphs */
144 /*-------------------------------------------------------------------*/
147 __is_ir_graph(void *thing) {
148 return (get_kind(thing) == k_ir_graph);
151 /** Returns the start block of a graph. */
152 static INLINE ir_node *
153 __get_irg_start_block(ir_graph *irg)
155 return irg->start_block;
159 __set_irg_start_block(ir_graph *irg, ir_node *node)
161 irg->start_block = node;
164 static INLINE ir_node *
165 __get_irg_start(ir_graph *irg)
171 __set_irg_start(ir_graph *irg, ir_node *node)
176 static INLINE ir_node *
177 __get_irg_end_block(ir_graph *irg)
179 return irg->end_block;
183 __set_irg_end_block(ir_graph *irg, ir_node *node)
185 irg->end_block = node;
188 static INLINE ir_node *
189 __get_irg_end(ir_graph *irg)
195 __set_irg_end(ir_graph *irg, ir_node *node)
200 static INLINE ir_node *
201 __get_irg_end_reg(ir_graph *irg) {
205 static INLINE ir_node *
206 __get_irg_end_except (ir_graph *irg) {
207 return irg->end_except;
210 static INLINE ir_node *
211 __get_irg_cstore(ir_graph *irg)
217 __set_irg_cstore(ir_graph *irg, ir_node *node)
222 static INLINE ir_node *
223 __get_irg_frame(ir_graph *irg)
229 __set_irg_frame(ir_graph *irg, ir_node *node)
234 static INLINE ir_node *
235 __get_irg_globals(ir_graph *irg)
241 __set_irg_globals(ir_graph *irg, ir_node *node)
246 static INLINE ir_node *
247 __get_irg_initial_mem(ir_graph *irg)
249 return irg->initial_mem;
253 __set_irg_initial_mem(ir_graph *irg, ir_node *node)
255 irg->initial_mem = node;
258 static INLINE ir_node *
259 __get_irg_args(ir_graph *irg)
265 __set_irg_args(ir_graph *irg, ir_node *node)
270 static INLINE ir_node *
271 __get_irg_bad(ir_graph *irg)
277 __set_irg_bad(ir_graph *irg, ir_node *node)
282 static INLINE ir_node *
283 __get_irg_current_block(ir_graph *irg)
285 return irg->current_block;
289 __set_irg_current_block(ir_graph *irg, ir_node *node)
291 irg->current_block = node;
294 static INLINE entity *
295 __get_irg_ent(ir_graph *irg)
297 assert(irg && irg->ent);
302 __set_irg_ent(ir_graph *irg, entity *ent)
308 __get_irg_frame_type(ir_graph *irg)
310 assert(irg && irg->frame_type);
311 return irg->frame_type;
315 __set_irg_frame_type(ir_graph *irg, type *ftp)
317 assert(is_class_type(ftp));
318 irg->frame_type = ftp;
321 static INLINE struct obstack *
322 __get_irg_obstack(ir_graph *irg) {
327 static INLINE irg_phase_state
328 __get_irg_phase_state(ir_graph *irg) {
329 return irg->phase_state;
333 __set_irg_phase_low(ir_graph *irg) {
334 irg->phase_state = phase_low;
337 static INLINE op_pin_state
338 __get_irg_pinned(ir_graph *irg) {
339 return irg->op_pin_state_pinned;
342 static INLINE irg_outs_state
343 __get_irg_outs_state(ir_graph *irg) {
344 return irg->outs_state;
348 __set_irg_outs_inconsistent(ir_graph *irg) {
349 irg->outs_state = outs_inconsistent;
352 static INLINE irg_dom_state
353 __get_irg_dom_state(ir_graph *irg) {
354 return irg->dom_state;
358 __set_irg_dom_inconsistent(ir_graph *irg) {
359 irg->dom_state = dom_inconsistent;
362 static INLINE irg_loopinfo_state
363 __get_irg_loopinfo_state(ir_graph *irg) {
364 return irg->loopinfo_state;
368 __set_irg_loopinfo_state(ir_graph *irg, irg_loopinfo_state s) {
369 irg->loopinfo_state = s;
373 __set_irg_pinned(ir_graph *irg, op_pin_state p) {
374 irg->op_pin_state_pinned = p;
377 static INLINE irg_callee_info_state
378 __get_irg_callee_info_state(ir_graph *irg) {
379 return irg->callee_info_state;
383 __set_irg_callee_info_state(ir_graph *irg, irg_callee_info_state s) {
384 irg_callee_info_state irp_state = get_irp_callee_info_state();
386 irg->callee_info_state = s;
388 /* I could compare ... but who knows? */
389 if ((irp_state == irg_callee_info_consistent) ||
390 ((irp_state == irg_callee_info_inconsistent) && (s == irg_callee_info_none)))
391 set_irp_callee_info_state(s);
394 static INLINE irg_inline_property
395 __get_irg_inline_property(ir_graph *irg) {
396 return irg->inline_property;
400 __set_irg_inline_property(ir_graph *irg, irg_inline_property s) {
401 irg->inline_property = s;
405 __set_irg_link(ir_graph *irg, void *thing) {
410 __get_irg_link(ir_graph *irg) {
414 static INLINE unsigned long
415 __get_irg_visited(ir_graph *irg)
420 static INLINE unsigned long
421 __get_irg_block_visited(ir_graph *irg)
423 return irg->block_visited;
427 __set_irg_block_visited(ir_graph *irg, unsigned long visited)
429 irg->block_visited = visited;
433 __inc_irg_block_visited(ir_graph *irg)
435 ++irg->block_visited;
438 #define is_ir_graph(thing) __is_ir_graph(thing)
439 #define get_irg_start_block(irg) __get_irg_start_block(irg)
440 #define set_irg_start_block(irg, node) __set_irg_start_block(irg, node)
441 #define get_irg_start(irg) __get_irg_start(irg)
442 #define set_irg_start(irg, node) __set_irg_start(irg, node)
443 #define get_irg_end_block(irg) __get_irg_end_block(irg)
444 #define set_irg_end_block(irg, node) __set_irg_end_block(irg, node)
445 #define get_irg_end(irg) __get_irg_end(irg)
446 #define set_irg_end(irg, node) __set_irg_end(irg, node)
447 #define get_irg_end_reg(irg) __get_irg_end_reg(irg)
448 #define get_irg_end_except(irg) __get_irg_end_except(irg)
449 #define get_irg_cstore(irg) __get_irg_cstore(irg)
450 #define set_irg_cstore(irg, node) __set_irg_cstore(irg, node)
451 #define get_irg_frame(irg) __get_irg_frame(irg)
452 #define set_irg_frame(irg, node) __set_irg_frame(irg, node)
453 #define get_irg_globals(irg) __get_irg_globals(irg)
454 #define set_irg_globals(irg, node) __set_irg_globals(irg, node)
455 #define get_irg_initial_mem(irg) __get_irg_initial_mem(irg)
456 #define set_irg_initial_mem(irg, node) __set_irg_initial_mem(irg, node)
457 #define get_irg_args(irg) __get_irg_args(irg)
458 #define set_irg_args(irg, node) __set_irg_args(irg, node)
459 #define get_irg_bad(irg) __get_irg_bad(irg)
460 #define set_irg_bad(irg, node) __set_irg_bad(irg, node)
461 #define get_irg_current_block(irg) __get_irg_current_block(irg)
462 #define set_irg_current_block(irg, node) __set_irg_current_block(irg, node)
463 #define get_irg_entity(irg) __get_irg_ent(irg)
464 #define set_irg_entity(irg, ent) __set_irg_ent(irg, ent)
465 #define get_irg_frame_type(irg) __get_irg_frame_type(irg)
466 #define set_irg_frame_type(irg, ftp) __set_irg_frame_type(irg, ftp)
467 #define get_irg_obstack(irg) __get_irg_obstack(irg)
468 #define get_irg_phase_state(irg) __get_irg_phase_state(irg)
469 #define set_irg_phase_low(irg) __set_irg_phase_low(irg)
470 #define get_irg_pinned(irg) __get_irg_pinned(irg)
471 #define get_irg_outs_state(irg) __get_irg_outs_state(irg)
472 #define set_irg_outs_inconsistent(irg) __set_irg_outs_inconsistent(irg)
473 #define get_irg_dom_state(irg) __get_irg_dom_state(irg)
474 #define set_irg_dom_inconsistent(irg) __set_irg_dom_inconsistent(irg)
475 #define get_irg_loopinfo_state(irg) __get_irg_loopinfo_state(irg)
476 #define set_irg_loopinfo_state(irg, s) __set_irg_loopinfo_state(irg, s)
477 #define set_irg_pinned(irg, p) __set_irg_pinned(irg, p)
478 #define get_irg_callee_info_state(irg) __get_irg_callee_info_state(irg)
479 #define set_irg_callee_info_state(irg, s) __set_irg_callee_info_state(irg, s)
480 #define get_irg_inline_property(irg) __get_irg_inline_property(irg)
481 #define set_irg_inline_property(irg, s) __set_irg_inline_property(irg, s)
482 #define set_irg_link(irg, thing) __set_irg_link(irg, thing)
483 #define get_irg_link(irg) __get_irg_link(irg)
484 #define get_irg_visited(irg) __get_irg_visited(irg)
485 #define get_irg_block_visited(irg) __get_irg_block_visited(irg)
486 #define set_irg_block_visited(irg, v) __set_irg_block_visited(irg, v)
487 #define inc_irg_block_visited(irg) __inc_irg_block_visited(irg)
489 # endif /* _IRGRAPH_T_H_ */