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