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 /* Local Variables: */
41 /* Local Prototypes: */
43 /* ===================================================
45 =================================================== */
46 /* Allocate a new pto */
47 static pto_t *new_pto (ir_node *node)
49 /* dummy implementation for fake_pto */
50 pto_t *pto = xmalloc (sizeof (pto_t));
55 /* Allocate a new alloc_pto */
56 static alloc_pto_t *new_alloc_pto (ir_node *node, int n_ctxs)
59 /* dummy implementation for fake_pto */
60 alloc_pto_t *alloc_pto = xmalloc (sizeof (alloc_pto_t));
62 alloc_pto->ptos = (pto_t**) xmalloc (n_ctxs * sizeof (pto_t*));
64 for (i = 0; i < n_ctxs; i ++) {
65 alloc_pto->ptos [i] = new_pto (node);
72 /* Helper to pto_init --- clear the link fields of class types */
73 static void clear_type_link (type_or_ent *thing, void *__unused)
75 if (is_type (thing)) {
76 type *tp = (type*) thing;
78 if (is_class_type (tp)) {
79 DBGPRINT (1, (stdout, "%s (\"%s\")\n",
80 __FUNCTION__, get_type_name (tp)));
82 set_type_link (tp, NULL);
84 } else if (is_entity (thing)) {
85 entity *ent = (entity*) thing;
87 DBGPRINT (1, (stdout, "%s (\"%s\")\n",
88 __FUNCTION__, get_entity_name (ent)));
90 set_entity_link (ent, NULL);
94 /* Helper to pto_init_graph --- clear the links of the given node */
95 static void clear_node_link (ir_node *node, void *__unused)
97 set_irn_link (node, NULL);
100 /* Helper to pto_init_graph --- clear the links of all nodes */
101 static void clear_graph_links (ir_graph *graph)
103 irg_walk_graph (graph, clear_node_link, NULL, NULL);
106 /* Temporary fix until we get 'real' ptos: Allocate some dummy for pto */
107 static void fake_pto (ir_node *node, void *env)
109 init_env_t *init_env = (init_env_t*) env;
110 int n_ctxs = init_env->n_ctxs;
112 const opcode op = get_irn_opcode (node);
120 pto_t *pto = new_pto (node);
121 set_node_pto (node, pto);
125 alloc_pto_t *alloc_pto = new_alloc_pto (node, n_ctxs);
126 set_alloc_pto (node, alloc_pto);
134 /* ===================================================
135 Exported Implementation:
136 =================================================== */
137 /* Initialise the Names of the Types/Entities */
138 void pto_init_type_names ()
141 type_walk (clear_type_link, NULL, NULL);
144 /* Initialise the given graph for a new pass run */
145 void pto_init_graph (ir_graph *graph)
147 graph_info_t *ginfo = ecg_get_info (graph);
148 int n_ctxs = ginfo->n_ctxs;
150 init_env_t *init_env = xmalloc (sizeof (init_env_t));
151 init_env->n_ctxs = n_ctxs;
155 clear_graph_links (graph);
157 entity *ent = get_irg_entity (graph);
159 const char *ent_name = (char*) get_entity_name (ent);
160 const char *own_name = (char*) get_type_name (get_entity_owner (ent));
162 DBGPRINT (0, (stdout, "%s: init \"%s.%s\" for %i ctxs\n", __FUNCTION__,
163 own_name, ent_name, n_ctxs));
165 irg_walk_graph (graph, fake_pto, NULL, init_env);
170 /* Set all alloc names to the right ptos for a new pass run */
171 void pto_init_allocs (graph_info_t *ginfo, int ctx_idx)
173 assert (NULL != ginfo);
175 alloc_info_t *ainfo = ginfo->allocs;
179 while (NULL != ainfo) {
180 ir_node *alloc = ainfo->alloc;
181 alloc_pto_t *alloc_pto = (alloc_pto_t*) get_irn_link (alloc);
183 alloc_pto->curr_pto = alloc_pto->ptos [ctx_idx];
185 DBGPRINT (0, (stdout, "%s:%i (%s[%li]): ctx_idx = %i\n",
186 __FUNCTION__, __LINE__, OPNAME (alloc), OPNUM (alloc), ctx_idx));
197 Revision 1.3 2004/11/18 16:37:07 liekweg