1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Authors: Martin Trapp, Christian Schaefer
16 ir_graph *current_ir_graph;
18 /* Allocates a list of nodes:
19 - The start block containing a start node and Proj nodes for it's four
20 results (X, M, P, Tuple).
21 - The end block containing an end node. This block is not matured after
22 new_ir_graph as predecessors need to be added to it.
23 - The current block, which is empty and also not matured.
24 Further it allocates several datastructures needed for graph construction
28 new_ir_graph (entity *ent, int params)
34 res = (ir_graph *) malloc (sizeof (ir_graph));
35 current_ir_graph = res;
36 add_irp_irg(res); /* remember this graph global. */
38 /** Internal information for graph construction either held in the graph or
39 *** initialized for each graph. **/
40 res->params = params + 1; /* number of local variables that are never
41 dereferenced in this graph plus one for
42 the store. This is not the number of parameters
44 res->visited = 0; /* visited flag, for the ir walker */
45 res->block_visited=0; /* visited flag, for the 'block'-walker */
47 #if USE_EXPICIT_PHI_IN_STACK
48 res->Phi_in_stack = new_Phi_in_stack(); /* A stack needed for automatic Phi
51 res->obst = (struct obstack *) xmalloc (sizeof (struct obstack));
52 obstack_init (res->obst);
53 res->value_table = new_identities (); /* value table for global value numbering
54 for optimizing use in iropt.c */
56 /** Type inforamtion for the procedure of the graph **/
60 /** Nodes needed in every graph **/
61 res->end_block = new_Block ();
62 res->end = new_End ();
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);
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);
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.
80 mature_block (res->current_block);
82 /** Make a block to start with **/
83 first_block = new_Block ();
84 add_in_edge (first_block, projX);
89 /* access routines for all ir_graph attributes:
91 {attr type} get_irg_{attribute name} (ir_graph *irg);
92 void set_irg_{attr name} (ir_graph *irg, {attr type} {attr}); */
95 get_irg_start_block (ir_graph *irg)
97 return irg->start_block;
101 set_irg_start_block (ir_graph *irg, ir_node *node)
103 irg->start_block = node;
107 get_irg_start (ir_graph *irg)
113 set_irg_start(ir_graph *irg, ir_node *node)
119 get_irg_end_block (ir_graph *irg)
121 return irg->end_block;
125 set_irg_end_block (ir_graph *irg, ir_node *node)
127 irg->end_block = node;
131 get_irg_end (ir_graph *irg)
137 set_irg_end (ir_graph *irg, ir_node *node)
143 get_irg_cstore (ir_graph *irg)
149 set_irg_cstore (ir_graph *irg, ir_node *node)
155 get_irg_frame (ir_graph *irg)
161 set_irg_frame (ir_graph *irg, ir_node *node)
167 get_irg_globals (ir_graph *irg)
173 set_irg_globals (ir_graph *irg, ir_node *node)
179 get_irg_args (ir_graph *irg)
185 set_irg_args (ir_graph *irg, ir_node *node)
191 get_irg_bad (ir_graph *irg)
197 set_irg_bad (ir_graph *irg, ir_node *node)
203 get_irg_current_block (ir_graph *irg)
205 return irg->current_block;
209 set_irg_current_block (ir_graph *irg, ir_node *node)
211 irg->current_block = node;
215 get_irg_ent (ir_graph *irg)
221 set_irg_ent (ir_graph *irg, entity *ent)
227 get_irg_params (ir_graph *irg)
233 set_irg_params (ir_graph *irg, int params)
235 irg->params = params;
239 get_irg_visited (ir_graph *irg)
245 set_irg_visited (ir_graph *irg, unsigned long visited)
247 irg->visited = visited;
251 inc_irg_visited (ir_graph *irg)
253 irg->visited = irg->visited++;
257 get_irg_block_visited (ir_graph *irg)
259 return irg->block_visited;
263 set_irg_block_visited (ir_graph *irg, unsigned long visited)
265 irg->block_visited = visited;
269 inc_irg_block_visited (ir_graph *irg)
271 irg->block_visited = irg->block_visited++;