Initial revision
[libfirm] / ir / ir / irgraph.c
1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
3 **
4 ** Authors: Martin Trapp, Christian Schaefer
5 **
6 **
7 */
8
9 # include "ircons.h"
10 # include "irgraph.h"
11 # include "iropt.h"
12 # include "array.h"
13 # include "irgmod.h"
14
15 ir_graph *current_ir_graph;
16
17 unsigned long ir_visited = 0;
18 unsigned long block_visited = 0;
19
20
21 /* Allocates a list of nodes:
22     - The start block containing a start node and Proj nodes for it's four
23       results (X, M, P, Tuple).
24     - The end block containing an end node. This block is not matured after
25       new_ir_graph as predecessors need to be added to it.
26     - The current block, which is empty and also not matured.
27    Further it allocates several datastructures needed for graph construction
28    and optimization.
29 */
30 ir_graph *
31 new_ir_graph (entity *ent, int params)
32 {
33   ir_graph *res;
34   ir_node *first_block;
35   ir_node *projX;
36
37   res = (ir_graph *) malloc (sizeof (ir_graph));
38   current_ir_graph = res;
39
40   /** Internal information for graph construction either held in the graph or
41   *** initialized for each graph. **/
42   res->params = params + 1;  /* number of local variables that are never
43                                 dereferenced in this graph plus one for
44                                 the store. This is not the number of parameters
45                                 to the procedure!  */
46 #if USE_EXPICIT_PHI_IN_STACK
47   res->Phi_in_stack = new_Phi_in_stack();  /* A stack needed for automatic Phi
48                                 generation */
49 #endif
50   //???!! turn the Phi_in_stack into a field of ir_graph??
51   res->obst      = (struct obstack *) xmalloc (sizeof (struct obstack));
52   obstack_init (res->obst);
53   res->value_table = new_identities (); /* Symbol table for local variables
54                                            of this procedure */
55
56   /** Type inforamtion for the procedure of the graph **/
57   res->ent = ent;
58
59   /** Nodes needed in every graph **/
60   res->end_block = new_Block ();
61   res->end       = new_End ();
62
63   res->start_block = new_Block ();
64   res->start     = new_Start ();
65   res->bad       = new_ir_node (res, res->start_block, op_Bad, mode_T, 0, NULL);
66
67   /* Proj results of start node */
68   projX        = new_Proj (res->start, mode_X, pns_initial_exec);
69   set_store (new_Proj (res->start, mode_M, pns_global_store));
70   res->frame   = new_Proj (res->start, mode_p, pns_frame_base);
71   res->dataseg = new_Proj (res->start, mode_p, pns_globals);
72   res->args    = new_Proj (res->start, mode_T, pns_args);
73
74   add_in_edge(res->start_block, projX);
75   // The code generation needs it. leave it in now.
76   // Use of this edge is matter of discussion, unresolved. Also possible:
77   // add_in_edge(res->start_block, res->start_block), but invalid typed.
78
79   mature_block (res->current_block);
80
81   /** Make a block to start with **/
82   first_block = new_Block ();
83   add_in_edge (first_block, projX);
84
85   return res;
86 }
87
88 /* access routines for all ir_graph attributes */
89
90 ir_node *
91 get_start_block_of_irgraph (ir_graph *irg)
92 {
93   return irg->start_block;
94 }
95
96 void
97 set_start_block_of_irgraph (ir_graph *irg, ir_node *node)
98 {
99   irg->start_block = node;
100 }
101
102 ir_node *
103 get_start_of_irgraph (ir_graph *irg)
104 {
105   return irg->start;
106 }
107
108 void
109 set_start_of_irgraph(ir_graph *irg, ir_node *node)
110 {
111   irg->start = node;
112 }
113
114 ir_node *
115 get_end_block_of_irgraph (ir_graph *irg)
116 {
117   return irg->end_block;
118 }
119
120 void
121 set_end_block_of_irgraph (ir_graph *irg, ir_node *node)
122 {
123   irg->end_block = node;
124 }
125
126 ir_node *
127 get_end_of_irgraph (ir_graph *irg)
128 {
129   return irg->end;
130 }
131
132 void
133 set_end_of_irgraph (ir_graph *irg, ir_node *node)
134 {
135   irg->end = node;
136 }
137
138 ir_node *
139 get_cstore_of_irgraph (ir_graph *irg)
140 {
141   return irg->cstore;
142 }
143
144 void
145 set_cstore_of_irgraph (ir_graph *irg, ir_node *node)
146 {
147   irg->cstore = node;
148 }
149
150 ir_node *
151 get_frame_of_irgraph (ir_graph *irg)
152 {
153   return irg->frame;
154 }
155
156 void
157 set_frame_of_irgraph(ir_graph *irg, ir_node *node)
158 {
159   irg->frame = node;
160 }
161
162 ir_node *
163 get_args_of_irgraph (ir_graph *irg)
164 {
165   return irg->args;
166 }
167
168 void
169 set_args_of_irgraph(ir_graph *irg, ir_node *node)
170 {
171   irg->args = node;
172 }
173
174 ir_node *
175 get_bad_of_irgraph (ir_graph *irg)
176 {
177   return irg->bad;
178 }
179
180 void
181 set_bad_of_irgraph(ir_graph *irg, ir_node *node)
182 {
183   irg->bad = node;
184 }
185
186 ir_node *
187 get_current_block_of_irgraph (ir_graph *irg)
188 {
189   return irg->current_block;
190 }
191
192 void
193 set_current_block_of_irgraph(ir_graph *irg, ir_node *node)
194 {
195   irg->current_block = node;
196 }
197
198 entity *
199 get_ent_of_irgraph(ir_graph *irg)
200 {
201   return irg->ent;
202 }
203
204 void
205 set_ent_of_irgraph(ir_graph *irg, entity *ent)
206 {
207   irg->ent = ent;
208 }
209
210 int
211 get_params_of_irgraph(ir_graph *irg)
212 {
213   return irg->params;
214 }
215
216 void
217 set_params_of_irgraph(ir_graph *irg, int params)
218 {
219   irg->params = params;
220 }