1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Authors: Martin Trapp, Christian Schaefer
6 ** irgraph.h: ir graph construction
17 /* to resolve recursion between irnode.h and irgraph.h */
18 #ifndef _IR_NODE_TYPEDEF_
19 #define _IR_NODE_TYPEDEF_
20 typedef struct ir_node ir_node;
23 /* to resolve recursion between entity.h and irgraph.h */
24 #ifndef _IR_GRAPH_TYPEDEF_
25 #define _IR_GRAPH_TYPEDEF_
26 typedef struct ir_graph ir_graph;
29 /***** irgraph/irgraph
31 * NAME Datastructure that holds central information about a procedure
34 ** ir_graph *new_ir_graph (entity *ent, int params);
35 * -------------------------------------------------
37 * This constructor generates the basic infrastructure needed to
38 * represent a procedure in FIRM.
40 * The parameters of new_ir_graph are:
42 * *ent A pointer to an entity representing the procedure.
44 * params An integer giving the number of local variables in the
47 * It allocates an ir_graph and sets current_ir_graph to point to this
48 * graph. Further it allocates the following nodes needed for every
51 * * The start block containing a start node and Proj nodes for it's
52 * five results (X, M, P, P, T).
53 * * The end block containing an end node. This block is not matured
54 * after executing new_ir_graph as predecessors need to be added to it.
55 * (Maturing a block means fixing it's number of predecessors.)
56 * * The current block, which is empty and also not matured.
58 * Further it enters the global store into the datastructure of the start
59 * block that contanis all valid values in this block (set_store()). This
60 * datastructure is used to build the Phi nodes and removed after
61 * completion of the graph. There is no path from end to start in the
62 * graph after calling ir_graph.
64 * pinned set to "pinned" if no global cse was performed on the graph.
65 * set to "floats" if global cse was performed (and during construction:
66 * did actually change something). Code placement is necessary.
70 /* Global variable holding the current_ir_graph. This global variable
71 is used by the ir construction interface in ircons and by the
73 extern ir_graph *current_ir_graph;
75 /* This flag indicate the current view. The behaviour of some methods
76 * (get_irn_*, set_irn_*) is influenced by this flag. */
77 extern bool interprocedural_view;
79 /* Create a new ir graph to built ir for a procedure.
80 ent is the entity representing this procedure, i.e., the type of the
81 entity must be of a method type. The constructor automatically sets the
82 field irg of the entity as well as current_ir_graph to the new ir graph.
83 n_loc is the number of local variables in this procedure including
84 the procedure parameters.
85 The state of the ir graph is: phase_building, pinned, no_outs. */
86 ir_graph *new_ir_graph (entity *ent, int n_loc);
88 /* Frees the passed irgraph.
89 Deallocates all nodes in this graph and the ir_graph structure.
90 Sets the field irgraph in the corresponding entity to NULL.
91 Does not remove the irgraph from the list in irprog (requires
92 inefficient search, call remove_irp_irg by hand).
93 Does not free types, entities or modes that are used only by this
94 graph, nor the entity standing for this graph. */
95 void free_ir_graph (ir_graph *irg);
97 /* access routines for all ir_graph attributes */
98 ir_node *get_irg_start_block (ir_graph *irg);
99 void set_irg_start_block (ir_graph *irg, ir_node *node);
101 ir_node *get_irg_start (ir_graph *irg);
102 void set_irg_start (ir_graph *irg, ir_node *node);
104 ir_node *get_irg_end_block (ir_graph *irg);
105 void set_irg_end_block (ir_graph *irg, ir_node *node);
107 ir_node *get_irg_end (ir_graph *irg);
108 void set_irg_end (ir_graph *irg, ir_node *node);
110 ir_node *get_irg_cstore (ir_graph *irg);
111 void set_irg_cstore (ir_graph *irg, ir_node *node);
113 ir_node *get_irg_frame (ir_graph *irg);
114 void set_irg_frame (ir_graph *irg, ir_node *node);
116 ir_node *get_irg_globals (ir_graph *irg);
117 void set_irg_globals (ir_graph *irg, ir_node *node);
119 ir_node *get_irg_args (ir_graph *irg);
120 void set_irg_args (ir_graph *irg, ir_node *node);
122 /* Use new_Bad() instead!! */
123 ir_node *get_irg_bad (ir_graph *irg);
124 void set_irg_bad (ir_graph *irg, ir_node *node);
126 /* Use new_Unknown() instead!! */
127 ir_node *get_irg_unknown (ir_graph *irg);
128 void set_irg_unknown (ir_graph *irg, ir_node *node);
130 ir_node *get_irg_current_block (ir_graph *irg);
131 void set_irg_current_block (ir_graph *irg, ir_node *node);
133 entity *get_irg_ent (ir_graph *irg);
134 void set_irg_ent (ir_graph *irg, entity *ent);
136 type *get_irg_frame_type (ir_graph *irg);
137 void set_irg_frame_type (ir_graph *irg, type *ftp);
138 /* To test for a frame type */
139 int is_frame_type(type *ftp);
141 /* Use not encouraged, internal of Phi construction algorithm. */
142 int get_irg_n_loc (ir_graph *irg);
143 void set_irg_n_loc (ir_graph *irg, int n_loc);
146 /********************************************************************************/
147 /* States of an ir_graph. */
148 /********************************************************************************/
150 /* An ir_graph can have different states. These states represent the analysis
151 information associated with the graph. Optimizations invalidate these
154 /* state: phase values: phase_building, phase_high, phase_low.
155 The irg is in phase_building during construction of the irgraph. It is in
156 phase_high after construction. All nodes are allowed. To get the irgraph
157 into phase_low all Sel nodes must be removed and replaced by explicit
158 address computations. SymConst size and typetag nodes must be removed (@@@
159 really?). Initialization of memory allocated by Alloc must be explicit.
160 @@@ More conditions? */
166 irg_phase_state get_irg_phase_state (ir_graph *irg);
167 void set_irg_phase_low(ir_graph *irg);
170 The graph is "pinned" if all nodes are accosiated with a basic block.
171 It is in state "floats" if nodes are in arbitrary blocks. In state
172 "floats" the block predecessor is set in all nodes, but this can be an
173 invalid block, i.e., the block is not a dominator of all the uses of
175 The enum op_pinned is defined in irop.h. */
176 op_pinned get_irg_pinned (ir_graph *irg);
179 Outs are the back edges or def-use edges.
180 Values: no_outs, outs_consistent, outs_inconsistent
181 no_outs: outs are not computed, no memory is allocated.
182 outs_consistent: outs are computed and correct,
183 outs_inconsistent: outs have been computed, memory is still allocated,
184 but the graph has been changed since. */
190 irg_outs_state get_irg_outs_state(ir_graph *irg);
191 void set_irg_outs_inconsistent(ir_graph *irg);
194 Signals the state of the dominator infomation.
195 Values: no_dom, dom_consistent, dom_inconsistent
196 no_dom: doms are not computed, no memory is allocated. The access routines
198 dom_consistent: dominator information is computed and correct,
199 dom_inconsistent: dominator information is computed, memory is still allocated,
200 but the graph has been changed since. Using the access routines is possible,
201 obtained information may be incorrect. */
207 irg_dom_state get_irg_dom_state(ir_graph *irg);
208 void set_irg_dom_inconsistent(ir_graph *irg);
210 /* increments visited by one */
211 void inc_irg_visited(ir_graph *irg);
212 unsigned long get_irg_visited (ir_graph *irg);
213 void set_irg_visited(ir_graph *irg, unsigned long i);
214 unsigned long get_max_irg_visited(void);
216 /* increments block_visited by one */
217 void inc_irg_block_visited(ir_graph *irg);
218 unsigned long get_irg_block_visited (ir_graph *irg);
219 void set_irg_block_visited(ir_graph *irg, unsigned long i);
222 # endif /* _IRGRAPH_H_ */