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 struct ir_node *no_mem; /**< NoMem node of this ir_graph, the one and
64 /* GL removed: we need unknown with mode for analyses. */
65 /* struct ir_node *unknown;*/ /**< unknown node of this ir_graph */
66 struct obstack *obst; /**< obstack where all of the ir_nodes live */
67 struct ir_node *current_block; /**< block for newly gen_*()-erated
70 /* -- Fields indicating different states of irgraph -- */
71 irg_phase_state phase_state; /**< compiler phase */
72 op_pin_state op_pin_state_pinned; /**< Flag for status of nodes */
73 irg_outs_state outs_state; /**< Out edges. */
74 irg_dom_state dom_state; /**< Dominator information */
75 irg_typeinfo_state typeinfo_state; /**< Validity of type information */
76 irg_callee_info_state callee_info_state; /**< Validity of callee information */
77 irg_inline_property inline_property; /**< How to handle inlineing. */
78 irg_loopinfo_state loopinfo_state; /**< state of loop information */
80 /* -- Fields for construction -- */
81 #if USE_EXPLICIT_PHI_IN_STACK
82 struct Phi_in_stack *Phi_in_stack; /**< needed for automatic Phi construction */
84 int n_loc; /**< number of local variable in this
85 procedure including procedure parameters. */
87 /* -- Fields for optimizations / analysis information -- */
88 pset *value_table; /**< hash table for global value numbering (cse)
89 for optimizing use in iropt.c */
90 struct ir_node **outs; /**< Space for the out arrays. */
93 int n_outs; /* < Size wasted for outs */
94 #endif /* defined DEBUG_libfirm */
95 struct ir_loop *loop; /**< The outermost loop */
96 void *link; /**< A void* field to link any information to
99 ir_graph **callers; /**< For callgraph analyses. */
100 int *caller_isbe; /**< For callgraph analyses: set if backedge. */
101 ir_graph **callees; /**< For callgraph analyses. */
102 int *callee_isbe; /**< For callgraph analyses: set if backedge. */
103 int callgraph_loop_depth;
104 int callgraph_recursion_depth;
107 /* -- Fields for Walking the graph -- */
108 unsigned long visited; /**< this flag is an identifier for
109 ir walk. it will be incremented
110 every time someone walks through
112 unsigned long block_visited; /**< same as visited, for a complete block */
114 int graph_nr; /**< a unique graph number for each graph to make output
120 * Initializes the graph construction module
122 void init_irgraph(void);
124 /** Make a rudimentary ir graph for the constant code.
125 Must look like a correct irg, spare everything else. */
126 ir_graph *new_const_code_irg(void);
129 * Set the op_pin_state_pinned state of a graph.
131 * @param irg the IR graph
132 * @param p new pin state
135 set_irg_pinned (ir_graph *irg, op_pin_state p);
137 /** Returns the obstack associated with the graph. */
138 struct obstack *get_irg_obstack(const ir_graph *irg);
141 * Returns true if the node n is allocated on the storage of graph irg.
143 * @param irg the IR graph
144 * @param n the IR node
146 int node_is_in_irgs_storage(ir_graph *irg, ir_node *n);
148 /*-------------------------------------------------------------------*/
149 /* inline functions for graphs */
150 /*-------------------------------------------------------------------*/
152 extern int __interprocedural_view;
155 __get_interprocedural_view(void) {
156 return __interprocedural_view;
160 __is_ir_graph(const void *thing) {
161 return (get_kind(thing) == k_ir_graph);
164 /** Returns the start block of a graph. */
165 static INLINE ir_node *
166 __get_irg_start_block(const ir_graph *irg) {
167 return irg->start_block;
171 __set_irg_start_block(ir_graph *irg, ir_node *node) {
172 irg->start_block = node;
175 static INLINE ir_node *
176 __get_irg_start(const ir_graph *irg) {
181 __set_irg_start(ir_graph *irg, ir_node *node) {
185 static INLINE ir_node *
186 __get_irg_end_block(const ir_graph *irg) {
187 return irg->end_block;
191 __set_irg_end_block(ir_graph *irg, ir_node *node) {
192 irg->end_block = node;
195 static INLINE ir_node *
196 __get_irg_end(const ir_graph *irg) {
201 __set_irg_end(ir_graph *irg, ir_node *node) {
205 static INLINE ir_node *
206 __get_irg_end_reg(const ir_graph *irg) {
210 static INLINE ir_node *
211 __get_irg_end_except (const ir_graph *irg) {
212 return irg->end_except;
215 static INLINE ir_node *
216 __get_irg_cstore(const ir_graph *irg) {
221 __set_irg_cstore(ir_graph *irg, ir_node *node) {
225 static INLINE ir_node *
226 __get_irg_frame(const ir_graph *irg) {
231 __set_irg_frame(ir_graph *irg, ir_node *node) {
235 static INLINE ir_node *
236 __get_irg_globals(const ir_graph *irg) {
241 __set_irg_globals(ir_graph *irg, ir_node *node) {
245 static INLINE ir_node *
246 __get_irg_initial_mem(const ir_graph *irg) {
247 return irg->initial_mem;
251 __set_irg_initial_mem(ir_graph *irg, ir_node *node) {
252 irg->initial_mem = node;
255 static INLINE ir_node *
256 __get_irg_args(const ir_graph *irg) {
261 __set_irg_args(ir_graph *irg, ir_node *node) {
265 static INLINE ir_node *
266 __get_irg_bad(const ir_graph *irg) {
271 __set_irg_bad(ir_graph *irg, ir_node *node) {
275 static INLINE ir_node *
276 __get_irg_no_mem(const ir_graph *irg) {
281 __set_irg_no_mem(ir_graph *irg, ir_node *node) {
284 static INLINE ir_node *
285 __get_irg_current_block(const ir_graph *irg) {
286 return irg->current_block;
290 __set_irg_current_block(ir_graph *irg, ir_node *node) {
291 irg->current_block = node;
294 static INLINE entity *
295 __get_irg_entity(const ir_graph *irg) {
296 assert(irg && irg->ent);
301 __set_irg_entity(ir_graph *irg, entity *ent) {
306 __get_irg_frame_type(const ir_graph *irg) {
307 assert(irg && irg->frame_type);
308 return irg->frame_type;
312 __set_irg_frame_type(ir_graph *irg, type *ftp) {
313 assert(is_class_type(ftp));
314 irg->frame_type = ftp;
317 static INLINE struct obstack *
318 __get_irg_obstack(const ir_graph *irg) {
323 static INLINE irg_phase_state
324 __get_irg_phase_state(const ir_graph *irg) {
325 return irg->phase_state;
329 __set_irg_phase_low(ir_graph *irg) {
330 irg->phase_state = phase_low;
333 static INLINE op_pin_state
334 __get_irg_pinned(const ir_graph *irg) {
335 return irg->op_pin_state_pinned;
338 static INLINE irg_outs_state
339 __get_irg_outs_state(const ir_graph *irg) {
340 return irg->outs_state;
344 __set_irg_outs_inconsistent(ir_graph *irg) {
345 irg->outs_state = outs_inconsistent;
348 static INLINE irg_dom_state
349 __get_irg_dom_state(const ir_graph *irg) {
350 return irg->dom_state;
354 __set_irg_dom_inconsistent(ir_graph *irg) {
355 irg->dom_state = dom_inconsistent;
358 static INLINE irg_loopinfo_state
359 __get_irg_loopinfo_state(const ir_graph *irg) {
360 return irg->loopinfo_state;
364 __set_irg_loopinfo_state(ir_graph *irg, irg_loopinfo_state s) {
365 irg->loopinfo_state = s;
369 __set_irg_pinned(ir_graph *irg, op_pin_state p) {
370 irg->op_pin_state_pinned = p;
373 static INLINE irg_callee_info_state
374 __get_irg_callee_info_state(const ir_graph *irg) {
375 return irg->callee_info_state;
379 __set_irg_callee_info_state(ir_graph *irg, irg_callee_info_state s) {
380 irg_callee_info_state irp_state = get_irp_callee_info_state();
382 irg->callee_info_state = s;
384 /* I could compare ... but who knows? */
385 if ((irp_state == irg_callee_info_consistent) ||
386 ((irp_state == irg_callee_info_inconsistent) && (s == irg_callee_info_none)))
387 set_irp_callee_info_state(s);
390 static INLINE irg_inline_property
391 __get_irg_inline_property(const ir_graph *irg) {
392 return irg->inline_property;
396 __set_irg_inline_property(ir_graph *irg, irg_inline_property s) {
397 irg->inline_property = s;
401 __set_irg_link(ir_graph *irg, void *thing) {
406 __get_irg_link(const ir_graph *irg) {
410 static INLINE unsigned long
411 __get_irg_visited(const ir_graph *irg) {
415 static INLINE unsigned long
416 __get_irg_block_visited(const ir_graph *irg) {
417 return irg->block_visited;
421 __set_irg_block_visited(ir_graph *irg, unsigned long visited) {
422 irg->block_visited = visited;
426 __inc_irg_block_visited(ir_graph *irg) {
427 ++irg->block_visited;
430 #define get_interprocedural_view() __get_interprocedural_view()
431 #define is_ir_graph(thing) __is_ir_graph(thing)
432 #define get_irg_start_block(irg) __get_irg_start_block(irg)
433 #define set_irg_start_block(irg, node) __set_irg_start_block(irg, node)
434 #define get_irg_start(irg) __get_irg_start(irg)
435 #define set_irg_start(irg, node) __set_irg_start(irg, node)
436 #define get_irg_end_block(irg) __get_irg_end_block(irg)
437 #define set_irg_end_block(irg, node) __set_irg_end_block(irg, node)
438 #define get_irg_end(irg) __get_irg_end(irg)
439 #define set_irg_end(irg, node) __set_irg_end(irg, node)
440 #define get_irg_end_reg(irg) __get_irg_end_reg(irg)
441 #define get_irg_end_except(irg) __get_irg_end_except(irg)
442 #define get_irg_cstore(irg) __get_irg_cstore(irg)
443 #define set_irg_cstore(irg, node) __set_irg_cstore(irg, node)
444 #define get_irg_frame(irg) __get_irg_frame(irg)
445 #define set_irg_frame(irg, node) __set_irg_frame(irg, node)
446 #define get_irg_globals(irg) __get_irg_globals(irg)
447 #define set_irg_globals(irg, node) __set_irg_globals(irg, node)
448 #define get_irg_initial_mem(irg) __get_irg_initial_mem(irg)
449 #define set_irg_initial_mem(irg, node) __set_irg_initial_mem(irg, node)
450 #define get_irg_args(irg) __get_irg_args(irg)
451 #define set_irg_args(irg, node) __set_irg_args(irg, node)
452 #define get_irg_bad(irg) __get_irg_bad(irg)
453 #define set_irg_bad(irg, node) __set_irg_bad(irg, node)
454 #define get_irg_no_mem(irg) __get_irg_no_mem(irg)
455 #define set_irg_no_mem(irg, node) __set_irg_no_mem(irg, node)
456 #define get_irg_current_block(irg) __get_irg_current_block(irg)
457 #define set_irg_current_block(irg, node) __set_irg_current_block(irg, node)
458 #define get_irg_entity(irg) __get_irg_entity(irg)
459 #define set_irg_entity(irg, ent) __set_irg_entity(irg, ent)
460 #define get_irg_frame_type(irg) __get_irg_frame_type(irg)
461 #define set_irg_frame_type(irg, ftp) __set_irg_frame_type(irg, ftp)
462 #define get_irg_obstack(irg) __get_irg_obstack(irg)
463 #define get_irg_phase_state(irg) __get_irg_phase_state(irg)
464 #define set_irg_phase_low(irg) __set_irg_phase_low(irg)
465 #define get_irg_pinned(irg) __get_irg_pinned(irg)
466 #define get_irg_outs_state(irg) __get_irg_outs_state(irg)
467 #define set_irg_outs_inconsistent(irg) __set_irg_outs_inconsistent(irg)
468 #define get_irg_dom_state(irg) __get_irg_dom_state(irg)
469 #define set_irg_dom_inconsistent(irg) __set_irg_dom_inconsistent(irg)
470 #define get_irg_loopinfo_state(irg) __get_irg_loopinfo_state(irg)
471 #define set_irg_loopinfo_state(irg, s) __set_irg_loopinfo_state(irg, s)
472 #define set_irg_pinned(irg, p) __set_irg_pinned(irg, p)
473 #define get_irg_callee_info_state(irg) __get_irg_callee_info_state(irg)
474 #define set_irg_callee_info_state(irg, s) __set_irg_callee_info_state(irg, s)
475 #define get_irg_inline_property(irg) __get_irg_inline_property(irg)
476 #define set_irg_inline_property(irg, s) __set_irg_inline_property(irg, s)
477 #define set_irg_link(irg, thing) __set_irg_link(irg, thing)
478 #define get_irg_link(irg) __get_irg_link(irg)
479 #define get_irg_visited(irg) __get_irg_visited(irg)
480 #define get_irg_block_visited(irg) __get_irg_block_visited(irg)
481 #define set_irg_block_visited(irg, v) __set_irg_block_visited(irg, v)
482 #define inc_irg_block_visited(irg) __inc_irg_block_visited(irg)
484 # endif /* _IRGRAPH_T_H_ */