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)
74 assert (iro_Alloc == get_irn_opcode (alloc));
77 alloc_pto_t *alloc_pto = obstack_alloc (pto_obst, sizeof (alloc_pto_t));
78 type *tp = get_Alloc_type (alloc);
80 alloc_pto->ptos = (pto_t**) obstack_alloc (pto_obst, n_ctxs * sizeof (pto_t*));
82 for (i = 0; i < n_ctxs; i ++) {
83 desc_t *desc = new_name (tp, alloc);
84 alloc_pto->ptos [i] = new_pto (alloc);
85 qset_insert (alloc_pto->ptos [i]->values, desc);
91 /* Allocate a new pto for a symconst */
92 static pto_t* new_symconst_pto (ir_node *symconst)
94 assert (iro_SymConst == get_irn_opcode (symconst));
96 pto_t *pto = new_pto (symconst);
97 entity *ent = get_SymConst_entity (symconst);
100 /* ok, so if the symconst has a pointer-to-mumble, it's some address
101 calculation, but if it's the mumble itself, it's just the same,
102 except it's presumably a constant of mumble. In any case, we need to
103 branch on this. "How's that for object fucking oriented? --jwz" */
104 if (is_pointer_type (get_entity_type (ent))) {
105 desc = new_ent_name (ent);
106 } else if (is_class_type (get_entity_type (ent))) {
107 desc = new_name (get_entity_type (ent), symconst);
109 fprintf (stderr, "%s: not handled: %s[%li] (\"%s\")\n",
111 get_op_name (get_irn_op (symconst)),
112 get_irn_node_nr (symconst),
113 get_entity_name (ent));
114 assert (0 && "something not handled");
117 qset_insert (pto->values, desc);
122 /* Allocate a new pto for a constant */
123 static pto_t *new_const_pto (ir_node *cnst)
125 assert (iro_Const == get_irn_opcode (cnst));
126 assert (mode_P == get_irn_mode (cnst));
128 static pto_t *cnst_pto = NULL;
130 /* since 'store's and 'load's via a NULL pointer are hardly ever
131 successful, we get away with an empty set */
133 tarval *tv = get_Const_tarval (cnst);
135 assert (tv == get_tarval_null (mode_P));
137 if (NULL == cnst_pto) {
138 cnst_pto = new_pto (cnst);
145 /* Helper to pto_init --- clear the link fields of class types */
146 static void clear_type_link (type_or_ent *thing, void *__unused)
148 if (is_type (thing)) {
149 type *tp = (type*) thing;
151 if (is_class_type (tp)) {
152 DBGPRINT (1, (stdout, "%s (\"%s\")\n",
153 __FUNCTION__, get_type_name (tp)));
155 set_type_link (tp, NULL);
157 } else if (is_entity (thing)) {
158 entity *ent = (entity*) thing;
160 DBGPRINT (1, (stdout, "%s (\"%s\")\n",
161 __FUNCTION__, get_entity_name (ent)));
163 set_entity_link (ent, NULL);
167 /* Helper to pto_init_graph --- clear the links of the given node */
168 static void clear_node_link (ir_node *node, void *__unused)
170 set_irn_link (node, NULL);
173 /* Helper to pto_init_graph --- clear the links of all nodes */
174 static void clear_graph_links (ir_graph *graph)
176 irg_walk_graph (graph, clear_node_link, NULL, NULL);
179 /* Reset ALL the pto values for a new pass */
180 static void reset_node_pto (ir_node *node, void *env)
182 reset_env_t *reset_env = (reset_env_t*) env;
183 int ctx_idx = reset_env->ctx_idx;
184 const opcode op = get_irn_opcode (node);
188 /* case (iro_SymConst): */ /* WHY? */
191 case (iro_Block): /* END BLOCK only */
193 /* allocate 'empty' pto values */
194 pto_t *pto = new_pto (node);
195 set_node_pto (node, pto);
199 /* set alloc to 'right' current pto */
200 alloc_pto_t *alloc_pto = (alloc_pto_t*) get_irn_link (node);
201 alloc_pto->curr_pto = alloc_pto->ptos [ctx_idx];
210 /* Temporary fix until we get 'real' ptos: Allocate some dummy for pto */
211 static void init_pto (ir_node *node, void *env)
213 init_env_t *init_env = (init_env_t*) env;
214 int n_ctxs = init_env->n_ctxs;
216 const opcode op = get_irn_opcode (node);
219 case (iro_SymConst): {
220 if (mode_P == get_irn_mode (node)) {
222 entity *ent = get_SymConst_entity (node);
223 if (is_class_type (get_entity_type (ent)) ||
224 is_pointer_type (get_entity_type (ent))) {
225 DBGPRINT (0, (stdout, "%s: new name \"%s\" for \"%s[%li]\"\n",
227 get_entity_name (ent),
231 pto_t *symconst_pto = new_symconst_pto (node);
232 set_node_pto (node, symconst_pto);
237 type *tp = get_Alloc_type (node); /* debugging only */
238 alloc_pto_t *alloc_pto = new_alloc_pto (node, n_ctxs);
239 set_alloc_pto (node, alloc_pto);
241 DBGPRINT (0, (stdout, "%s: %i names \"%s\" for \"%s[%li]\"\n",
250 if (mode_P == get_irn_mode (node)) {
251 pto_t *pto = new_const_pto (node);
252 set_node_pto (node, pto);
259 /* nothing --- handled by reset_node_pto on each pass */
268 /* Initialise the given graph for a new pass run */
269 static void pto_init_graph_allocs (ir_graph *graph)
271 graph_info_t *ginfo = ecg_get_info (graph);
272 int n_ctxs = ginfo->n_ctxs;
274 init_env_t *init_env = xmalloc (sizeof (init_env_t));
275 init_env->n_ctxs = n_ctxs;
279 irg_walk_graph (graph, init_pto, NULL, init_env);
281 memset (init_env, 0x00, sizeof (init_env_t));
287 /* ===================================================
288 Exported Implementation:
289 =================================================== */
290 /* "Fake" the arguments to the main method */
291 void fake_main_args (ir_graph *graph)
295 entity *ent = get_irg_entity (graph);
296 type *mtp = get_entity_type (ent);
297 ir_node **args = find_irg_args (graph);
298 type *ctp = get_method_param_type (mtp, 1); /* ctp == char[]*[]* */
300 /* 'main' has signature 'void(int, char[]*[]*)' */
301 assert (NULL == args [2]);
303 assert (is_pointer_type (ctp));
305 ctp = get_pointer_points_to_type (ctp); /* ctp == char[]*[] */
307 assert (is_array_type (ctp));
309 desc_t *arg_desc = new_name (ctp, args [1]);
310 pto_t *arg_pto = new_pto (args [1]);
311 /* todo: simulate 'store' to arg1[] ?!? */
312 qset_insert (arg_pto->values, arg_desc);
314 set_node_pto (args [1], arg_pto);
316 # ifdef TEST_MAIN_TYPE
317 ctp = get_array_element_type (ctp); /* ctp == char[]* */
319 assert (is_pointer_type (ctp));
321 ctp = get_pointer_points_to_type (ctp); /* ctp == char[] */
323 assert (is_array_type (ctp));
325 ctp = get_array_element_type (ctp); /* ctp == char */
327 assert (is_primitive_type (ctp));
328 # endif /* defined TEST_MAIN_TYPE */
333 /* Initialise the Init module */
334 void pto_init_init ()
336 pto_obst = (struct obstack*) xmalloc (sizeof (struct obstack));
338 obstack_init (pto_obst);
341 /* Cleanup the Init module */
342 void pto_init_cleanup ()
344 obstack_free (pto_obst, NULL);
345 memset (pto_obst, 0x00, sizeof (struct obstack));
351 /* Initialise the Names of the Types/Entities */
352 void pto_init_type_names ()
355 type_walk (clear_type_link, NULL, NULL);
359 /* Initialise the given graph for a new pass run */
360 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 (0, (stdout, "%s: init \"%s.%s\" for %i ctxs\n", __FUNCTION__,
371 own_name, ent_name, n_ctxs));
375 clear_graph_links (graph);
376 pto_init_graph_allocs (graph);
381 /* Reset the given graph for a new pass run */
382 void pto_reset_graph_pto (ir_graph *graph, int ctx_idx)
386 reset_env_t *reset_env = (reset_env_t*) xmalloc (sizeof (reset_env_t));
387 reset_env->ctx_idx = ctx_idx;
389 irg_walk_graph (graph, reset_node_pto, NULL, reset_env);
391 memset (reset_env, 0x00, sizeof (reset_env_t));
399 Revision 1.6 2004/11/26 16:00:41 liekweg
400 recognize class consts vs. ptr-to-class consts
402 Revision 1.5 2004/11/24 14:53:56 liekweg
405 Revision 1.4 2004/11/20 21:21:56 liekweg
406 Finalise initialisation
408 Revision 1.3 2004/11/18 16:37:07 liekweg