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 *bad; /**< bad node of this ir_graph, the one and
63 struct ir_node *no_mem; /**< NoMem node of this ir_graph, the one and
65 /* GL removed: we need unknown with mode for analyses. */
66 /* struct ir_node *unknown;*/ /**< unknown node of this ir_graph */
67 struct obstack *obst; /**< obstack where all of the ir_nodes live */
68 struct ir_node *current_block; /**< block for newly gen_*()-erated
71 /* -- Fields indicating different states of irgraph -- */
72 irg_phase_state phase_state; /**< compiler phase */
73 op_pin_state op_pin_state_pinned; /**< Flag for status of nodes */
74 irg_outs_state outs_state; /**< Out edges. */
75 irg_dom_state dom_state; /**< Dominator information */
76 irg_typeinfo_state typeinfo_state; /**< Validity of type information */
77 irg_callee_info_state callee_info_state; /**< Validity of callee information */
78 irg_inline_property inline_property; /**< How to handle inlineing. */
79 irg_loopinfo_state loopinfo_state; /**< state of loop information */
81 /* -- Fields for construction -- */
82 #if USE_EXPLICIT_PHI_IN_STACK
83 struct Phi_in_stack *Phi_in_stack; /**< needed for automatic Phi construction */
85 int n_loc; /**< number of local variable in this
86 procedure including procedure parameters. */
88 /* -- Fields for optimizations / analysis information -- */
89 pset *value_table; /**< hash table for global value numbering (cse)
90 for optimizing use in iropt.c */
91 struct ir_node **outs; /**< Space for the out arrays. */
94 int n_outs; /* < Size wasted for outs */
95 #endif /* defined DEBUG_libfirm */
96 struct ir_loop *loop; /**< The outermost loop */
97 void *link; /**< A void* field to link any information to
100 ir_graph **callers; /**< For callgraph analyses. */
101 int *caller_isbe; /**< For callgraph analyses: set if backedge. */
102 ir_graph **callees; /**< For callgraph analyses. */
103 int *callee_isbe; /**< For callgraph analyses: set if backedge. */
104 int callgraph_loop_depth;
105 int callgraph_recursion_depth;
108 /* -- Fields for Walking the graph -- */
109 unsigned long visited; /**< this flag is an identifier for
110 ir walk. it will be incremented
111 every time someone walks through
113 unsigned long block_visited; /**< same as visited, for a complete block */
115 int graph_nr; /**< a unique graph number for each graph to make output
121 * Initializes the graph construction module
123 void init_irgraph(void);
125 /* Internal constructor that does not add to irp_irgs or the like. */
126 ir_graph *new_r_ir_graph (entity *ent, int n_loc);
128 /** Make a rudimentary ir graph for the constant code.
129 Must look like a correct irg, spare everything else. */
130 ir_graph *new_const_code_irg(void);
133 * Set the op_pin_state_pinned state of a graph.
135 * @param irg the IR graph
136 * @param p new pin state
139 set_irg_pinned (ir_graph *irg, op_pin_state p);
141 /** Returns the obstack associated with the graph. */
142 struct obstack *get_irg_obstack(const ir_graph *irg);
145 * Returns true if the node n is allocated on the storage of graph irg.
147 * @param irg the IR graph
148 * @param n the IR node
150 int node_is_in_irgs_storage(ir_graph *irg, ir_node *n);
152 /*-------------------------------------------------------------------*/
153 /* inline functions for graphs */
154 /*-------------------------------------------------------------------*/
156 extern int __interprocedural_view;
159 __get_interprocedural_view(void) {
160 return __interprocedural_view;
164 __is_ir_graph(const void *thing) {
165 return (get_kind(thing) == k_ir_graph);
168 /** Returns the start block of a graph. */
169 static INLINE ir_node *
170 __get_irg_start_block(const ir_graph *irg) {
171 return irg->start_block;
175 __set_irg_start_block(ir_graph *irg, ir_node *node) {
176 irg->start_block = node;
179 static INLINE ir_node *
180 __get_irg_start(const ir_graph *irg) {
185 __set_irg_start(ir_graph *irg, ir_node *node) {
189 static INLINE ir_node *
190 __get_irg_end_block(const ir_graph *irg) {
191 return irg->end_block;
195 __set_irg_end_block(ir_graph *irg, ir_node *node) {
196 irg->end_block = node;
199 static INLINE ir_node *
200 __get_irg_end(const ir_graph *irg) {
205 __set_irg_end(ir_graph *irg, ir_node *node) {
209 static INLINE ir_node *
210 __get_irg_end_reg(const ir_graph *irg) {
214 static INLINE ir_node *
215 __get_irg_end_except (const ir_graph *irg) {
216 return irg->end_except;
219 static INLINE ir_node *
220 __get_irg_cstore(const ir_graph *irg) {
225 __set_irg_cstore(ir_graph *irg, ir_node *node) {
229 static INLINE ir_node *
230 __get_irg_frame(const ir_graph *irg) {
235 __set_irg_frame(ir_graph *irg, ir_node *node) {
239 static INLINE ir_node *
240 __get_irg_globals(const ir_graph *irg) {
245 __set_irg_globals(ir_graph *irg, ir_node *node) {
249 static INLINE ir_node *
250 __get_irg_initial_mem(const ir_graph *irg) {
251 return irg->initial_mem;
255 __set_irg_initial_mem(ir_graph *irg, ir_node *node) {
256 irg->initial_mem = node;
259 static INLINE ir_node *
260 __get_irg_args(const ir_graph *irg) {
265 __set_irg_args(ir_graph *irg, ir_node *node) {
269 static INLINE ir_node *
270 __get_irg_bad(const ir_graph *irg) {
275 __set_irg_bad(ir_graph *irg, ir_node *node) {
279 static INLINE ir_node *
280 __get_irg_no_mem(const ir_graph *irg) {
285 __set_irg_no_mem(ir_graph *irg, ir_node *node) {
288 static INLINE ir_node *
289 __get_irg_current_block(const ir_graph *irg) {
290 return irg->current_block;
294 __set_irg_current_block(ir_graph *irg, ir_node *node) {
295 irg->current_block = node;
298 static INLINE entity *
299 __get_irg_entity(const ir_graph *irg) {
300 assert(irg && irg->ent);
305 __set_irg_entity(ir_graph *irg, entity *ent) {
310 __get_irg_frame_type(const ir_graph *irg) {
311 assert(irg && irg->frame_type);
312 return irg->frame_type;
316 __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(const ir_graph *irg) {
327 static INLINE irg_phase_state
328 __get_irg_phase_state(const 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(const ir_graph *irg) {
339 return irg->op_pin_state_pinned;
342 static INLINE irg_outs_state
343 __get_irg_outs_state(const 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(const 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(const 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(const 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(const 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(const ir_graph *irg) {
414 static INLINE unsigned long
415 __get_irg_visited(const ir_graph *irg) {
419 static INLINE unsigned long
420 __get_irg_block_visited(const ir_graph *irg) {
421 return irg->block_visited;
425 __set_irg_block_visited(ir_graph *irg, unsigned long visited) {
426 irg->block_visited = visited;
430 __inc_irg_block_visited(ir_graph *irg) {
431 ++irg->block_visited;
434 #define get_interprocedural_view() __get_interprocedural_view()
435 #define is_ir_graph(thing) __is_ir_graph(thing)
436 #define get_irg_start_block(irg) __get_irg_start_block(irg)
437 #define set_irg_start_block(irg, node) __set_irg_start_block(irg, node)
438 #define get_irg_start(irg) __get_irg_start(irg)
439 #define set_irg_start(irg, node) __set_irg_start(irg, node)
440 #define get_irg_end_block(irg) __get_irg_end_block(irg)
441 #define set_irg_end_block(irg, node) __set_irg_end_block(irg, node)
442 #define get_irg_end(irg) __get_irg_end(irg)
443 #define set_irg_end(irg, node) __set_irg_end(irg, node)
444 #define get_irg_end_reg(irg) __get_irg_end_reg(irg)
445 #define get_irg_end_except(irg) __get_irg_end_except(irg)
446 #define get_irg_cstore(irg) __get_irg_cstore(irg)
447 #define set_irg_cstore(irg, node) __set_irg_cstore(irg, node)
448 #define get_irg_frame(irg) __get_irg_frame(irg)
449 #define set_irg_frame(irg, node) __set_irg_frame(irg, node)
450 #define get_irg_globals(irg) __get_irg_globals(irg)
451 #define set_irg_globals(irg, node) __set_irg_globals(irg, node)
452 #define get_irg_initial_mem(irg) __get_irg_initial_mem(irg)
453 #define set_irg_initial_mem(irg, node) __set_irg_initial_mem(irg, node)
454 #define get_irg_args(irg) __get_irg_args(irg)
455 #define set_irg_args(irg, node) __set_irg_args(irg, node)
456 #define get_irg_bad(irg) __get_irg_bad(irg)
457 #define set_irg_bad(irg, node) __set_irg_bad(irg, node)
458 #define get_irg_no_mem(irg) __get_irg_no_mem(irg)
459 #define set_irg_no_mem(irg, node) __set_irg_no_mem(irg, node)
460 #define get_irg_current_block(irg) __get_irg_current_block(irg)
461 #define set_irg_current_block(irg, node) __set_irg_current_block(irg, node)
462 #define get_irg_entity(irg) __get_irg_entity(irg)
463 #define set_irg_entity(irg, ent) __set_irg_entity(irg, ent)
464 #define get_irg_frame_type(irg) __get_irg_frame_type(irg)
465 #define set_irg_frame_type(irg, ftp) __set_irg_frame_type(irg, ftp)
466 #define get_irg_obstack(irg) __get_irg_obstack(irg)
467 #define get_irg_phase_state(irg) __get_irg_phase_state(irg)
468 #define set_irg_phase_low(irg) __set_irg_phase_low(irg)
469 #define get_irg_pinned(irg) __get_irg_pinned(irg)
470 #define get_irg_outs_state(irg) __get_irg_outs_state(irg)
471 #define set_irg_outs_inconsistent(irg) __set_irg_outs_inconsistent(irg)
472 #define get_irg_dom_state(irg) __get_irg_dom_state(irg)
473 #define set_irg_dom_inconsistent(irg) __set_irg_dom_inconsistent(irg)
474 #define get_irg_loopinfo_state(irg) __get_irg_loopinfo_state(irg)
475 #define set_irg_loopinfo_state(irg, s) __set_irg_loopinfo_state(irg, s)
476 #define set_irg_pinned(irg, p) __set_irg_pinned(irg, p)
477 #define get_irg_callee_info_state(irg) __get_irg_callee_info_state(irg)
478 #define set_irg_callee_info_state(irg, s) __set_irg_callee_info_state(irg, s)
479 #define get_irg_inline_property(irg) __get_irg_inline_property(irg)
480 #define set_irg_inline_property(irg, s) __set_irg_inline_property(irg, s)
481 #define set_irg_link(irg, thing) __set_irg_link(irg, thing)
482 #define get_irg_link(irg) __get_irg_link(irg)
483 #define get_irg_visited(irg) __get_irg_visited(irg)
484 #define get_irg_block_visited(irg) __get_irg_block_visited(irg)
485 #define set_irg_block_visited(irg, v) __set_irg_block_visited(irg, v)
486 #define inc_irg_block_visited(irg) __inc_irg_block_visited(irg)
488 # endif /* _IRGRAPH_T_H_ */