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