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 ir_graph **callers; /**< For callgraph analyses. */
91 int *caller_isbe; /**< For callgraph analyses: set if backedge. */
92 ir_graph **callees; /**< For callgraph analyses. */
93 int *callee_isbe; /**< For callgraph analyses: set if backedge. */
95 /* -- Fields for Walking the graph -- */
96 unsigned long visited; /**< this flag is an identifier for
97 ir walk. it will be incremented
98 every time someone walks through
100 unsigned long block_visited; /**< same as visited, for a complete block */
102 int graph_nr; /**< a unique graph number for each graph to make output
107 void init_irgraph(void);
109 /** Make a rudimentary ir graph for the constant code.
110 Must look like a correct irg, spare everything else. */
111 ir_graph *new_const_code_irg(void);
114 * Set the pinned state of a graph.
120 set_irg_pinned (ir_graph *irg, op_pinned p);
122 /** Returns the obstack associated with the graph. */
123 struct obstack *get_irg_obstack(ir_graph *irg);
126 * Returns true if the node n is allocated on the storage of graph irg.
128 * @param irg the IR graph
129 * @param n the IR node
131 int node_is_in_irgs_storage(ir_graph *irg, ir_node *n);
133 /*-------------------------------------------------------------------*/
134 /* inline functions for graphs */
135 /*-------------------------------------------------------------------*/
138 __is_ir_graph(void *thing) {
139 return (get_kind(thing) == k_ir_graph);
142 /** Returns the start block of a graph. */
143 static INLINE ir_node *
144 __get_irg_start_block(ir_graph *irg)
146 return irg->start_block;
150 __set_irg_start_block(ir_graph *irg, ir_node *node)
152 irg->start_block = node;
155 static INLINE ir_node *
156 __get_irg_start(ir_graph *irg)
162 __set_irg_start(ir_graph *irg, ir_node *node)
167 static INLINE ir_node *
168 __get_irg_end_block(ir_graph *irg)
170 return irg->end_block;
174 __set_irg_end_block(ir_graph *irg, ir_node *node)
176 irg->end_block = node;
179 static INLINE ir_node *
180 __get_irg_end(ir_graph *irg)
186 __set_irg_end(ir_graph *irg, ir_node *node)
191 static INLINE ir_node *
192 __get_irg_end_reg(ir_graph *irg) {
196 static INLINE ir_node *
197 __get_irg_end_except (ir_graph *irg) {
198 return irg->end_except;
201 static INLINE ir_node *
202 __get_irg_cstore(ir_graph *irg)
208 __set_irg_cstore(ir_graph *irg, ir_node *node)
213 static INLINE ir_node *
214 __get_irg_frame(ir_graph *irg)
220 __set_irg_frame(ir_graph *irg, ir_node *node)
225 static INLINE ir_node *
226 __get_irg_globals(ir_graph *irg)
232 __set_irg_globals(ir_graph *irg, ir_node *node)
237 static INLINE ir_node *
238 __get_irg_initial_mem(ir_graph *irg)
240 return irg->initial_mem;
244 __set_irg_initial_mem(ir_graph *irg, ir_node *node)
246 irg->initial_mem = node;
249 static INLINE ir_node *
250 __get_irg_args(ir_graph *irg)
256 __set_irg_args(ir_graph *irg, ir_node *node)
261 static INLINE ir_node *
262 __get_irg_bad(ir_graph *irg)
268 __set_irg_bad(ir_graph *irg, ir_node *node)
273 static INLINE ir_node *
274 __get_irg_current_block(ir_graph *irg)
276 return irg->current_block;
280 __set_irg_current_block(ir_graph *irg, ir_node *node)
282 irg->current_block = node;
285 static INLINE entity *
286 __get_irg_ent(ir_graph *irg)
288 assert(irg && irg->ent);
293 __set_irg_ent(ir_graph *irg, entity *ent)
299 __get_irg_frame_type(ir_graph *irg)
301 assert(irg && irg->frame_type);
302 return irg->frame_type;
306 __set_irg_frame_type(ir_graph *irg, type *ftp)
308 assert(is_class_type(ftp));
309 irg->frame_type = ftp;
312 static INLINE struct obstack *
313 __get_irg_obstack(ir_graph *irg) {
318 static INLINE irg_phase_state
319 __get_irg_phase_state(ir_graph *irg) {
320 return irg->phase_state;
324 __set_irg_phase_low(ir_graph *irg) {
325 irg->phase_state = phase_low;
328 static INLINE op_pinned
329 __get_irg_pinned(ir_graph *irg) {
333 static INLINE irg_outs_state
334 __get_irg_outs_state(ir_graph *irg) {
335 return irg->outs_state;
339 __set_irg_outs_inconsistent(ir_graph *irg) {
340 irg->outs_state = outs_inconsistent;
343 static INLINE irg_dom_state
344 __get_irg_dom_state(ir_graph *irg) {
345 return irg->dom_state;
349 __set_irg_dom_inconsistent(ir_graph *irg) {
350 irg->dom_state = dom_inconsistent;
353 static INLINE irg_loopinfo_state
354 __get_irg_loopinfo_state(ir_graph *irg) {
355 return irg->loopinfo_state;
359 __set_irg_loopinfo_state(ir_graph *irg, irg_loopinfo_state s) {
360 irg->loopinfo_state = s;
364 __set_irg_pinned(ir_graph *irg, op_pinned p) {
368 static INLINE irg_callee_info_state
369 __get_irg_callee_info_state(ir_graph *irg) {
370 return irg->callee_info_state;
374 __set_irg_callee_info_state(ir_graph *irg, irg_callee_info_state s) {
375 irg->callee_info_state = s;
378 static INLINE irg_inline_property
379 __get_irg_inline_property(ir_graph *irg) {
380 return irg->inline_property;
384 __set_irg_inline_property(ir_graph *irg, irg_inline_property s) {
385 irg->inline_property = s;
389 __set_irg_link(ir_graph *irg, void *thing) {
394 __get_irg_link(ir_graph *irg) {
398 static INLINE unsigned long
399 __get_irg_visited(ir_graph *irg)
404 static INLINE unsigned long
405 __get_irg_block_visited(ir_graph *irg)
407 return irg->block_visited;
411 __set_irg_block_visited(ir_graph *irg, unsigned long visited)
413 irg->block_visited = visited;
417 __inc_irg_block_visited(ir_graph *irg)
419 ++irg->block_visited;
422 #define is_ir_graph(thing) __is_ir_graph(thing)
423 #define get_irg_start_block(irg) __get_irg_start_block(irg)
424 #define set_irg_start_block(irg, node) __set_irg_start_block(irg, node)
425 #define get_irg_start(irg) __get_irg_start(irg)
426 #define set_irg_start(irg, node) __set_irg_start(irg, node)
427 #define get_irg_end_block(irg) __get_irg_end_block(irg)
428 #define set_irg_end_block(irg, node) __set_irg_end_block(irg, node)
429 #define get_irg_end(irg) __get_irg_end(irg)
430 #define set_irg_end(irg, node) __set_irg_end(irg, node)
431 #define get_irg_end_reg(irg) __get_irg_end_reg(irg)
432 #define get_irg_end_except(irg) __get_irg_end_except(irg)
433 #define get_irg_cstore(irg) __get_irg_cstore(irg)
434 #define set_irg_cstore(irg, node) __set_irg_cstore(irg, node)
435 #define get_irg_frame(irg) __get_irg_frame(irg)
436 #define set_irg_frame(irg, node) __set_irg_frame(irg, node)
437 #define get_irg_globals(irg) __get_irg_globals(irg)
438 #define set_irg_globals(irg, node) __set_irg_globals(irg, node)
439 #define get_irg_initial_mem(irg) __get_irg_initial_mem(irg)
440 #define set_irg_initial_mem(irg, node) __set_irg_initial_mem(irg, node)
441 #define get_irg_args(irg) __get_irg_args(irg)
442 #define set_irg_args(irg, node) __set_irg_args(irg, node)
443 #define get_irg_bad(irg) __get_irg_bad(irg)
444 #define set_irg_bad(irg, node) __set_irg_bad(irg, node)
445 #define get_irg_current_block(irg) __get_irg_current_block(irg)
446 #define set_irg_current_block(irg, node) __set_irg_current_block(irg, node)
447 #define get_irg_ent(irg) __get_irg_ent(irg)
448 #define set_irg_ent(irg, ent) __set_irg_ent(irg, ent)
449 #define get_irg_frame_type(irg) __get_irg_frame_type(irg)
450 #define set_irg_frame_type(irg, ftp) __set_irg_frame_type(irg, ftp)
451 #define get_irg_obstack(irg) __get_irg_obstack(irg)
452 #define get_irg_phase_state(irg) __get_irg_phase_state(irg)
453 #define set_irg_phase_low(irg) __set_irg_phase_low(irg)
454 #define get_irg_pinned(irg) __get_irg_pinned(irg)
455 #define get_irg_outs_state(irg) __get_irg_outs_state(irg)
456 #define set_irg_outs_inconsistent(irg) __set_irg_outs_inconsistent(irg)
457 #define get_irg_dom_state(irg) __get_irg_dom_state(irg)
458 #define set_irg_dom_inconsistent(irg) __set_irg_dom_inconsistent(irg)
459 #define get_irg_loopinfo_state(irg) __get_irg_loopinfo_state(irg)
460 #define set_irg_loopinfo_state(irg, s) __set_irg_loopinfo_state(irg, s)
461 #define set_irg_pinned(irg, p) __set_irg_pinned(irg, p)
462 #define get_irg_callee_info_state(irg) __get_irg_callee_info_state(irg)
463 #define set_irg_callee_info_state(irg, s) __set_irg_callee_info_state(irg, s)
464 #define get_irg_inline_property(irg) __get_irg_inline_property(irg)
465 #define set_irg_inline_property(irg, s) __set_irg_inline_property(irg, s)
466 #define set_irg_link(irg, thing) __set_irg_link(irg, thing)
467 #define get_irg_link(irg) __get_irg_link(irg)
468 #define get_irg_visited(irg) __get_irg_visited(irg)
469 #define get_irg_block_visited(irg) __get_irg_block_visited(irg)
470 #define set_irg_block_visited(irg, v) __set_irg_block_visited(irg, v)
471 #define inc_irg_block_visited(irg) __inc_irg_block_visited(irg)
473 # endif /* _IRGRAPH_T_H_ */