3 * File name: ir/ir/irgraph.c
4 * Purpose: Entry point to the representation of procedure code.
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
28 /* to resolve recursion between irnode.h and irgraph.h */
29 #ifndef _IR_NODE_TYPEDEF_
30 #define _IR_NODE_TYPEDEF_
31 typedef struct ir_node ir_node;
34 /* to resolve recursion between entity.h and irgraph.h */
35 #ifndef _IR_GRAPH_TYPEDEF_
36 #define _IR_GRAPH_TYPEDEF_
37 typedef struct ir_graph ir_graph;
42 * NAME Datastructure that holds central information about a procedure
44 * ir_graph *new_ir_graph (entity *ent, int params);
45 * -------------------------------------------------
47 * This constructor generates the basic infrastructure needed to
48 * represent a procedure in FIRM.
50 * The parameters of new_ir_graph are:
52 * *ent A pointer to an entity representing the procedure.
54 * params An integer giving the number of local variables in the
57 * It allocates an ir_graph and sets current_ir_graph to point to this
58 * graph. Further it allocates the following nodes needed for every
61 * * The start block containing a start node and Proj nodes for it's
62 * five results (X, M, P, P, T).
63 * * The end block containing an end node. This block is not matured
64 * after executing new_ir_graph as predecessors need to be added to it.
65 * (Maturing a block means fixing it's number of predecessors.)
66 * * The current block, which is empty and also not matured.
68 * Further it enters the global store into the datastructure of the start
69 * block that contanis all valid values in this block (set_store()). This
70 * datastructure is used to build the Phi nodes and removed after
71 * completion of the graph. There is no path from end to start in the
72 * graph after calling ir_graph.
73 * pinned set to "pinned" if no global cse was performed on the graph.
74 * set to "floats" if global cse was performed (and during construction:
75 * did actually change something). Code placement is necessary.
78 /** Global variable holding the current ir graph.
80 * This global variable is used by the ir construction
81 * interface in ircons and by the optimizations.
83 extern ir_graph *current_ir_graph;
85 ir_graph *get_current_ir_graph(void);
86 void set_current_ir_graph(ir_graph *graph);
88 /** This flag indicate the current view. The behaviour of some methods
89 * (get_irn_*, set_irn_*) is influenced by this flag. */
90 extern bool interprocedural_view;
91 bool get_interprocedural_view(void);
92 void set_interprocedural_view(bool state);
94 /** Create a new ir graph to built ir for a procedure.
96 * ent is the entity representing this procedure, i.e., the type of the
97 * entity must be of a method type. The constructor automatically sets the
98 * field irg of the entity as well as current_ir_graph to the new ir graph.
99 * n_loc is the number of local variables in this procedure including
100 * the procedure parameters.
101 * The constructor adds the new irgraph to the list in ir_prog.
102 * The state of the ir graph is: phase_building, pinned, no_outs. */
103 ir_graph *new_ir_graph (entity *ent, int n_loc);
105 /** Frees the passed irgraph.
106 * Deallocates all nodes in this graph and the ir_graph structure.
107 * Sets the field irgraph in the corresponding entity to NULL.
108 * Does not remove the irgraph from the list in irprog (requires
109 * inefficient search, call remove_irp_irg by hand).
110 * Does not free types, entities or modes that are used only by this
111 * graph, nor the entity standing for this graph.
113 void free_ir_graph (ir_graph *irg);
115 /* --- access routines for all ir_graph attributes --- */
118 * Checks whether a pointer points to a ir graph.
120 * @param thing an arbitrary pointer
123 * true if the thing is a ir graph, else false
125 int is_ir_graph(void *thing);
127 #define get_irg_entity get_irg_ent
128 #define set_irg_entity set_irg_ent
129 entity *get_irg_ent (ir_graph *irg);
130 void set_irg_ent (ir_graph *irg, entity *ent);
132 type *get_irg_frame_type (ir_graph *irg);
133 void set_irg_frame_type (ir_graph *irg, type *ftp);
134 /* To test for a frame type. O(#irgs) if ftp is class type. */
135 int is_frame_type (type *ftp);
137 ir_node *get_irg_start_block (ir_graph *irg);
138 void set_irg_start_block (ir_graph *irg, ir_node *node);
140 ir_node *get_irg_start (ir_graph *irg);
141 void set_irg_start (ir_graph *irg, ir_node *node);
143 ir_node *get_irg_end_block (ir_graph *irg);
144 void set_irg_end_block (ir_graph *irg, ir_node *node);
146 ir_node *get_irg_end (ir_graph *irg);
147 void set_irg_end (ir_graph *irg, ir_node *node);
149 /* The fields end_reg and end_except contain the end nodes of the
150 interprocedural view. If the view is not constructed they contain
151 the nomal end node. */
152 ir_node *get_irg_end_reg (ir_graph *irg);
153 void set_irg_end_reg (ir_graph *irg, ir_node *node);
155 ir_node *get_irg_end_except (ir_graph *irg);
156 void set_irg_end_except (ir_graph *irg, ir_node *node);
159 /* @@@ oblivious, no more supported. */
160 ir_node *get_irg_cstore (ir_graph *irg);
161 void set_irg_cstore (ir_graph *irg, ir_node *node);
164 /** Returns the node that represents the frame pointer. */
165 ir_node *get_irg_frame (ir_graph *irg);
166 /** Sets the node that represents the frame pointer. */
167 void set_irg_frame (ir_graph *irg, ir_node *node);
169 /** Returns the node that represents the global pointer. */
170 ir_node *get_irg_globals (ir_graph *irg);
171 /** Sets the node that represents the global pointer. */
172 void set_irg_globals (ir_graph *irg, ir_node *node);
174 /** Returns the node that represents the initial memory. */
175 ir_node *get_irg_initial_mem (ir_graph *irg);
176 /** Sets the node that represents the initial memory. */
177 void set_irg_initial_mem (ir_graph *irg, ir_node *node);
179 /** Returns the node that represents the argument pointer. */
180 ir_node *get_irg_args (ir_graph *irg);
181 /** Sets the node that represents the argument pointer. */
182 void set_irg_args (ir_graph *irg, ir_node *node);
184 /** Returns the current block of a graph. */
185 ir_node *get_irg_current_block (ir_graph *irg);
186 /** Sets the current block of a graph. */
187 void set_irg_current_block (ir_graph *irg, ir_node *node);
189 /* Use new_Bad() instead!! */
190 ir_node *get_irg_bad (ir_graph *irg);
191 void set_irg_bad (ir_graph *irg, ir_node *node);
193 /* Use new_Unknown() instead!! */
194 /* GL removed: we need unknown with mode for analyses.
195 ir_node *get_irg_unknown (ir_graph *irg);
196 void set_irg_unknown (ir_graph *irg, ir_node *node);
199 /** Returns teh number of value numbers of a graph. */
200 int get_irg_n_locs (ir_graph *irg);
202 /** Returns the graph number. */
203 long get_irg_graph_nr(ir_graph *irg);
205 /********************************************************************************/
206 /* States of an ir_graph. */
207 /********************************************************************************/
210 information associated with the graph. Optimizations invalidate these
213 /** state: phase values: phase_building, phase_high, phase_low.
214 The irg is in phase_building during construction of the irgraph. It is in
215 phase_high after construction. All nodes are allowed. To get the irgraph
216 into phase_low all Sel nodes must be removed and replaced by explicit
217 address computations. SymConst size and typetag nodes must be removed (@@@
218 really?). Initialization of memory allocated by Alloc must be explicit.
219 @@@ More conditions? */
226 irg_phase_state get_irg_phase_state (ir_graph *irg);
227 void set_irg_phase_low(ir_graph *irg);
230 The graph is "pinned" if all nodes are associated with a basic block.
231 It is in state "floats" if nodes are in arbitrary blocks. In state
232 "floats" the block predecessor is set in all nodes, but this can be an
233 invalid block, i.e., the block is not a dominator of all the uses of
235 The enum op_pinned is defined in irop.h. */
236 op_pinned get_irg_pinned (ir_graph *irg);
238 /** state: outs_state
239 Outs are the back edges or def-use edges.
240 Values: no_outs, outs_consistent, outs_inconsistent
241 no_outs: outs are not computed, no memory is allocated.
242 outs_consistent: outs are computed and correct,
243 outs_inconsistent: outs have been computed, memory is still allocated,
244 but the graph has been changed since. */
250 irg_outs_state get_irg_outs_state(ir_graph *irg);
251 void set_irg_outs_inconsistent(ir_graph *irg);
254 Signals the state of the dominator infomation.
255 Values: no_dom, dom_consistent, dom_inconsistent
256 no_dom: doms are not computed, no memory is allocated. The access routines
258 dom_consistent: dominator information is computed and correct,
259 dom_inconsistent: dominator information is computed, memory is still allocated,
260 but the graph has been changed since. Using the access routines is possible,
261 obtained information may be incorrect. */
267 irg_dom_state get_irg_dom_state(ir_graph *irg);
268 void set_irg_dom_inconsistent(ir_graph *irg);
270 /* state: loopinfo_state
271 Loop information describes the loops within the control and
272 data flow of the procedure. */
274 loopinfo_none, /**< No loop information is constructed. Default. */
275 loopinfo_consistent, /**< IntRAprocedural loop information constructed and valid. */
276 loopinfo_inconsistent, /**< IntRAprocedural loop information constructed and invalid. */
277 loopinfo_ip_consistent, /**< IntERprocedural loop information constructed and valid. */
278 loopinfo_ip_inconsistent, /**< IntERprocedural loop information constructed and invalid. */
279 loopinfo_cf_consistent, /**< IntRAprocedural control loop information constructed and valid. */
280 loopinfo_cf_inconsistent, /**< IntRAprocedural control loop information constructed and invalid. */
281 loopinfo_cf_ip_consistent, /**< IntERprocedural control loop information constructed and valid. */
282 loopinfo_cf_ip_inconsistent /**< IntERprocedural control loop information constructed and invalid. */
283 } irg_loopinfo_state;
284 irg_loopinfo_state get_irg_loopinfo_state(ir_graph *irg);
285 void set_irg_loopinfo_state(ir_graph *irg, irg_loopinfo_state s);
286 /* Sets the loopinformation state to the appropriate inconsistent state.
287 If state is 'none' does not change. */
288 void set_irg_loopinfo_inconsistent(ir_graph *irg);
291 /** state: callee_information_state
292 * Call nodes contain a list of possible callees. This list must be
293 * computed by an anlyses. */
295 irg_callee_info_none,
296 irg_callee_info_consistent,
297 irg_callee_info_inconsistent
298 } irg_callee_info_state;
299 irg_callee_info_state get_irg_callee_info_state(ir_graph *irg);
300 void set_irg_callee_info_state(ir_graph *irg, irg_callee_info_state s);
303 * Tells how to handle an ir graph in inlineing.
306 irg_inline_any, /**< No restriction on inlineing. Default. */
307 irg_inline_forbidden, /**< The graph may not be inlined. */
308 irg_inline_recomended, /**< The graph should be inlined. */
309 irg_inline_forced /**< The graph must be inlined. */
310 } irg_inline_property;
311 irg_inline_property get_irg_inline_property(ir_graph *irg);
312 void set_irg_inline_property(ir_graph *irg, irg_inline_property s);
314 /** A void * field to link arbritary information to the node. */
315 void set_irg_link (ir_graph *irg, void *thing);
316 void *get_irg_link (ir_graph *irg);
318 /* increments visited by one */
319 void inc_irg_visited (ir_graph *irg);
320 unsigned long get_irg_visited (ir_graph *irg);
321 void set_irg_visited (ir_graph *irg, unsigned long i);
322 unsigned long get_max_irg_visited (void);
323 void set_max_irg_visited (int val);
324 unsigned long inc_max_irg_visited (void);
326 /* increments block_visited by one */
327 void inc_irg_block_visited (ir_graph *irg);
328 unsigned long get_irg_block_visited (ir_graph *irg);
329 void set_irg_block_visited (ir_graph *irg, unsigned long i);
331 # endif /* _IRGRAPH_H_ */