imporoved loop dumper slightly
[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.  This global variable
79    is used by the ir construction interface in ircons and by the
80    optimizations. */
81 extern ir_graph *current_ir_graph;
82 ir_graph *get_current_ir_graph(void);
83 void set_current_ir_graph(ir_graph *graph);
84
85 /** This flag indicate the current view. The behaviour of some methods
86  * (get_irn_*, set_irn_*) is influenced by this flag. */
87 extern bool interprocedural_view;
88 bool get_interprocedural_view(void);
89 void set_interprocedural_view(bool state);
90
91 /** Create a new ir graph to built ir for a procedure.
92  *
93  *  ent is the entity representing this procedure, i.e., the type of the
94  *  entity must be of a method type.  The constructor automatically sets the
95  *  field irg of the entity as well as current_ir_graph to the new ir graph.
96  *  n_loc is the number of local variables in this procedure including
97  *  the procedure parameters.
98  *  The constructor adds the new irgraph to the list in ir_prog.
99  *  The state of the ir graph is:  phase_building, pinned, no_outs. */
100 ir_graph *new_ir_graph (entity *ent, int n_loc);
101
102 /** Frees the passed irgraph.
103    Deallocates all nodes in this graph and the ir_graph structure.
104    Sets the field irgraph in the corresponding entity to NULL.
105    Does not remove the irgraph from the list in irprog (requires
106    inefficient search, call remove_irp_irg by hand).
107    Does not free types, entities or modes that are used only by this
108    graph, nor the entity standing for this graph. */
109 void free_ir_graph (ir_graph *irg);
110
111 /* --- access routines for all ir_graph attributes --- */
112
113 /**
114  *   Checks whether a pointer points to a ir graph.
115  *
116  *   @param thing     an arbitrary pointer
117  *
118  *   @return
119  *       true if the thing is a ir graph, else false
120  */
121 int
122 is_ir_graph(void *thing);
123
124 #define get_irg_entity get_irg_ent
125 #define set_irg_entity set_irg_ent
126 entity  *get_irg_ent (ir_graph *irg);
127 void     set_irg_ent (ir_graph *irg, entity *ent);
128
129 type    *get_irg_frame_type (ir_graph *irg);
130 void     set_irg_frame_type (ir_graph *irg, type *ftp);
131 /* To test for a frame type. O(#irgs) if ftp is class type.  */
132 int      is_frame_type (type *ftp);
133
134 ir_node *get_irg_start_block (ir_graph *irg);
135 void     set_irg_start_block (ir_graph *irg, ir_node *node);
136
137 ir_node *get_irg_start (ir_graph *irg);
138 void     set_irg_start (ir_graph *irg, ir_node *node);
139
140 ir_node *get_irg_end_block (ir_graph *irg);
141 void     set_irg_end_block (ir_graph *irg, ir_node *node);
142
143 ir_node *get_irg_end (ir_graph *irg);
144 void     set_irg_end (ir_graph *irg, ir_node *node);
145
146 /* @@@ oblivious, no more supported. */
147 ir_node *get_irg_cstore (ir_graph *irg);
148 void     set_irg_cstore (ir_graph *irg, ir_node *node);
149 /* end oblivious */
150
151 /* node that represents frame pointer */
152 ir_node *get_irg_frame (ir_graph *irg);
153 void     set_irg_frame (ir_graph *irg, ir_node *node);
154
155 /* node that represents global pointer */
156 ir_node *get_irg_globals (ir_graph *irg);
157 void     set_irg_globals (ir_graph *irg, ir_node *node);
158
159 ir_node *get_irg_args (ir_graph *irg);
160 void     set_irg_args (ir_graph *irg, ir_node *node);
161
162 ir_node *get_irg_current_block (ir_graph *irg);
163 void     set_irg_current_block (ir_graph *irg, ir_node *node);
164
165 /* Use new_Bad() instead!! */
166 ir_node *get_irg_bad (ir_graph *irg);
167 void     set_irg_bad (ir_graph *irg, ir_node *node);
168
169 /* Use new_Unknown() instead!! */
170 ir_node *get_irg_unknown (ir_graph *irg);
171 void     set_irg_unknown (ir_graph *irg, ir_node *node);
172
173 int      get_irg_n_locs (ir_graph *irg);
174
175 INLINE long get_irg_graph_nr(ir_graph *irg);
176
177 /********************************************************************************/
178 /* States of an ir_graph.                                                       */
179 /********************************************************************************/
180
181 /*
182    information associated with the graph.  Optimizations invalidate these
183    states.  */
184
185 /** state: phase values: phase_building, phase_high, phase_low.
186    The irg is in phase_building during construction of the irgraph.  It is in
187    phase_high after construction.  All nodes are allowed.  To get the irgraph
188    into phase_low all Sel nodes must be removed and replaced by explicit
189    address computations.  SymConst size and typetag nodes must be removed (@@@
190    really?).  Initialization of memory allocated by Alloc must be explicit.
191    @@@ More conditions? */
192 typedef enum {
193   phase_building,
194   phase_high,
195   phase_low
196 } irg_phase_state;
197
198 irg_phase_state get_irg_phase_state (ir_graph *irg);
199 void set_irg_phase_low(ir_graph *irg);
200
201 /* state: pinned
202    The graph is "pinned" if all nodes are associated with a basic block.
203    It is in state "floats" if nodes are in arbitrary blocks.  In state
204    "floats" the block predecessor is set in all nodes, but this can be an
205    invalid block, i.e., the block is not a dominator of all the uses of
206    the node.
207    The enum op_pinned is defined in irop.h. */
208 op_pinned get_irg_pinned (ir_graph *irg);
209
210 /** state: outs_state
211    Outs are the back edges or def-use edges.
212    Values:  no_outs, outs_consistent, outs_inconsistent
213    no_outs: outs are not computed, no memory is allocated.
214    outs_consistent:  outs are computed and correct,
215    outs_inconsistent: outs have been computed, memory is still allocated,
216    but the graph has been changed since. */
217 typedef enum {
218   no_outs,
219   outs_consistent,
220   outs_inconsistent
221 } irg_outs_state;
222 irg_outs_state get_irg_outs_state(ir_graph *irg);
223 void set_irg_outs_inconsistent(ir_graph *irg);
224
225 /** state: dom_state
226    Signals the state of the dominator infomation.
227    Values:  no_dom, dom_consistent, dom_inconsistent
228    no_dom: doms are not computed, no memory is allocated.  The access routines
229    may not be used.
230    dom_consistent:  dominator information is computed and correct,
231    dom_inconsistent: dominator information is computed, memory is still allocated,
232    but the graph has been changed since. Using the access routines is possible,
233    obtained information may be incorrect. */
234 typedef enum {
235   no_dom,
236   dom_consistent,
237   dom_inconsistent
238 } irg_dom_state;
239 irg_dom_state get_irg_dom_state(ir_graph *irg);
240 void set_irg_dom_inconsistent(ir_graph *irg);
241
242 /* state: loopinfo_state
243    Loop information describes the loops within the control and
244    data flow of the procedure.  */
245 /* @@@ make unrecognizable for jni script!!! -- Why??? */
246 typedef enum {
247   no_loopinfo,
248   loopinfo_consistent,
249   loopinfo_inconsistent
250 } irg_loopinfo_state;
251 irg_loopinfo_state get_irg_loopinfo_state(ir_graph *irg);
252 void set_irg_loopinfo_inconsistent(ir_graph *irg);
253
254
255 /* A void * field to link arbritary information to the node. */
256 void  set_irg_link (ir_graph *irg, void *thing);
257 void *get_irg_link (ir_graph *irg);
258
259 /* increments visited by one */
260 void          inc_irg_visited (ir_graph *irg);
261 unsigned long get_irg_visited (ir_graph *irg);
262 void          set_irg_visited (ir_graph *irg, unsigned long i);
263 unsigned long get_max_irg_visited (void);
264 void          set_max_irg_visited (int val);
265 unsigned long inc_max_irg_visited (void);
266
267 /* increments block_visited by one */
268 void          inc_irg_block_visited (ir_graph *irg);
269 unsigned long get_irg_block_visited (ir_graph *irg);
270 void          set_irg_block_visited (ir_graph *irg, unsigned long i);
271
272 # endif /* _IRGRAPH_H_ */