1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Authors: Martin Trapp, Christian Schaefer
10 # include "irgraph_t.h"
16 ir_graph *current_ir_graph;
18 #if USE_EXPICIT_PHI_IN_STACK
19 /* really defined in ircons.c */
20 typedef struct Phi_in_stack Phi_in_stack;
21 Phi_in_stack *new_Phi_in_stack();
24 /* Allocates a list of nodes:
25 - The start block containing a start node and Proj nodes for it's four
26 results (X, M, P, Tuple).
27 - The end block containing an end node. This block is not matured after
28 new_ir_graph as predecessors need to be added to it.
29 - The current block, which is empty and also not matured.
30 Further it allocates several datastructures needed for graph construction
34 new_ir_graph (entity *ent, int params)
40 res = (ir_graph *) malloc (sizeof (ir_graph));
41 current_ir_graph = res;
42 add_irp_irg(res); /* remember this graph global. */
44 /** Internal information for graph construction either held in the graph or
45 *** initialized for each graph. **/
46 res->params = params + 1; /* number of local variables that are never
47 dereferenced in this graph plus one for
48 the store. This is not the number of parameters
50 res->visited = 0; /* visited flag, for the ir walker */
51 res->block_visited=0; /* visited flag, for the 'block'-walker */
53 #if USE_EXPICIT_PHI_IN_STACK
54 res->Phi_in_stack = new_Phi_in_stack(); /* A stack needed for automatic Phi
57 res->obst = (struct obstack *) xmalloc (sizeof (struct obstack));
58 obstack_init (res->obst);
59 res->value_table = new_identities (); /* value table for global value
60 numbering for optimizing use in
63 /** Type inforamtion for the procedure of the graph **/
65 set_entity_irg(ent, res);
67 /** Nodes needed in every graph **/
68 res->end_block = new_immBlock ();
69 res->end = new_End ();
71 res->start_block = new_immBlock ();
72 res->start = new_Start ();
73 res->bad = new_ir_node (res, res->start_block, op_Bad, mode_T, 0, NULL);
75 /* Proj results of start node */
76 projX = new_Proj (res->start, mode_X, pns_initial_exec);
77 set_store (new_Proj (res->start, mode_M, pns_global_store));
78 res->frame = new_Proj (res->start, mode_p, pns_frame_base);
79 res->globals = new_Proj (res->start, mode_p, pns_globals);
80 res->args = new_Proj (res->start, mode_T, pns_args);
82 add_in_edge(res->start_block, projX);
83 // The code generation needs it. leave it in now.
84 // Use of this edge is matter of discussion, unresolved. Also possible:
85 // add_in_edge(res->start_block, res->start_block), but invalid typed.
87 mature_block (res->current_block);
89 /** Make a block to start with **/
90 first_block = new_immBlock ();
91 add_in_edge (first_block, projX);
96 /* access routines for all ir_graph attributes:
98 {attr type} get_irg_{attribute name} (ir_graph *irg);
99 void set_irg_{attr name} (ir_graph *irg, {attr type} {attr}); */
102 get_irg_start_block (ir_graph *irg)
104 return irg->start_block;
108 set_irg_start_block (ir_graph *irg, ir_node *node)
110 irg->start_block = node;
114 get_irg_start (ir_graph *irg)
120 set_irg_start(ir_graph *irg, ir_node *node)
126 get_irg_end_block (ir_graph *irg)
128 return irg->end_block;
132 set_irg_end_block (ir_graph *irg, ir_node *node)
134 irg->end_block = node;
138 get_irg_end (ir_graph *irg)
144 set_irg_end (ir_graph *irg, ir_node *node)
150 get_irg_cstore (ir_graph *irg)
156 set_irg_cstore (ir_graph *irg, ir_node *node)
162 get_irg_frame (ir_graph *irg)
168 set_irg_frame (ir_graph *irg, ir_node *node)
174 get_irg_globals (ir_graph *irg)
180 set_irg_globals (ir_graph *irg, ir_node *node)
186 get_irg_args (ir_graph *irg)
192 set_irg_args (ir_graph *irg, ir_node *node)
198 get_irg_bad (ir_graph *irg)
204 set_irg_bad (ir_graph *irg, ir_node *node)
210 get_irg_current_block (ir_graph *irg)
212 return irg->current_block;
216 set_irg_current_block (ir_graph *irg, ir_node *node)
218 irg->current_block = node;
222 get_irg_ent (ir_graph *irg)
224 assert(irg && irg->ent);
229 set_irg_ent (ir_graph *irg, entity *ent)
235 get_irg_params (ir_graph *irg)
241 set_irg_params (ir_graph *irg, int params)
243 irg->params = params;
247 get_irg_visited (ir_graph *irg)
253 set_irg_visited (ir_graph *irg, unsigned long visited)
255 irg->visited = visited;
259 inc_irg_visited (ir_graph *irg)
261 irg->visited = irg->visited++;
265 get_irg_block_visited (ir_graph *irg)
267 return irg->block_visited;
271 set_irg_block_visited (ir_graph *irg, unsigned long visited)
273 irg->block_visited = visited;
277 inc_irg_block_visited (ir_graph *irg)
279 irg->block_visited = irg->block_visited++;