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"
37 #define FRAME_TP_SUFFIX "frame_tp"
39 /** ir_graph holds all information for a procedure */
41 firm_kind kind; /**< always set to k_ir_graph*/
42 /* -- Basics of the representation -- */
43 struct entity *ent; /**< The entity of this procedure, i.e.,
44 the type of the procedure and the
45 class it belongs to. */
46 struct type *frame_type; /**< A class type representing the stack frame.
47 Can include "inner" methods. */
48 struct ir_node *start_block; /**< block the start node will belong to */
49 struct ir_node *start; /**< start node of this ir_graph */
50 struct ir_node *end_block; /**< block the end node will belong to */
51 struct ir_node *end; /**< end node of this ir_graph */
52 struct ir_node *end_reg; /**< end node of this ir_graph */
53 struct ir_node *end_except; /**< end node of this ir_graph */
54 struct ir_node *cstore; /**< constant store -- no more needed!! */
55 struct ir_node *frame; /**< method's frame */
56 struct ir_node *globals; /**< pointer to the data segment containing all
57 globals as well as global procedures. */
58 struct ir_node *initial_mem; /**< initial memory of this graph */
59 struct ir_node *args; /**< methods arguments */
60 struct ir_node *bad; /**< bad node of this ir_graph, the one and
62 /* GL removed: we need unknown with mode for analyses. */
63 /* struct ir_node *unknown;*/ /**< unknown node of this ir_graph */
64 struct obstack *obst; /**< obstack where all of the ir_nodes live */
65 struct ir_node *current_block; /**< block for newly gen_*()-erated
68 /* -- Fields indicating different states of irgraph -- */
69 irg_phase_state phase_state; /**< compiler phase */
70 op_pin_state op_pin_state_pinned; /**< Flag for status of nodes */
71 irg_outs_state outs_state; /**< Out edges. */
72 irg_dom_state dom_state; /**< Dominator information */
73 irg_typeinfo_state typeinfo_state; /**< Validity of type information */
74 irg_callee_info_state callee_info_state; /**< Validity of callee information */
75 irg_inline_property inline_property; /**< How to handle inlineing. */
76 irg_loopinfo_state loopinfo_state; /**< state of loop information */
78 /* -- Fields for construction -- */
79 #if USE_EXPLICIT_PHI_IN_STACK
80 struct Phi_in_stack *Phi_in_stack; /**< needed for automatic Phi construction */
82 int n_loc; /**< number of local variable in this
83 procedure including procedure parameters. */
85 /* -- Fields for optimizations / analysis information -- */
86 pset *value_table; /**< hash table for global value numbering (cse)
87 for optimizing use in iropt.c */
88 struct ir_node **outs; /**< Space for the out arrays. */
91 int n_outs; /* < Size wasted for outs */
92 #endif /* defined DEBUG_libfirm */
93 struct ir_loop *loop; /**< The outermost loop */
94 void *link; /**< A void* field to link any information to
97 ir_graph **callers; /**< For callgraph analyses. */
98 int *caller_isbe; /**< For callgraph analyses: set if backedge. */
99 ir_graph **callees; /**< For callgraph analyses. */
100 int *callee_isbe; /**< For callgraph analyses: set if backedge. */
101 int callgraph_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
118 * Initializes the graph construction module
120 void init_irgraph(void);
122 /** Make a rudimentary ir graph for the constant code.
123 Must look like a correct irg, spare everything else. */
124 ir_graph *new_const_code_irg(void);
127 * Set the op_pin_state_pinned state of a graph.
129 * @param irg the IR graph
130 * @param p new pin state
133 set_irg_pinned (ir_graph *irg, op_pin_state p);
135 /** Returns the obstack associated with the graph. */
136 struct obstack *get_irg_obstack(const ir_graph *irg);
139 * Returns true if the node n is allocated on the storage of graph irg.
141 * @param irg the IR graph
142 * @param n the IR node
144 int node_is_in_irgs_storage(ir_graph *irg, ir_node *n);
146 /*-------------------------------------------------------------------*/
147 /* inline functions for graphs */
148 /*-------------------------------------------------------------------*/
150 extern int __interprocedural_view;
153 __get_interprocedural_view(void) {
154 return __interprocedural_view;
158 __is_ir_graph(const void *thing) {
159 return (get_kind(thing) == k_ir_graph);
162 /** Returns the start block of a graph. */
163 static INLINE ir_node *
164 __get_irg_start_block(const ir_graph *irg) {
165 return irg->start_block;
169 __set_irg_start_block(ir_graph *irg, ir_node *node) {
170 irg->start_block = node;
173 static INLINE ir_node *
174 __get_irg_start(const ir_graph *irg) {
179 __set_irg_start(ir_graph *irg, ir_node *node) {
183 static INLINE ir_node *
184 __get_irg_end_block(const ir_graph *irg) {
185 return irg->end_block;
189 __set_irg_end_block(ir_graph *irg, ir_node *node) {
190 irg->end_block = node;
193 static INLINE ir_node *
194 __get_irg_end(const ir_graph *irg) {
199 __set_irg_end(ir_graph *irg, ir_node *node) {
203 static INLINE ir_node *
204 __get_irg_end_reg(const ir_graph *irg) {
208 static INLINE ir_node *
209 __get_irg_end_except (const ir_graph *irg) {
210 return irg->end_except;
213 static INLINE ir_node *
214 __get_irg_cstore(const ir_graph *irg) {
219 __set_irg_cstore(ir_graph *irg, ir_node *node) {
223 static INLINE ir_node *
224 __get_irg_frame(const ir_graph *irg) {
229 __set_irg_frame(ir_graph *irg, ir_node *node) {
233 static INLINE ir_node *
234 __get_irg_globals(const ir_graph *irg) {
239 __set_irg_globals(ir_graph *irg, ir_node *node) {
243 static INLINE ir_node *
244 __get_irg_initial_mem(const ir_graph *irg) {
245 return irg->initial_mem;
249 __set_irg_initial_mem(ir_graph *irg, ir_node *node) {
250 irg->initial_mem = node;
253 static INLINE ir_node *
254 __get_irg_args(const ir_graph *irg) {
259 __set_irg_args(ir_graph *irg, ir_node *node) {
263 static INLINE ir_node *
264 __get_irg_bad(const ir_graph *irg) {
269 __set_irg_bad(ir_graph *irg, ir_node *node) {
273 static INLINE ir_node *
274 __get_irg_current_block(const ir_graph *irg) {
275 return irg->current_block;
279 __set_irg_current_block(ir_graph *irg, ir_node *node) {
280 irg->current_block = node;
283 static INLINE entity *
284 __get_irg_entity(const ir_graph *irg) {
285 assert(irg && irg->ent);
290 __set_irg_entity(ir_graph *irg, entity *ent) {
295 __get_irg_frame_type(const ir_graph *irg) {
296 assert(irg && irg->frame_type);
297 return irg->frame_type;
301 __set_irg_frame_type(ir_graph *irg, type *ftp) {
302 assert(is_class_type(ftp));
303 irg->frame_type = ftp;
306 static INLINE struct obstack *
307 __get_irg_obstack(const ir_graph *irg) {
312 static INLINE irg_phase_state
313 __get_irg_phase_state(const ir_graph *irg) {
314 return irg->phase_state;
318 __set_irg_phase_low(ir_graph *irg) {
319 irg->phase_state = phase_low;
322 static INLINE op_pin_state
323 __get_irg_pinned(const ir_graph *irg) {
324 return irg->op_pin_state_pinned;
327 static INLINE irg_outs_state
328 __get_irg_outs_state(const ir_graph *irg) {
329 return irg->outs_state;
333 __set_irg_outs_inconsistent(ir_graph *irg) {
334 irg->outs_state = outs_inconsistent;
337 static INLINE irg_dom_state
338 __get_irg_dom_state(const ir_graph *irg) {
339 return irg->dom_state;
343 __set_irg_dom_inconsistent(ir_graph *irg) {
344 irg->dom_state = dom_inconsistent;
347 static INLINE irg_loopinfo_state
348 __get_irg_loopinfo_state(const ir_graph *irg) {
349 return irg->loopinfo_state;
353 __set_irg_loopinfo_state(ir_graph *irg, irg_loopinfo_state s) {
354 irg->loopinfo_state = s;
358 __set_irg_pinned(ir_graph *irg, op_pin_state p) {
359 irg->op_pin_state_pinned = p;
362 static INLINE irg_callee_info_state
363 __get_irg_callee_info_state(const ir_graph *irg) {
364 return irg->callee_info_state;
368 __set_irg_callee_info_state(ir_graph *irg, irg_callee_info_state s) {
369 irg_callee_info_state irp_state = get_irp_callee_info_state();
371 irg->callee_info_state = s;
373 /* I could compare ... but who knows? */
374 if ((irp_state == irg_callee_info_consistent) ||
375 ((irp_state == irg_callee_info_inconsistent) && (s == irg_callee_info_none)))
376 set_irp_callee_info_state(s);
379 static INLINE irg_inline_property
380 __get_irg_inline_property(const ir_graph *irg) {
381 return irg->inline_property;
385 __set_irg_inline_property(ir_graph *irg, irg_inline_property s) {
386 irg->inline_property = s;
390 __set_irg_link(ir_graph *irg, void *thing) {
395 __get_irg_link(const ir_graph *irg) {
399 static INLINE unsigned long
400 __get_irg_visited(const ir_graph *irg) {
404 static INLINE unsigned long
405 __get_irg_block_visited(const ir_graph *irg) {
406 return irg->block_visited;
410 __set_irg_block_visited(ir_graph *irg, unsigned long visited) {
411 irg->block_visited = visited;
415 __inc_irg_block_visited(ir_graph *irg) {
416 ++irg->block_visited;
419 #define get_interprocedural_view() __get_interprocedural_view()
420 #define is_ir_graph(thing) __is_ir_graph(thing)
421 #define get_irg_start_block(irg) __get_irg_start_block(irg)
422 #define set_irg_start_block(irg, node) __set_irg_start_block(irg, node)
423 #define get_irg_start(irg) __get_irg_start(irg)
424 #define set_irg_start(irg, node) __set_irg_start(irg, node)
425 #define get_irg_end_block(irg) __get_irg_end_block(irg)
426 #define set_irg_end_block(irg, node) __set_irg_end_block(irg, node)
427 #define get_irg_end(irg) __get_irg_end(irg)
428 #define set_irg_end(irg, node) __set_irg_end(irg, node)
429 #define get_irg_end_reg(irg) __get_irg_end_reg(irg)
430 #define get_irg_end_except(irg) __get_irg_end_except(irg)
431 #define get_irg_cstore(irg) __get_irg_cstore(irg)
432 #define set_irg_cstore(irg, node) __set_irg_cstore(irg, node)
433 #define get_irg_frame(irg) __get_irg_frame(irg)
434 #define set_irg_frame(irg, node) __set_irg_frame(irg, node)
435 #define get_irg_globals(irg) __get_irg_globals(irg)
436 #define set_irg_globals(irg, node) __set_irg_globals(irg, node)
437 #define get_irg_initial_mem(irg) __get_irg_initial_mem(irg)
438 #define set_irg_initial_mem(irg, node) __set_irg_initial_mem(irg, node)
439 #define get_irg_args(irg) __get_irg_args(irg)
440 #define set_irg_args(irg, node) __set_irg_args(irg, node)
441 #define get_irg_bad(irg) __get_irg_bad(irg)
442 #define set_irg_bad(irg, node) __set_irg_bad(irg, node)
443 #define get_irg_current_block(irg) __get_irg_current_block(irg)
444 #define set_irg_current_block(irg, node) __set_irg_current_block(irg, node)
445 #define get_irg_entity(irg) __get_irg_entity(irg)
446 #define set_irg_entity(irg, ent) __set_irg_entity(irg, ent)
447 #define get_irg_frame_type(irg) __get_irg_frame_type(irg)
448 #define set_irg_frame_type(irg, ftp) __set_irg_frame_type(irg, ftp)
449 #define get_irg_obstack(irg) __get_irg_obstack(irg)
450 #define get_irg_phase_state(irg) __get_irg_phase_state(irg)
451 #define set_irg_phase_low(irg) __set_irg_phase_low(irg)
452 #define get_irg_pinned(irg) __get_irg_pinned(irg)
453 #define get_irg_outs_state(irg) __get_irg_outs_state(irg)
454 #define set_irg_outs_inconsistent(irg) __set_irg_outs_inconsistent(irg)
455 #define get_irg_dom_state(irg) __get_irg_dom_state(irg)
456 #define set_irg_dom_inconsistent(irg) __set_irg_dom_inconsistent(irg)
457 #define get_irg_loopinfo_state(irg) __get_irg_loopinfo_state(irg)
458 #define set_irg_loopinfo_state(irg, s) __set_irg_loopinfo_state(irg, s)
459 #define set_irg_pinned(irg, p) __set_irg_pinned(irg, p)
460 #define get_irg_callee_info_state(irg) __get_irg_callee_info_state(irg)
461 #define set_irg_callee_info_state(irg, s) __set_irg_callee_info_state(irg, s)
462 #define get_irg_inline_property(irg) __get_irg_inline_property(irg)
463 #define set_irg_inline_property(irg, s) __set_irg_inline_property(irg, s)
464 #define set_irg_link(irg, thing) __set_irg_link(irg, thing)
465 #define get_irg_link(irg) __get_irg_link(irg)
466 #define get_irg_visited(irg) __get_irg_visited(irg)
467 #define get_irg_block_visited(irg) __get_irg_block_visited(irg)
468 #define set_irg_block_visited(irg, v) __set_irg_block_visited(irg, v)
469 #define inc_irg_block_visited(irg) __inc_irg_block_visited(irg)
471 # endif /* _IRGRAPH_T_H_ */