5 File name: ir/ana/pto_init.c
6 Purpose: Initialisation Functions
9 Created: Sat Nov 13 19:35:27 CET 2004
11 Copyright: (c) 1999-2004 Universität Karlsruhe
12 Licence: This file is protected by the GPL - GNU GENERAL PUBLIC LICENSE.
20 pto_init: Initialisation Functions
27 # include "pto_init.h"
28 # include "pto_debug.h"
29 # include "pto_comp.h"
30 # include "pto_name.h"
31 # include "pto_util.h"
33 # include "typewalk.h"
38 # define obstack_chunk_alloc xmalloc
39 # define obstack_chunk_free free
41 /* Local Data Types: */
42 typedef struct init_env_str
47 typedef struct reset_env_str
52 /* Local Variables: */
53 extern struct obstack *qset_obst; /* from pto_name */
55 static struct obstack *pto_obst = NULL; /* all pto_t's go onto this one */
57 /* Local Prototypes: */
59 /* ===================================================
61 =================================================== */
62 /* Allocate a new pto */
63 static pto_t *new_pto (ir_node *node)
65 pto_t *pto = obstack_alloc (pto_obst, sizeof (pto_t));
66 pto->values = qset_new (N_INITIAL_OJBS, qset_obst);
71 /* Allocate a new alloc_pto */
72 static alloc_pto_t *new_alloc_pto (ir_node *alloc, int n_ctxs)
75 alloc_pto_t *alloc_pto = obstack_alloc (pto_obst, sizeof(*alloc_pto));
78 assert (op_Alloc == get_irn_op(alloc));
80 tp = get_Alloc_type (alloc);
82 alloc_pto->ptos = (pto_t**) obstack_alloc (pto_obst, n_ctxs * sizeof (pto_t*));
84 for (i = 0; i < n_ctxs; i ++) {
85 desc_t *desc = new_name (tp, alloc, i);
86 alloc_pto->ptos [i] = new_pto (alloc);
87 qset_insert (alloc_pto->ptos [i]->values, desc);
93 /* Allocate a new pto for a symconst */
94 static pto_t* new_symconst_pto (ir_node *symconst)
100 assert (op_SymConst == get_irn_op(symconst));
102 pto = new_pto (symconst);
103 ent = get_SymConst_entity (symconst);
106 const char *ent_name = (char*) get_entity_name (ent);
107 const char *own_name = (char*) get_type_name (get_entity_owner (ent));
108 HERE3 ("start", own_name, ent_name);
110 /* Ok, so if the symconst has a pointer-to-mumble, it's some address
111 calculation, but if it's the mumble itself, it's just the same,
112 except it's presumably a constant of mumble. In any case, we need to
113 branch on this. "How's that for object fucking oriented? --jwz" */
114 if (is_pointer_type (get_entity_type (ent))) {
115 desc = new_ent_name (ent);
116 } else if (is_class_type (get_entity_type (ent))) {
117 desc = new_name (get_entity_type (ent), symconst, -1);
119 fprintf (stderr, "new_symconst_pto(): not handled: %s[%li] (\"%s\")\n",
120 get_op_name (get_irn_op (symconst)),
121 get_irn_node_nr (symconst),
122 get_entity_name (ent));
123 assert (0 && "something not handled");
126 qset_insert (pto->values, desc);
128 /* HERE3 ("end", own_name, ent_name); */
133 /* Helper to pto_init --- clear the link fields of class types */
134 static void clear_type_link (type_or_ent *thing, void *_unused)
136 if (is_type (thing)) {
137 type *tp = (type*) thing;
139 if (is_class_type (tp)) {
140 DBGPRINT (1, (stdout, "clear_type_link() (\"%s\")\n",
141 get_type_name (tp)));
143 set_type_link (tp, NULL);
145 } else if (is_entity (thing)) {
146 entity *ent = (entity*) thing;
148 DBGPRINT (1, (stdout, "clear_type_link() (\"%s\")\n",
149 get_entity_name (ent)));
151 set_entity_link (ent, NULL);
155 /* Helper to pto_init_graph --- clear the links of the given node */
156 static void clear_node_link (ir_node *node, void *_unused)
158 set_irn_link (node, NULL);
161 /* Helper to pto_init_graph --- clear the links of all nodes */
162 static void clear_graph_links (ir_graph *graph)
164 irg_walk_graph (graph, clear_node_link, NULL, NULL);
167 /* Reset ALL the pto values for a new pass */
168 static void reset_node_pto (ir_node *node, void *env)
170 reset_env_t *reset_env = (reset_env_t*) env;
171 int ctx_idx = reset_env->ctx_idx;
172 opcode op = get_irn_opcode (node);
174 /* HERE ("start"); */
179 case (iro_Block): /* END BLOCK only */
181 /* allocate 'empty' pto values */
182 pto_t *pto = new_pto (node);
183 set_node_pto (node, pto);
187 /* set alloc to 'right' current pto */
188 alloc_pto_t *alloc_pto = (alloc_pto_t*) get_irn_link (node);
189 alloc_pto->curr_pto = alloc_pto->ptos [ctx_idx];
191 DBGPRINT (1, (stdout, "reset_node_pto(): setting pto of \"%s[%li]\" for ctx %i\n",
196 assert (alloc_pto->curr_pto);
198 case (iro_SymConst): {
199 /* nothing, leave as-is */
203 /* basically, nothing */
204 DBGPRINT (2, (stdout, "reset_node_pto(): resetting pto of \"%s[%li]\"\n",
207 set_node_pto (node, NULL);
214 /* Initialise primary name sources */
215 static void init_pto (ir_node *node, void *env)
217 init_env_t *init_env = (init_env_t*) env;
218 int n_ctxs = init_env->n_ctxs;
220 opcode op = get_irn_opcode (node);
223 case (iro_SymConst): {
224 if (mode_is_reference(get_irn_mode (node))) {
225 entity *ent = get_SymConst_entity (node);
226 type *tp = get_entity_type (ent);
227 if (is_class_type (tp) || is_pointer_type (tp)) {
228 pto_t *symconst_pto = new_symconst_pto (node);
229 set_node_pto (node, symconst_pto);
232 DBGPRINT (1, (stdout, "init_pto(): new name \"%s\" for \"%s[%li]\"\n",
233 get_entity_name (ent),
241 alloc_pto_t *alloc_pto = new_alloc_pto (node, n_ctxs);
244 set_alloc_pto (node, alloc_pto);
246 tp = get_Alloc_type (node); /* debugging only */
247 DBGPRINT (1, (stdout, "init_pto(): %i names \"%s\" for \"%s[%li]\"\n",
257 /* nothing --- handled by reset_node_pto on each pass */
266 /* Initialise the given graph for a new pass run */
267 static void pto_init_graph_allocs (ir_graph *graph)
269 graph_info_t *ginfo = ecg_get_info (graph);
272 init_env.n_ctxs = ginfo->n_ctxs;
274 /* HERE ("start"); */
276 irg_walk_graph (graph, init_pto, NULL, &init_env);
281 /* ===================================================
282 Exported Implementation:
283 =================================================== */
284 /* "Fake" the arguments to the main method */
285 void fake_main_args (ir_graph *graph)
287 /* HERE ("start"); */
289 entity *ent = get_irg_entity (graph);
290 type *mtp = get_entity_type (ent);
291 ir_node **args = find_irg_args (graph);
292 type *ctp = get_method_param_type (mtp, 1); /* ctp == char[]*[]* */
296 /* 'main' has signature 'void(int, char[]*[]*)' */
297 assert (NULL == args [2]);
299 assert (is_pointer_type (ctp));
301 ctp = get_pointer_points_to_type (ctp); /* ctp == char[]*[] */
303 assert (is_array_type (ctp));
305 arg_desc = new_name (ctp, args [1], -1);
306 arg_pto = new_pto (args [1]);
307 /* todo: simulate 'store' to arg1[] ?!? */
308 qset_insert (arg_pto->values, arg_desc);
310 set_node_pto (args [1], arg_pto);
312 DBGPRINT (1, (stdout, "fake_main_args():%i (%s[%li])\n",
313 __LINE__, OPNAME (args [1]), OPNUM (args [1])));
315 # ifdef TEST_MAIN_TYPE
316 ctp = get_array_element_type (ctp); /* ctp == char[]* */
318 assert (is_pointer_type (ctp));
320 ctp = get_pointer_points_to_type (ctp); /* ctp == char[] */
322 assert (is_array_type (ctp));
324 ctp = get_array_element_type (ctp); /* ctp == char */
326 assert (is_primitive_type (ctp));
327 # endif /* defined TEST_MAIN_TYPE */
332 /* Initialise the Init module */
333 void pto_init_init (void)
335 pto_obst = xmalloc(sizeof(*pto_obst));
337 obstack_init (pto_obst);
340 /* Cleanup the Init module */
341 void pto_init_cleanup (void)
343 obstack_free (pto_obst, NULL);
344 memset (pto_obst, 0, sizeof (*pto_obst));
350 /* Initialise the Names of the Types/Entities */
351 void pto_init_type_names ()
353 /* HERE ("start"); */
354 type_walk (clear_type_link, NULL, NULL);
358 /* Initialise the given graph for a new pass run */
359 void pto_init_graph (ir_graph *graph)
362 graph_info_t *ginfo = ecg_get_info (graph);
363 const int n_ctxs = ginfo->n_ctxs;
365 /* only for debugging stuff: */
366 entity *ent = get_irg_entity (graph);
367 const char *ent_name = (char*) get_entity_name (ent);
368 const char *own_name = (char*) get_type_name (get_entity_owner (ent));
370 DBGPRINT (2, (stdout, "pto_init_graph(): init \"%s.%s\" for %i ctxs\n",
371 own_name, ent_name, n_ctxs));
373 /* HERE ("start"); */
375 clear_graph_links (graph);
376 pto_init_graph_allocs (graph);
380 assert (NULL == get_irg_proj_args (graph));
381 proj_args = find_irg_args (graph);
382 set_irg_proj_args (graph, proj_args);
383 assert (proj_args == get_irg_proj_args (graph));
386 /* Reset the given graph for a new pass run */
387 void pto_reset_graph_pto (ir_graph *graph, int ctx_idx)
389 reset_env_t reset_env;
390 reset_env.ctx_idx = ctx_idx;
392 /* HERE ("start"); */
394 irg_walk_graph (graph, reset_node_pto, NULL, &reset_env);
402 Revision 1.13 2004/12/21 15:07:55 beck
403 removed C99 contructs
404 removed unnecessary allocation
405 removed use of mode_P, use mode_is_reference() instead
406 removed handling of Const with pointer tarvals, these constructs are removed
408 Revision 1.12 2004/12/20 17:41:14 liekweg
411 Revision 1.11 2004/12/20 17:34:35 liekweg
412 fix recursion handling
414 Revision 1.10 2004/12/15 13:31:00 liekweg
415 store ctx idx in names
417 Revision 1.9 2004/12/15 09:18:18 liekweg
420 Revision 1.8 2004/12/02 16:17:51 beck
421 fixed config.h include
423 Revision 1.7 2004/11/30 14:47:54 liekweg
424 fix initialisation; do correct iteration
426 Revision 1.6 2004/11/26 16:00:41 liekweg
427 recognize class consts vs. ptr-to-class consts
429 Revision 1.5 2004/11/24 14:53:56 liekweg
432 Revision 1.4 2004/11/20 21:21:56 liekweg
433 Finalise initialisation
435 Revision 1.3 2004/11/18 16:37:07 liekweg