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