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
23 # include "pto_init.h"
24 # include "pto_debug.h"
25 # include "pto_comp.h"
27 # include "typewalk.h"
33 /* Local Data Types: */
34 typedef struct init_env_str
39 typedef struct reset_env_str
44 /* Local Variables: */
46 /* Local Prototypes: */
48 /* ===================================================
50 =================================================== */
51 /* Allocate a new pto */
52 static pto_t *new_pto (ir_node *node)
54 /* dummy implementation for fake_pto */
55 pto_t *pto = xmalloc (sizeof (pto_t));
60 /* Allocate a new alloc_pto */
61 static alloc_pto_t *new_alloc_pto (ir_node *node, int n_ctxs)
64 /* dummy implementation for testing */
65 alloc_pto_t *alloc_pto = xmalloc (sizeof (alloc_pto_t));
67 alloc_pto->ptos = (pto_t**) xmalloc (n_ctxs * sizeof (pto_t*));
69 for (i = 0; i < n_ctxs; i ++) {
70 alloc_pto->ptos [i] = new_pto (node);
77 /* Helper to pto_init --- clear the link fields of class types */
78 static void clear_type_link (type_or_ent *thing, void *__unused)
80 if (is_type (thing)) {
81 type *tp = (type*) thing;
83 if (is_class_type (tp)) {
84 DBGPRINT (1, (stdout, "%s (\"%s\")\n",
85 __FUNCTION__, get_type_name (tp)));
87 set_type_link (tp, NULL);
89 } else if (is_entity (thing)) {
90 entity *ent = (entity*) thing;
92 DBGPRINT (1, (stdout, "%s (\"%s\")\n",
93 __FUNCTION__, get_entity_name (ent)));
95 set_entity_link (ent, NULL);
99 /* Helper to pto_init_graph --- clear the links of the given node */
100 static void clear_node_link (ir_node *node, void *__unused)
102 set_irn_link (node, NULL);
105 /* Helper to pto_init_graph --- clear the links of all nodes */
106 static void clear_graph_links (ir_graph *graph)
108 irg_walk_graph (graph, clear_node_link, NULL, NULL);
111 /* Reset ALL the pto values for a new pass */
112 static void reset_node_pto (ir_node *node, void *env)
114 reset_env_t *reset_env = (reset_env_t*) env;
115 int ctx_idx = reset_env->ctx_idx;
116 const opcode op = get_irn_opcode (node);
124 /* todo: allocate 'empty' pto values */
125 pto_t *pto = new_pto (node);
126 set_node_pto (node, pto);
130 /* todo: set alloc to 'right' current pto */
131 alloc_pto_t *alloc_pto = (alloc_pto_t*) get_irn_link (node);
132 alloc_pto->curr_pto = alloc_pto->ptos [ctx_idx];
141 /* Temporary fix until we get 'real' ptos: Allocate some dummy for pto */
142 static void init_alloc_pto (ir_node *node, void *env)
144 init_env_t *init_env = (init_env_t*) env;
145 int n_ctxs = init_env->n_ctxs;
147 const opcode op = get_irn_opcode (node);
155 /* nothing (handled by init_node_pto) */
159 /* todo: alloc 'right' ptos */
160 alloc_pto_t *alloc_pto = new_alloc_pto (node, n_ctxs);
161 set_alloc_pto (node, alloc_pto);
171 /* Initialise the given graph for a new pass run */
172 static void pto_init_graph_allocs (ir_graph *graph)
174 graph_info_t *ginfo = ecg_get_info (graph);
175 int n_ctxs = ginfo->n_ctxs;
177 init_env_t *init_env = xmalloc (sizeof (init_env_t));
178 init_env->n_ctxs = n_ctxs;
182 irg_walk_graph (graph, init_alloc_pto, NULL, init_env);
187 /* ===================================================
188 Exported Implementation:
189 =================================================== */
190 /* Initialise the Names of the Types/Entities */
191 void pto_init_type_names ()
194 type_walk (clear_type_link, NULL, NULL);
198 /* Initialise the given graph for a new pass run */
199 void pto_init_graph (ir_graph *graph)
201 graph_info_t *ginfo = ecg_get_info (graph);
202 const int n_ctxs = ginfo->n_ctxs;
204 /* only for debugging stuff: */
205 entity *ent = get_irg_entity (graph);
206 const char *ent_name = (char*) get_entity_name (ent);
207 const char *own_name = (char*) get_type_name (get_entity_owner (ent));
209 DBGPRINT (0, (stdout, "%s: init \"%s.%s\" for %i ctxs\n", __FUNCTION__,
210 own_name, ent_name, n_ctxs));
214 clear_graph_links (graph);
215 pto_init_graph_allocs (graph);
220 /* Reset the given graph for a new pass run */
221 void pto_reset_graph_pto (ir_graph *graph, int ctx_idx)
225 reset_env_t *reset_env = (reset_env_t*) xmalloc (sizeof (reset_env_t));
226 reset_env->ctx_idx = ctx_idx;
228 irg_walk_graph (graph, reset_node_pto, NULL, reset_env);
236 Revision 1.4 2004/11/20 21:21:56 liekweg
237 Finalise initialisation
239 Revision 1.3 2004/11/18 16:37:07 liekweg