improved dumper, checks more modes now...
[libfirm] / ir / ir / irgraph.h
1 /*
2  * Project:     libFIRM
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
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1998-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13 /**
14  * @file irgraph.h
15  *
16  * ir graph construction.
17  *
18  * @author Martin Trapp, Christian Schaefer
19  */
20
21
22 #include "irop.h"
23
24 # ifndef _IRGRAPH_H_
25 # define _IRGRAPH_H_
26 # include "tv.h"
27
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;
32 #endif
33
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;
38 #endif
39
40 /**
41  *
42  * NAME  Datastructure that holds central information about a procedure
43  *
44  *    ir_graph *new_ir_graph (entity *ent, int params);
45  *    -------------------------------------------------
46  *
47  *    This constructor generates the basic infrastructure needed to
48  *    represent a procedure in FIRM.
49  *
50  *    The parameters of new_ir_graph are:
51  *
52  *      *ent             A pointer to an entity representing the procedure.
53  *
54  *      params           An integer giving the number of local variables in the
55  *                       procedure.
56  *
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
59  *    procedure:
60  *
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.
67  *
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.
76  */
77
78 /** Global variable holding the current IR-graph.
79  * This global variable is used by the ir construction
80  * interface in ircons and by the optimizations.
81  */
82 extern ir_graph *current_ir_graph;
83
84 ir_graph *get_current_ir_graph(void);
85 void set_current_ir_graph(ir_graph *graph);
86
87 /** This flag indicate the current view. The behaviour of some methods
88  * (get_irn_*, set_irn_*) is influenced by this flag. */
89 extern bool interprocedural_view;
90 bool get_interprocedural_view(void);
91 void set_interprocedural_view(bool state);
92
93 /** Create a new ir graph to built ir for a procedure.
94  *
95  *  ent is the entity representing this procedure, i.e., the type of the
96  *  entity must be of a method type.  The constructor automatically sets the
97  *  field irg of the entity as well as current_ir_graph to the new ir graph.
98  *  n_loc is the number of local variables in this procedure including
99  *  the procedure parameters.
100  *  The constructor adds the new irgraph to the list in ir_prog.
101  *  The state of the ir graph is:  phase_building, pinned, no_outs. */
102 ir_graph *new_ir_graph (entity *ent, int n_loc);
103
104 /** Frees the passed irgraph.
105  * Deallocates all nodes in this graph and the ir_graph structure.
106  * Sets the field irgraph in the corresponding entity to NULL.
107  * Does not remove the irgraph from the list in irprog (requires
108  * inefficient search, call remove_irp_irg by hand).
109  * Does not free types, entities or modes that are used only by this
110  * graph, nor the entity standing for this graph.
111  */
112 void free_ir_graph (ir_graph *irg);
113
114 /* --- access routines for all ir_graph attributes --- */
115
116 /**
117  *   Checks whether a pointer points to a ir graph.
118  *
119  *   @param thing     an arbitrary pointer
120  *
121  *   @return
122  *       true if the thing is a ir graph, else false
123  */
124 int      is_ir_graph(void *thing);
125
126 #define get_irg_entity get_irg_ent
127 #define set_irg_entity set_irg_ent
128 entity  *get_irg_ent (ir_graph *irg);
129 void     set_irg_ent (ir_graph *irg, entity *ent);
130
131 type    *get_irg_frame_type (ir_graph *irg);
132 void     set_irg_frame_type (ir_graph *irg, type *ftp);
133 /* To test for a frame type. O(#irgs) if ftp is class type.  */
134 int      is_frame_type (type *ftp);
135
136 ir_node *get_irg_start_block (ir_graph *irg);
137 void     set_irg_start_block (ir_graph *irg, ir_node *node);
138
139 ir_node *get_irg_start (ir_graph *irg);
140 void     set_irg_start (ir_graph *irg, ir_node *node);
141
142 ir_node *get_irg_end_block (ir_graph *irg);
143 void     set_irg_end_block (ir_graph *irg, ir_node *node);
144
145 ir_node *get_irg_end (ir_graph *irg);
146 void     set_irg_end (ir_graph *irg, ir_node *node);
147
148 /* The fields end_reg and end_except contain the end nodes of the
149    interprocedural view.  If the view is not constructed they contain
150    the nomal end node. */
151 ir_node *get_irg_end_reg (ir_graph *irg);
152 void     set_irg_end_reg (ir_graph *irg, ir_node *node);
153
154 ir_node *get_irg_end_except (ir_graph *irg);
155 void     set_irg_end_except (ir_graph *irg, ir_node *node);
156
157
158 /* @@@ oblivious, no more supported. */
159 ir_node *get_irg_cstore (ir_graph *irg);
160 void     set_irg_cstore (ir_graph *irg, ir_node *node);
161 /* end oblivious */
162
163 /** Returns the node that represents the frame pointer. */
164 ir_node *get_irg_frame (ir_graph *irg);
165 /** Sets the node that represents the frame pointer. */
166 void     set_irg_frame (ir_graph *irg, ir_node *node);
167
168 /** Returns the node that represents the global pointer. */
169 ir_node *get_irg_globals (ir_graph *irg);
170 /** Sets the node that represents the global pointer. */
171 void     set_irg_globals (ir_graph *irg, ir_node *node);
172
173 /** Returns the node that represents the initial memory. */
174 ir_node *get_irg_initial_mem (ir_graph *irg);
175 /** Sets the node that represents the initial memory. */
176 void     set_irg_initial_mem (ir_graph *irg, ir_node *node);
177
178 /** Returns the node that represents the argument pointer. */
179 ir_node *get_irg_args (ir_graph *irg);
180 /** Sets the node that represents the argument pointer. */
181 void     set_irg_args (ir_graph *irg, ir_node *node);
182
183 /** Returns the current block of a graph. */
184 ir_node *get_irg_current_block (ir_graph *irg);
185 /** Sets the current block of a graph. */
186 void     set_irg_current_block (ir_graph *irg, ir_node *node);
187
188 /* Use new_Bad() instead!! */
189 ir_node *get_irg_bad (ir_graph *irg);
190 void     set_irg_bad (ir_graph *irg, ir_node *node);
191
192 /* Use new_Unknown() instead!! */
193 /* GL removed: we need unknown with mode for analyses.
194 ir_node *get_irg_unknown (ir_graph *irg);
195 void     set_irg_unknown (ir_graph *irg, ir_node *node);
196 */
197
198 /** Returns teh number of value numbers of a graph. */
199 int      get_irg_n_locs (ir_graph *irg);
200
201 /** Returns the graph number. */
202 long     get_irg_graph_nr(ir_graph *irg);
203
204 /********************************************************************************/
205 /* States of an ir_graph.                                                       */
206 /********************************************************************************/
207
208 /*
209    information associated with the graph.  Optimizations invalidate these
210    states.  */
211
212 /** state: phase values: phase_building, phase_high, phase_low.
213    The irg is in phase_building during construction of the irgraph.  It is in
214    phase_high after construction.  All nodes are allowed.  To get the irgraph
215    into phase_low all Sel nodes must be removed and replaced by explicit
216    address computations.  SymConst size and typetag nodes must be removed (@@@
217    really?).  Initialization of memory allocated by Alloc must be explicit.
218    @@@ More conditions? */
219 typedef enum {
220   phase_building,
221   phase_high,
222   phase_low
223 } irg_phase_state;
224
225 irg_phase_state get_irg_phase_state (ir_graph *irg);
226 void set_irg_phase_low(ir_graph *irg);
227
228 /** state: pinned
229    The graph is "pinned" if all nodes are associated with a basic block.
230    It is in state "floats" if nodes are in arbitrary blocks.  In state
231    "floats" the block predecessor is set in all nodes, but this can be an
232    invalid block, i.e., the block is not a dominator of all the uses of
233    the node.
234    The enum op_pinned is defined in irop.h. */
235 op_pinned get_irg_pinned (ir_graph *irg);
236
237 /** state: outs_state
238    Outs are the back edges or def-use edges.
239    Values:  no_outs, outs_consistent, outs_inconsistent
240    no_outs: outs are not computed, no memory is allocated.
241    outs_consistent:  outs are computed and correct,
242    outs_inconsistent: outs have been computed, memory is still allocated,
243    but the graph has been changed since. */
244 typedef enum {
245   no_outs,
246   outs_consistent,
247   outs_inconsistent
248 } irg_outs_state;
249 irg_outs_state get_irg_outs_state(ir_graph *irg);
250 void set_irg_outs_inconsistent(ir_graph *irg);
251
252 /** state: dom_state
253    Signals the state of the dominator infomation.
254    Values:  no_dom, dom_consistent, dom_inconsistent
255    no_dom: doms are not computed, no memory is allocated.  The access routines
256    may not be used.
257    dom_consistent:  dominator information is computed and correct,
258    dom_inconsistent: dominator information is computed, memory is still allocated,
259    but the graph has been changed since. Using the access routines is possible,
260    obtained information may be incorrect. */
261 typedef enum {
262   no_dom,
263   dom_consistent,
264   dom_inconsistent
265 } irg_dom_state;
266 irg_dom_state get_irg_dom_state(ir_graph *irg);
267 void set_irg_dom_inconsistent(ir_graph *irg);
268
269 /* state: loopinfo_state
270    Loop information describes the loops within the control and
271    data flow of the procedure.  */
272 typedef enum {
273   loopinfo_none,            /**< No loop information is constructed. Default. */
274   loopinfo_consistent,      /**< IntRAprocedural loop information constructed and valid. */
275   loopinfo_inconsistent,    /**< IntRAprocedural loop information constructed and invalid. */
276   loopinfo_ip_consistent,   /**< IntERprocedural loop information constructed and valid. */
277   loopinfo_ip_inconsistent, /**< IntERprocedural loop information constructed and invalid. */
278   loopinfo_cf_consistent,      /**< IntRAprocedural control loop information constructed and valid. */
279   loopinfo_cf_inconsistent,    /**< IntRAprocedural control loop information constructed and invalid. */
280   loopinfo_cf_ip_consistent,   /**< IntERprocedural control loop information constructed and valid. */
281   loopinfo_cf_ip_inconsistent  /**< IntERprocedural control loop information constructed and invalid. */
282 } irg_loopinfo_state;
283 irg_loopinfo_state get_irg_loopinfo_state(ir_graph *irg);
284 void set_irg_loopinfo_state(ir_graph *irg, irg_loopinfo_state s);
285 /* Sets the loopinformation state to the appropriate inconsistent state.
286    If state is 'none' does not change. */
287 void set_irg_loopinfo_inconsistent(ir_graph *irg);
288
289
290 /** state: callee_information_state
291  *  Call nodes contain a list of possible callees.  This list must be
292  *  computed by an anlyses.  */
293 typedef enum {
294   irg_callee_info_none,
295   irg_callee_info_consistent,
296   irg_callee_info_inconsistent
297 } irg_callee_info_state;
298 irg_callee_info_state get_irg_callee_info_state(ir_graph *irg);
299 void set_irg_callee_info_state(ir_graph *irg, irg_callee_info_state s);
300
301 /** property:
302  *  Tells how to handle an ir graph in inlineing.
303  */
304 typedef enum {
305   irg_inline_any,         /**< No restriction on inlineing. Default. */
306   irg_inline_forbidden,   /**< The graph may not be inlined. */
307   irg_inline_recomended,  /**< The graph should be inlined. */
308   irg_inline_forced       /**< The graph must be inlined. */
309 } irg_inline_property;
310 irg_inline_property get_irg_inline_property(ir_graph *irg);
311 void set_irg_inline_property(ir_graph *irg, irg_inline_property s);
312
313 /** A void * field to link arbritary information to the node. */
314 void  set_irg_link (ir_graph *irg, void *thing);
315 void *get_irg_link (ir_graph *irg);
316
317 /* increments visited by one */
318 void          inc_irg_visited (ir_graph *irg);
319 unsigned long get_irg_visited (ir_graph *irg);
320 void          set_irg_visited (ir_graph *irg, unsigned long i);
321 unsigned long get_max_irg_visited (void);
322 void          set_max_irg_visited (int val);
323 unsigned long inc_max_irg_visited (void);
324
325 /* increments block_visited by one */
326 void          inc_irg_block_visited (ir_graph *irg);
327 unsigned long get_irg_block_visited (ir_graph *irg);
328 void          set_irg_block_visited (ir_graph *irg, unsigned long i);
329
330 # endif /* _IRGRAPH_H_ */