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
22 # ifndef _IRGRAPH_T_H_
23 # define _IRGRAPH_T_H_
27 # include "firm_common_t.h"
28 # include "irtypeinfo.h"
30 #define FRAME_TP_SUFFIX "frame_tp"
32 /** ir_graph holds all information for a procedure */
34 firm_kind kind; /**< always set to k_ir_graph*/
35 /* -- Basics of the representation -- */
36 struct entity *ent; /**< The entity of this procedure, i.e.,
37 the type of the procedure and the
38 class it belongs to. */
39 struct type *frame_type; /**< A class type representing the stack frame.
40 Can include "inner" methods. */
41 struct ir_node *start_block; /**< block the start node will belong to */
42 struct ir_node *start; /**< start node of this ir_graph */
43 struct ir_node *end_block; /**< block the end node will belong to */
44 struct ir_node *end; /**< end node of this ir_graph */
45 struct ir_node *end_reg; /**< end node of this ir_graph */
46 struct ir_node *end_except; /**< end node of this ir_graph */
47 struct ir_node *cstore; /**< constant store -- no more needed!! */
48 struct ir_node *frame; /**< method's frame */
49 struct ir_node *globals; /**< pointer to the data segment containing all
50 globals as well as global procedures. */
51 struct ir_node *initial_mem; /**< initial memory of this graph */
52 struct ir_node *args; /**< methods arguments */
53 struct ir_node *bad; /**< bad node of this ir_graph, the one and
55 /* GL removed: we need unknown with mode for analyses. */
56 /* struct ir_node *unknown;*/ /**< unknown node of this ir_graph */
57 struct obstack *obst; /**< obstack where all of the ir_nodes live */
58 struct ir_node *current_block; /**< block for newly gen_*()-erated
61 /* -- Fields indicating different states of irgraph -- */
62 irg_phase_state phase_state; /**< compiler phase */
63 op_pinned pinned; /**< Flag for status of nodes */
64 irg_outs_state outs_state; /**< Out edges. */
65 irg_dom_state dom_state; /**< Dominator information */
66 irg_typeinfo_state typeinfo_state; /**< Validity of type information */
67 irg_callee_info_state callee_info_state; /**< Validity of callee information */
68 irg_inline_property inline_property; /**< How to handle inlineing. */
69 irg_loopinfo_state loopinfo_state; /**< state of loop information */
71 /* -- Fields for construction -- */
72 #if USE_EXPLICIT_PHI_IN_STACK
73 struct Phi_in_stack *Phi_in_stack; /**< needed for automatic Phi construction */
75 int n_loc; /**< number of local variable in this
76 procedure including procedure parameters. */
78 /* -- Fields for optimizations / analysis information -- */
79 pset *value_table; /**< hash table for global value numbering (cse)
80 for optimizing use in iropt.c */
81 struct ir_node **outs; /**< Space for the out arrays. */
84 int n_outs; /* < Size wasted for outs */
85 #endif /* defined DEBUG_libfirm */
86 struct ir_loop *loop; /**< The outermost loop */
87 void *link; /**< A void* field to link any information to
90 /* -- Fields for Walking the graph -- */
91 unsigned long visited; /**< this flag is an identifier for
92 ir walk. it will be incremented
93 every time someone walks through
95 unsigned long block_visited; /**< same as visited, for a complete block */
97 int graph_nr; /**< a unique graph number for each graph to make output
102 void init_irgraph(void);
104 /** Make a rudimentary ir graph for the constant code.
105 Must look like a correct irg, spare everything else. */
106 ir_graph *new_const_code_irg(void);
109 * Set the pinned state of a graph.
115 set_irg_pinned (ir_graph *irg, op_pinned p);
117 /** Returns the obstack associated with the graph. */
118 struct obstack *get_irg_obstack(ir_graph *irg);
121 * Returns true if the node n is allocated on the storage of graph irg.
123 * @param irg the IR graph
124 * @param n the IR node
126 int node_is_in_irgs_storage(ir_graph *irg, ir_node *n);
128 /*-------------------------------------------------------------------*/
129 /* inline functions for graphs */
130 /*-------------------------------------------------------------------*/
133 __is_ir_graph(void *thing) {
134 return (get_kind(thing) == k_ir_graph);
137 /** Returns the start block of a graph. */
138 static INLINE ir_node *
139 __get_irg_start_block(ir_graph *irg)
141 return irg->start_block;
145 __set_irg_start_block(ir_graph *irg, ir_node *node)
147 irg->start_block = node;
150 static INLINE ir_node *
151 __get_irg_start(ir_graph *irg)
157 __set_irg_start(ir_graph *irg, ir_node *node)
162 static INLINE ir_node *
163 __get_irg_end_block(ir_graph *irg)
165 return irg->end_block;
169 __set_irg_end_block(ir_graph *irg, ir_node *node)
171 irg->end_block = node;
174 static INLINE ir_node *
175 __get_irg_end(ir_graph *irg)
181 __set_irg_end(ir_graph *irg, ir_node *node)
186 static INLINE ir_node *
187 __get_irg_end_reg(ir_graph *irg) {
191 static INLINE ir_node *
192 __get_irg_end_except (ir_graph *irg) {
193 return irg->end_except;
196 static INLINE ir_node *
197 __get_irg_cstore(ir_graph *irg)
203 __set_irg_cstore(ir_graph *irg, ir_node *node)
208 static INLINE ir_node *
209 __get_irg_frame(ir_graph *irg)
215 __set_irg_frame(ir_graph *irg, ir_node *node)
220 static INLINE ir_node *
221 __get_irg_globals(ir_graph *irg)
227 __set_irg_globals(ir_graph *irg, ir_node *node)
232 static INLINE ir_node *
233 __get_irg_initial_mem(ir_graph *irg)
235 return irg->initial_mem;
239 __set_irg_initial_mem(ir_graph *irg, ir_node *node)
241 irg->initial_mem = node;
244 static INLINE ir_node *
245 __get_irg_args(ir_graph *irg)
251 __set_irg_args(ir_graph *irg, ir_node *node)
256 static INLINE ir_node *
257 __get_irg_bad(ir_graph *irg)
263 __set_irg_bad(ir_graph *irg, ir_node *node)
268 static INLINE ir_node *
269 __get_irg_current_block(ir_graph *irg)
271 return irg->current_block;
275 __set_irg_current_block(ir_graph *irg, ir_node *node)
277 irg->current_block = node;
280 static INLINE entity *
281 __get_irg_ent(ir_graph *irg)
283 assert(irg && irg->ent);
288 __set_irg_ent(ir_graph *irg, entity *ent)
294 __get_irg_frame_type(ir_graph *irg)
296 assert(irg && irg->frame_type);
297 return irg->frame_type;
301 __set_irg_frame_type(ir_graph *irg, type *ftp)
303 assert(is_class_type(ftp));
304 irg->frame_type = ftp;
307 static INLINE struct obstack *
308 __get_irg_obstack(ir_graph *irg) {
313 static INLINE irg_phase_state
314 __get_irg_phase_state(ir_graph *irg) {
315 return irg->phase_state;
319 __set_irg_phase_low(ir_graph *irg) {
320 irg->phase_state = phase_low;
323 static INLINE op_pinned
324 __get_irg_pinned(ir_graph *irg) {
328 static INLINE irg_outs_state
329 __get_irg_outs_state(ir_graph *irg) {
330 return irg->outs_state;
334 __set_irg_outs_inconsistent(ir_graph *irg) {
335 irg->outs_state = outs_inconsistent;
338 static INLINE irg_dom_state
339 __get_irg_dom_state(ir_graph *irg) {
340 return irg->dom_state;
344 __set_irg_dom_inconsistent(ir_graph *irg) {
345 irg->dom_state = dom_inconsistent;
348 static INLINE irg_loopinfo_state
349 __get_irg_loopinfo_state(ir_graph *irg) {
350 return irg->loopinfo_state;
354 __set_irg_loopinfo_state(ir_graph *irg, irg_loopinfo_state s) {
355 irg->loopinfo_state = s;
359 __set_irg_pinned(ir_graph *irg, op_pinned p) {
363 static INLINE irg_callee_info_state
364 __get_irg_callee_info_state(ir_graph *irg) {
365 return irg->callee_info_state;
369 __set_irg_callee_info_state(ir_graph *irg, irg_callee_info_state s) {
370 irg->callee_info_state = s;
373 static INLINE irg_inline_property
374 __get_irg_inline_property(ir_graph *irg) {
375 return irg->inline_property;
379 __set_irg_inline_property(ir_graph *irg, irg_inline_property s) {
380 irg->inline_property = s;
384 __set_irg_link(ir_graph *irg, void *thing) {
389 __get_irg_link(ir_graph *irg) {
393 static INLINE unsigned long
394 __get_irg_visited(ir_graph *irg)
399 static INLINE unsigned long
400 __get_irg_block_visited(ir_graph *irg)
402 return irg->block_visited;
406 __set_irg_block_visited(ir_graph *irg, unsigned long visited)
408 irg->block_visited = visited;
412 __inc_irg_block_visited(ir_graph *irg)
414 ++irg->block_visited;
417 #define is_ir_graph(thing) __is_ir_graph(thing)
418 #define get_irg_start_block(irg) __get_irg_start_block(irg)
419 #define set_irg_start_block(irg, node) __set_irg_start_block(irg, node)
420 #define get_irg_start(irg) __get_irg_start(irg)
421 #define set_irg_start(irg, node) __set_irg_start(irg, node)
422 #define get_irg_end_block(irg) __get_irg_end_block(irg)
423 #define set_irg_end_block(irg, node) __set_irg_end_block(irg, node)
424 #define get_irg_end(irg) __get_irg_end(irg)
425 #define set_irg_end(irg, node) __set_irg_end(irg, node)
426 #define get_irg_end_reg(irg) __get_irg_end_reg(irg)
427 #define get_irg_end_except(irg) __get_irg_end_except(irg)
428 #define get_irg_cstore(irg) __get_irg_cstore(irg)
429 #define set_irg_cstore(irg, node) __set_irg_cstore(irg, node)
430 #define get_irg_frame(irg) __get_irg_frame(irg)
431 #define set_irg_frame(irg, node) __set_irg_frame(irg, node)
432 #define get_irg_globals(irg) __get_irg_globals(irg)
433 #define set_irg_globals(irg, node) __set_irg_globals(irg, node)
434 #define get_irg_initial_mem(irg) __get_irg_initial_mem(irg)
435 #define set_irg_initial_mem(irg, node) __set_irg_initial_mem(irg, node)
436 #define get_irg_args(irg) __get_irg_args(irg)
437 #define set_irg_args(irg, node) __set_irg_args(irg, node)
438 #define get_irg_bad(irg) __get_irg_bad(irg)
439 #define set_irg_bad(irg, node) __set_irg_bad(irg, node)
440 #define get_irg_current_block(irg) __get_irg_current_block(irg)
441 #define set_irg_current_block(irg, node) __set_irg_current_block(irg, node)
442 #define get_irg_ent(irg) __get_irg_ent(irg)
443 #define set_irg_ent(irg, ent) __set_irg_ent(irg, ent)
444 #define get_irg_frame_type(irg) __get_irg_frame_type(irg)
445 #define set_irg_frame_type(irg, ftp) __set_irg_frame_type(irg, ftp)
446 #define get_irg_obstack(irg) __get_irg_obstack(irg)
447 #define get_irg_phase_state(irg) __get_irg_phase_state(irg)
448 #define set_irg_phase_low(irg) __set_irg_phase_low(irg)
449 #define get_irg_pinned(irg) __get_irg_pinned(irg)
450 #define get_irg_outs_state(irg) __get_irg_outs_state(irg)
451 #define set_irg_outs_inconsistent(irg) __set_irg_outs_inconsistent(irg)
452 #define get_irg_dom_state(irg) __get_irg_dom_state(irg)
453 #define set_irg_dom_inconsistent(irg) __set_irg_dom_inconsistent(irg)
454 #define get_irg_loopinfo_state(irg) __get_irg_loopinfo_state(irg)
455 #define set_irg_loopinfo_state(irg, s) __set_irg_loopinfo_state(irg, s)
456 #define set_irg_pinned(irg, p) __set_irg_pinned(irg, p)
457 #define get_irg_callee_info_state(irg) __get_irg_callee_info_state(irg)
458 #define set_irg_callee_info_state(irg, s) __set_irg_callee_info_state(irg, s)
459 #define get_irg_inline_property(irg) __get_irg_inline_property(irg)
460 #define set_irg_inline_property(irg, s) __set_irg_inline_property(irg, s)
461 #define set_irg_link(irg, thing) __set_irg_link(irg, thing)
462 #define get_irg_link(irg) __get_irg_link(irg)
463 #define get_irg_visited(irg) __get_irg_visited(irg)
464 #define get_irg_block_visited(irg) __get_irg_block_visited(irg)
465 #define set_irg_block_visited(irg, v) __set_irg_block_visited(irg, v)
466 #define inc_irg_block_visited(irg) __inc_irg_block_visited(irg)
468 # endif /* _IRGRAPH_T_H_ */