Added two new modes: mode_BAD the mode of tarval_bad and mode_ANY, the mode of tarval...
[libfirm] / ir / ir / irgraph.h
1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 * All rights reserved.
3 */
4
5 /**
6  * @file irgraph.h
7  *
8  * ir graph construction.
9  *
10  * @author Martin Trapp, Christian Schaefer
11  */
12
13 /* $Id$ */
14
15 #include "irop.h"
16
17 # ifndef _IRGRAPH_H_
18 # define _IRGRAPH_H_
19 # include "tv.h"
20
21 /* to resolve recursion between irnode.h and irgraph.h */
22 #ifndef _IR_NODE_TYPEDEF_
23 #define _IR_NODE_TYPEDEF_
24 typedef struct ir_node ir_node;
25 #endif
26
27 /* to resolve recursion between entity.h and irgraph.h */
28 #ifndef _IR_GRAPH_TYPEDEF_
29 #define _IR_GRAPH_TYPEDEF_
30 typedef struct ir_graph ir_graph;
31 #endif
32
33 /**
34  *
35  * NAME  Datastructure that holds central information about a procedure
36  *
37  *    ir_graph *new_ir_graph (entity *ent, int params);
38  *    -------------------------------------------------
39  *
40  *    This constructor generates the basic infrastructure needed to
41  *    represent a procedure in FIRM.
42  *
43  *    The parameters of new_ir_graph are:
44  *
45  *      *ent             A pointer to an entity representing the procedure.
46  *
47  *      params           An integer giving the number of local variables in the
48  *                       procedure.
49  *
50  *    It allocates an ir_graph and sets current_ir_graph to point to this
51  *    graph.  Further it allocates the following nodes needed for every
52  *    procedure:
53  *
54  *    * The start block containing a start node and Proj nodes for it's
55  *      five results (X, M, P, P, T).
56  *    * The end block containing an end node. This block is not matured
57  *      after executing new_ir_graph as predecessors need to be added to it.
58  *      (Maturing a block means fixing it's number of predecessors.)
59  *    * The current block, which is empty and also not matured.
60  *
61  *    Further it enters the global store into the datastructure of the start
62  *    block that contanis all valid values in this block (set_store()).  This
63  *    datastructure is used to build the Phi nodes and removed after
64  *    completion of the graph.  There is no path from end to start in the
65  *    graph after calling ir_graph.
66  *   pinned    set to "pinned" if no global cse was performed on the graph.
67  *             set to "floats" if global cse was performed (and during construction:
68  *             did actually change something).  Code placement is necessary.
69  */
70
71 /* Global variable holding the current_ir_graph.  This global variable
72    is used by the ir construction interface in ircons and by the
73    optimizations. */
74 extern ir_graph *current_ir_graph;
75 ir_graph *get_current_ir_graph(void);
76 void set_current_ir_graph(ir_graph *graph);
77
78 /** This flag indicate the current view. The behaviour of some methods
79  * (get_irn_*, set_irn_*) is influenced by this flag. */
80 extern bool interprocedural_view;
81 bool get_interprocedural_view(void);
82 void set_interprocedural_view(bool state);
83
84 /** Create a new ir graph to built ir for a procedure.
85    ent is the entity representing this procedure, i.e., the type of the
86    entity must be of a method type.  The constructor automatically sets the
87    field irg of the entity as well as current_ir_graph to the new ir graph.
88    n_loc is the number of local variables in this procedure including
89    the procedure parameters.
90    The state of the ir graph is:  phase_building, pinned, no_outs. */
91 ir_graph *new_ir_graph (entity *ent, int n_loc);
92
93 /** Frees the passed irgraph.
94    Deallocates all nodes in this graph and the ir_graph structure.
95    Sets the field irgraph in the corresponding entity to NULL.
96    Does not remove the irgraph from the list in irprog (requires
97    inefficient search, call remove_irp_irg by hand).
98    Does not free types, entities or modes that are used only by this
99    graph, nor the entity standing for this graph. */
100 void free_ir_graph (ir_graph *irg);
101
102 /* --- access routines for all ir_graph attributes --- */
103 entity  *get_irg_ent (ir_graph *irg);
104 void     set_irg_ent (ir_graph *irg, entity *ent);
105
106 type    *get_irg_frame_type (ir_graph *irg);
107 void     set_irg_frame_type (ir_graph *irg, type *ftp);
108 /* To test for a frame type */
109 int      is_frame_type(type *ftp);
110
111 ir_node *get_irg_start_block (ir_graph *irg);
112 void     set_irg_start_block (ir_graph *irg, ir_node *node);
113
114 ir_node *get_irg_start (ir_graph *irg);
115 void     set_irg_start (ir_graph *irg, ir_node *node);
116
117 ir_node *get_irg_end_block (ir_graph *irg);
118 void     set_irg_end_block (ir_graph *irg, ir_node *node);
119
120 ir_node *get_irg_end (ir_graph *irg);
121 void     set_irg_end (ir_graph *irg, ir_node *node);
122
123 /* @@@ oblivious, no more supported. */
124 ir_node *get_irg_cstore (ir_graph *irg);
125 void     set_irg_cstore (ir_graph *irg, ir_node *node);
126 /* end oblivious */
127
128 ir_node *get_irg_frame (ir_graph *irg);
129 void     set_irg_frame (ir_graph *irg, ir_node *node);
130
131 ir_node *get_irg_globals (ir_graph *irg);
132 void     set_irg_globals (ir_graph *irg, ir_node *node);
133
134 ir_node *get_irg_args (ir_graph *irg);
135 void     set_irg_args (ir_graph *irg, ir_node *node);
136
137 ir_node *get_irg_current_block (ir_graph *irg);
138 void     set_irg_current_block (ir_graph *irg, ir_node *node);
139
140 /* Use new_Bad() instead!! */
141 ir_node *get_irg_bad (ir_graph *irg);
142 void     set_irg_bad (ir_graph *irg, ir_node *node);
143
144 /* Use new_Unknown() instead!! */
145 ir_node *get_irg_unknown (ir_graph *irg);
146 void     set_irg_unknown (ir_graph *irg, ir_node *node);
147
148 int      get_irg_n_locs (ir_graph *irg);
149
150 INLINE long get_irg_graph_nr(ir_graph *irg);
151
152 /********************************************************************************/
153 /* States of an ir_graph.                                                       */
154 /********************************************************************************/
155
156 /*
157    information associated with the graph.  Optimizations invalidate these
158    states.  */
159
160 /** state: phase values: phase_building, phase_high, phase_low.
161    The irg is in phase_building during construction of the irgraph.  It is in
162    phase_high after construction.  All nodes are allowed.  To get the irgraph
163    into phase_low all Sel nodes must be removed and replaced by explicit
164    address computations.  SymConst size and typetag nodes must be removed (@@@
165    really?).  Initialization of memory allocated by Alloc must be explicit.
166    @@@ More conditions? */
167 typedef enum {
168   phase_building,
169   phase_high,
170   phase_low
171 } irg_phase_state;
172
173 irg_phase_state get_irg_phase_state (ir_graph *irg);
174 void set_irg_phase_low(ir_graph *irg);
175
176 /* state: pinned
177    The graph is "pinned" if all nodes are associated with a basic block.
178    It is in state "floats" if nodes are in arbitrary blocks.  In state
179    "floats" the block predecessor is set in all nodes, but this can be an
180    invalid block, i.e., the block is not a dominator of all the uses of
181    the node.
182    The enum op_pinned is defined in irop.h. */
183 op_pinned get_irg_pinned (ir_graph *irg);
184
185 /** state: outs_state
186    Outs are the back edges or def-use edges.
187    Values:  no_outs, outs_consistent, outs_inconsistent
188    no_outs: outs are not computed, no memory is allocated.
189    outs_consistent:  outs are computed and correct,
190    outs_inconsistent: outs have been computed, memory is still allocated,
191    but the graph has been changed since. */
192 typedef enum {
193   no_outs,
194   outs_consistent,
195   outs_inconsistent
196 } irg_outs_state;
197 irg_outs_state get_irg_outs_state(ir_graph *irg);
198 void set_irg_outs_inconsistent(ir_graph *irg);
199
200 /** state: dom_state
201    Signals the state of the dominator infomation.
202    Values:  no_dom, dom_consistent, dom_inconsistent
203    no_dom: doms are not computed, no memory is allocated.  The access routines
204    may not be used.
205    dom_consistent:  dominator information is computed and correct,
206    dom_inconsistent: dominator information is computed, memory is still allocated,
207    but the graph has been changed since. Using the access routines is possible,
208    obtained information may be incorrect. */
209 typedef enum {
210   no_dom,
211   dom_consistent,
212   dom_inconsistent
213 } irg_dom_state;
214 irg_dom_state get_irg_dom_state(ir_graph *irg);
215 void set_irg_dom_inconsistent(ir_graph *irg);
216
217 /* state: loopinfo_state
218    Loop information describes the loops within the control and
219    data flow of the procedure.
220 tpedef enum {   @@@ make unrecognizable for jni script!!!
221   no_loopinfo,
222   loopinfo_consistent,
223   loopinfo_inconsistent
224 } irg_loopinfo_state;
225 irg_loopinfo_state get_irg_loopinfo_state(ir_graph *irg);
226 void set_irg_loopinfo_inconsistent(ir_graph *irg);
227 */
228
229 /* A void * field to link arbritary information to the node. */
230 void set_irg_link (ir_graph *irg, void *thing);
231 void *get_irg_link (ir_graph *irg);
232
233 /* increments visited by one */
234 void     inc_irg_visited(ir_graph *irg);
235 unsigned long get_irg_visited (ir_graph *irg);
236 void     set_irg_visited(ir_graph *irg, unsigned long i);
237 unsigned long get_max_irg_visited(void);
238 void set_max_irg_visited(int val);
239 unsigned long inc_max_irg_visited(void);
240
241 /* increments block_visited by one */
242 void     inc_irg_block_visited(ir_graph *irg);
243 unsigned long get_irg_block_visited (ir_graph *irg);
244 void     set_irg_block_visited(ir_graph *irg, unsigned long i);
245
246 # endif /* _IRGRAPH_H_ */