Changed file names.
[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
75 /* Create a new ir graph to built ir for a procedure.
76    ent is the entity representing this procedure, i.e., the type of the
77    entity must be of a method type.  The constructor automatically sets the
78    field irg of the entity as well as current_ir_graph to the new ir graph.
79    n_loc is the number of local variables in this procedure including
80    the procedure parameters.
81    The state of the ir graph is:  phase_building, pinned, no_outs. */
82 ir_graph *new_ir_graph (entity *ent, int n_loc);
83
84 /* Frees the passed irgraph.
85    Deallocates all nodes in this graph and the ir_graph structure.
86    Sets the field irgraph in the corresponding entity to NULL.
87    Does not remove the irgraph from the list in irprog (requires
88    inefficient search, call remove_irp_irg by hand).
89    Does not free types, entities or modes that are used only by this
90    graph, nor the entity standing for this graph. */
91 void free_ir_graph (ir_graph *irg);
92
93 /* access routines for all ir_graph attributes */
94 ir_node *get_irg_start_block (ir_graph *irg);
95 void     set_irg_start_block (ir_graph *irg, ir_node *node);
96
97 ir_node *get_irg_start (ir_graph *irg);
98 void     set_irg_start (ir_graph *irg, ir_node *node);
99
100 ir_node *get_irg_end_block (ir_graph *irg);
101 void     set_irg_end_block (ir_graph *irg, ir_node *node);
102
103 ir_node *get_irg_end (ir_graph *irg);
104 void     set_irg_end (ir_graph *irg, ir_node *node);
105
106 ir_node *get_irg_cstore (ir_graph *irg);
107 void     set_irg_cstore (ir_graph *irg, ir_node *node);
108
109 ir_node *get_irg_frame (ir_graph *irg);
110 void     set_irg_frame (ir_graph *irg, ir_node *node);
111
112 ir_node *get_irg_globals (ir_graph *irg);
113 void     set_irg_globals (ir_graph *irg, ir_node *node);
114
115 ir_node *get_irg_args (ir_graph *irg);
116 void     set_irg_args (ir_graph *irg, ir_node *node);
117
118 /* Use new_Bad() instead!! */
119 ir_node *get_irg_bad (ir_graph *irg);
120 void     set_irg_bad (ir_graph *irg, ir_node *node);
121
122 ir_node *get_irg_current_block (ir_graph *irg);
123 void     set_irg_current_block (ir_graph *irg, ir_node *node);
124
125 entity  *get_irg_ent (ir_graph *irg);
126 void     set_irg_ent (ir_graph *irg, entity *ent);
127
128 type    *get_irg_frame_type (ir_graph *irg);
129 void     set_irg_frame_type (ir_graph *irg, type *ftp);
130 /* To test for a frame type */
131 int      is_frame_type(type *ftp);
132
133 /* Use not encouraged, internal of Phi construction algorithm. */
134 int      get_irg_n_loc (ir_graph *irg);
135 void     set_irg_n_loc (ir_graph *irg, int n_loc);
136
137
138 /********************************************************************************/
139 /* States of an ir_graph.                                                       */
140 /********************************************************************************/
141
142 /* An ir_graph can have different states.  These states represent the analysis
143    information associated with the graph.  Optimizations invalidate these
144    states.  */
145
146 /* state: phase values: phase_building, phase_high, phase_low.
147    The irg is in phase_building during construction of the irgraph.  It is in
148    phase_high after construction.  All nodes are allowed.  To get the irgraph
149    into phase_low all Sel nodes must be removed and replaced by explicit
150    address computations.  SymConst size and typetag nodes must be removed (@@@
151    really?).  Initialization of memory allocated by Alloc must be explicit.
152    @@@ More conditions? */
153 typedef enum {
154   phase_building,
155   phase_high,
156   phase_low
157 } irg_phase_state;
158 irg_phase_state get_irg_phase_state (ir_graph *irg);
159 void set_irg_phase_low(ir_graph *irg);
160
161 /* state: pinned
162    The graph is "pinned" if all nodes are accosiated with a basic block.
163    It is in state "floats" if nodes are in arbitrary blocks.  In state
164    "floats" the block predecessor is set in all nodes, but this can be an
165    invalid block, i.e., the block is not a dominator of all the uses of
166    the node.
167    The enum op_pinned is defined in irop.h. */
168 op_pinned get_irg_pinned (ir_graph *irg);
169
170 /* state: outs_state
171    Outs are the back edges or def-use edges.
172    Values:  no_outs, outs_consistent, outs_inconsistent
173    no_outs: outs are not computed, no memory is allocated.
174    outs_consistent:  outs are computed and correct,
175    outs_inconsistent: outs have been computed, memory is still allocated,
176    but the graph has been changed since. */
177 typedef enum {
178   no_outs,
179   outs_consistent,
180   outs_inconsistent
181 } irg_outs_state;
182 irg_outs_state get_irg_outs_state(ir_graph *irg);
183 void set_irg_outs_inconsistent(ir_graph *irg);
184
185 /* state: dom_state
186    Signals the state of the dominator infomation.
187    Values:  no_dom, dom_consistent, dom_inconsistent
188    no_dom: doms are not computed, no memory is allocated.  The access routines
189    may not be used.
190    dom_consistent:  dominator information is computed and correct,
191    dom_inconsistent: dominator information is computed, memory is still allocated,
192    but the graph has been changed since. Using the access routines is possible,
193    obtained information may be incorrect. */
194 typedef enum {
195   no_dom,
196   dom_consistent,
197   dom_inconsistent
198 } irg_dom_state;
199 irg_dom_state get_irg_dom_state(ir_graph *irg);
200 void set_irg_dom_inconsistent(ir_graph *irg);
201
202 /* increments visited by one */
203 void     inc_irg_visited(ir_graph *irg);
204 unsigned long get_irg_visited (ir_graph *irg);
205 void     set_irg_visited(ir_graph *irg, unsigned long i);
206
207 /* increments block_visited by one */
208 void     inc_irg_block_visited(ir_graph *irg);
209 unsigned long get_irg_block_visited (ir_graph *irg);
210 void     set_irg_block_visited(ir_graph *irg, unsigned long i);
211 /*****/
212
213 # endif /* _IRGRAPH_H_ */