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 /*-------------------------------------------------------------------*/
146 extern int __interprocedural_view;
149 __get_interprocedural_view(void) {
150 return __interprocedural_view;
154 __is_ir_graph(void *thing) {
155 return (get_kind(thing) == k_ir_graph);
158 /** Returns the start block of a graph. */
159 static INLINE ir_node *
160 __get_irg_start_block(ir_graph *irg)
162 return irg->start_block;
166 __set_irg_start_block(ir_graph *irg, ir_node *node)
168 irg->start_block = node;
171 static INLINE ir_node *
172 __get_irg_start(ir_graph *irg)
178 __set_irg_start(ir_graph *irg, ir_node *node)
183 static INLINE ir_node *
184 __get_irg_end_block(ir_graph *irg)
186 return irg->end_block;
190 __set_irg_end_block(ir_graph *irg, ir_node *node)
192 irg->end_block = node;
195 static INLINE ir_node *
196 __get_irg_end(ir_graph *irg)
202 __set_irg_end(ir_graph *irg, ir_node *node)
207 static INLINE ir_node *
208 __get_irg_end_reg(ir_graph *irg) {
212 static INLINE ir_node *
213 __get_irg_end_except (ir_graph *irg) {
214 return irg->end_except;
217 static INLINE ir_node *
218 __get_irg_cstore(ir_graph *irg)
224 __set_irg_cstore(ir_graph *irg, ir_node *node)
229 static INLINE ir_node *
230 __get_irg_frame(ir_graph *irg)
236 __set_irg_frame(ir_graph *irg, ir_node *node)
241 static INLINE ir_node *
242 __get_irg_globals(ir_graph *irg)
248 __set_irg_globals(ir_graph *irg, ir_node *node)
253 static INLINE ir_node *
254 __get_irg_initial_mem(ir_graph *irg)
256 return irg->initial_mem;
260 __set_irg_initial_mem(ir_graph *irg, ir_node *node)
262 irg->initial_mem = node;
265 static INLINE ir_node *
266 __get_irg_args(ir_graph *irg)
272 __set_irg_args(ir_graph *irg, ir_node *node)
277 static INLINE ir_node *
278 __get_irg_bad(ir_graph *irg)
284 __set_irg_bad(ir_graph *irg, ir_node *node)
289 static INLINE ir_node *
290 __get_irg_current_block(ir_graph *irg)
292 return irg->current_block;
296 __set_irg_current_block(ir_graph *irg, ir_node *node)
298 irg->current_block = node;
301 static INLINE entity *
302 __get_irg_ent(ir_graph *irg)
304 assert(irg && irg->ent);
309 __set_irg_ent(ir_graph *irg, entity *ent)
315 __get_irg_frame_type(ir_graph *irg)
317 assert(irg && irg->frame_type);
318 return irg->frame_type;
322 __set_irg_frame_type(ir_graph *irg, type *ftp)
324 assert(is_class_type(ftp));
325 irg->frame_type = ftp;
328 static INLINE struct obstack *
329 __get_irg_obstack(ir_graph *irg) {
334 static INLINE irg_phase_state
335 __get_irg_phase_state(ir_graph *irg) {
336 return irg->phase_state;
340 __set_irg_phase_low(ir_graph *irg) {
341 irg->phase_state = phase_low;
344 static INLINE op_pin_state
345 __get_irg_pinned(ir_graph *irg) {
346 return irg->op_pin_state_pinned;
349 static INLINE irg_outs_state
350 __get_irg_outs_state(ir_graph *irg) {
351 return irg->outs_state;
355 __set_irg_outs_inconsistent(ir_graph *irg) {
356 irg->outs_state = outs_inconsistent;
359 static INLINE irg_dom_state
360 __get_irg_dom_state(ir_graph *irg) {
361 return irg->dom_state;
365 __set_irg_dom_inconsistent(ir_graph *irg) {
366 irg->dom_state = dom_inconsistent;
369 static INLINE irg_loopinfo_state
370 __get_irg_loopinfo_state(ir_graph *irg) {
371 return irg->loopinfo_state;
375 __set_irg_loopinfo_state(ir_graph *irg, irg_loopinfo_state s) {
376 irg->loopinfo_state = s;
380 __set_irg_pinned(ir_graph *irg, op_pin_state p) {
381 irg->op_pin_state_pinned = p;
384 static INLINE irg_callee_info_state
385 __get_irg_callee_info_state(ir_graph *irg) {
386 return irg->callee_info_state;
390 __set_irg_callee_info_state(ir_graph *irg, irg_callee_info_state s) {
391 irg_callee_info_state irp_state = get_irp_callee_info_state();
393 irg->callee_info_state = s;
395 /* I could compare ... but who knows? */
396 if ((irp_state == irg_callee_info_consistent) ||
397 ((irp_state == irg_callee_info_inconsistent) && (s == irg_callee_info_none)))
398 set_irp_callee_info_state(s);
401 static INLINE irg_inline_property
402 __get_irg_inline_property(ir_graph *irg) {
403 return irg->inline_property;
407 __set_irg_inline_property(ir_graph *irg, irg_inline_property s) {
408 irg->inline_property = s;
412 __set_irg_link(ir_graph *irg, void *thing) {
417 __get_irg_link(ir_graph *irg) {
421 static INLINE unsigned long
422 __get_irg_visited(ir_graph *irg)
427 static INLINE unsigned long
428 __get_irg_block_visited(ir_graph *irg)
430 return irg->block_visited;
434 __set_irg_block_visited(ir_graph *irg, unsigned long visited)
436 irg->block_visited = visited;
440 __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_current_block(irg) __get_irg_current_block(irg)
470 #define set_irg_current_block(irg, node) __set_irg_current_block(irg, node)
471 #define get_irg_entity(irg) __get_irg_ent(irg)
472 #define set_irg_entity(irg, ent) __set_irg_ent(irg, ent)
473 #define get_irg_frame_type(irg) __get_irg_frame_type(irg)
474 #define set_irg_frame_type(irg, ftp) __set_irg_frame_type(irg, ftp)
475 #define get_irg_obstack(irg) __get_irg_obstack(irg)
476 #define get_irg_phase_state(irg) __get_irg_phase_state(irg)
477 #define set_irg_phase_low(irg) __set_irg_phase_low(irg)
478 #define get_irg_pinned(irg) __get_irg_pinned(irg)
479 #define get_irg_outs_state(irg) __get_irg_outs_state(irg)
480 #define set_irg_outs_inconsistent(irg) __set_irg_outs_inconsistent(irg)
481 #define get_irg_dom_state(irg) __get_irg_dom_state(irg)
482 #define set_irg_dom_inconsistent(irg) __set_irg_dom_inconsistent(irg)
483 #define get_irg_loopinfo_state(irg) __get_irg_loopinfo_state(irg)
484 #define set_irg_loopinfo_state(irg, s) __set_irg_loopinfo_state(irg, s)
485 #define set_irg_pinned(irg, p) __set_irg_pinned(irg, p)
486 #define get_irg_callee_info_state(irg) __get_irg_callee_info_state(irg)
487 #define set_irg_callee_info_state(irg, s) __set_irg_callee_info_state(irg, s)
488 #define get_irg_inline_property(irg) __get_irg_inline_property(irg)
489 #define set_irg_inline_property(irg, s) __set_irg_inline_property(irg, s)
490 #define set_irg_link(irg, thing) __set_irg_link(irg, thing)
491 #define get_irg_link(irg) __get_irg_link(irg)
492 #define get_irg_visited(irg) __get_irg_visited(irg)
493 #define get_irg_block_visited(irg) __get_irg_block_visited(irg)
494 #define set_irg_block_visited(irg, v) __set_irg_block_visited(irg, v)
495 #define inc_irg_block_visited(irg) __inc_irg_block_visited(irg)
497 # endif /* _IRGRAPH_T_H_ */