rewrite
[libfirm] / ir / ana2 / pto_init.c
1 /* -*- c -*- */
2
3 /*
4    Project:     libFIRM
5    File name:   ir/ana/pto_init.c
6    Purpose:     Initialisation Functions
7    Author:      Florian
8    Modified by:
9    Created:     Sat Nov 13 19:35:27 CET 2004
10    CVS-ID:      $Id$
11    Copyright:   (c) 1999-2004 Universität Karlsruhe
12    Licence:     This file is protected by the GPL -  GNU GENERAL PUBLIC LICENSE.
13 */
14
15 # ifdef HAVE_CONFIG_H
16 #  include <config.h>
17 # endif
18
19 /*
20  pto_init: Initialisation Functions
21 */
22
23 # include "pto_init.h"
24 # include "pto_debug.h"
25 # include "pto_comp.h"
26
27 # include "typewalk.h"
28 # include "irgwalk.h"
29 # include "xmalloc.h"
30
31 /* Local Defines: */
32
33 /* Local Data Types: */
34 typedef struct init_env_str
35 {
36   int n_ctxs;
37 } init_env_t;
38
39 /* Local Variables: */
40
41 /* Local Prototypes: */
42
43 /* ===================================================
44    Local Implementation:
45    =================================================== */
46 /* Allocate a new pto */
47 static pto_t *new_pto (ir_node *node)
48 {
49   /* dummy implementation for fake_pto */
50   pto_t *pto = xmalloc (sizeof (pto_t));
51
52   return (pto);
53 }
54
55 /* Allocate a new alloc_pto */
56 static alloc_pto_t *new_alloc_pto (ir_node *node, int n_ctxs)
57 {
58   int i;
59   /* dummy implementation for fake_pto */
60   alloc_pto_t *alloc_pto = xmalloc (sizeof (alloc_pto_t));
61
62   alloc_pto->ptos = (pto_t**) xmalloc (n_ctxs * sizeof (pto_t*));
63
64   for (i = 0; i < n_ctxs; i ++) {
65     alloc_pto->ptos [i] = new_pto (node);
66   }
67
68   return (alloc_pto);
69 }
70
71
72 /* Helper to pto_init --- clear the link fields of class types */
73 static void clear_type_link (type_or_ent *thing, void *__unused)
74 {
75   if (is_type (thing)) {
76     type *tp = (type*) thing;
77
78     if (is_class_type (tp)) {
79       DBGPRINT (1, (stdout, "%s (\"%s\")\n",
80                     __FUNCTION__, get_type_name (tp)));
81
82       set_type_link (tp, NULL);
83     }
84   } else if (is_entity (thing)) {
85     entity *ent = (entity*) thing;
86
87     DBGPRINT (1, (stdout, "%s (\"%s\")\n",
88                   __FUNCTION__, get_entity_name (ent)));
89
90     set_entity_link (ent, NULL);
91   }
92 }
93
94 /* Helper to pto_init_graph --- clear the links of the given node */
95 static void clear_node_link (ir_node *node, void *__unused)
96 {
97   set_irn_link (node, NULL);
98 }
99
100 /* Helper to pto_init_graph --- clear the links of all nodes */
101 static void clear_graph_links (ir_graph *graph)
102 {
103   irg_walk_graph (graph, clear_node_link, NULL, NULL);
104 }
105
106 /* Temporary fix until we get 'real' ptos: Allocate some dummy for pto */
107 static void fake_pto (ir_node *node, void *env)
108 {
109   init_env_t *init_env = (init_env_t*) env;
110   int n_ctxs = init_env->n_ctxs;
111
112   const opcode op = get_irn_opcode (node);
113
114   switch (op) {
115   case (iro_Load):
116   case (iro_SymConst):
117   case (iro_Const):
118   case (iro_Call):
119   case (iro_Phi): {
120     pto_t *pto = new_pto (node);
121     set_node_pto (node, pto);
122     } break;
123
124   case (iro_Alloc): {
125     alloc_pto_t *alloc_pto = new_alloc_pto (node, n_ctxs);
126     set_alloc_pto (node, alloc_pto);
127
128     } break;
129   default:
130     HERE ("no pto");
131   }
132 }
133
134 /* ===================================================
135    Exported Implementation:
136    =================================================== */
137 /* Initialise the Names of the Types/Entities */
138 void pto_init_type_names ()
139 {
140   HERE ("start");
141   type_walk (clear_type_link, NULL, NULL);
142 }
143
144 /* Initialise the given graph for a new pass run */
145 void pto_init_graph (ir_graph *graph)
146 {
147   graph_info_t *ginfo = ecg_get_info (graph);
148   int n_ctxs = ginfo->n_ctxs;
149
150   init_env_t *init_env = xmalloc (sizeof (init_env_t));
151   init_env->n_ctxs = n_ctxs;
152
153   HERE ("start");
154
155   clear_graph_links (graph);
156
157   entity *ent = get_irg_entity (graph);
158
159   const char *ent_name = (char*) get_entity_name (ent);
160   const char *own_name = (char*) get_type_name (get_entity_owner (ent));
161
162   DBGPRINT (0, (stdout, "%s: init \"%s.%s\" for %i ctxs\n", __FUNCTION__,
163                 own_name, ent_name, n_ctxs));
164
165   irg_walk_graph (graph, fake_pto, NULL, init_env);
166
167   HERE ("end");
168 }
169
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)
172 {
173   assert (NULL != ginfo);
174
175   alloc_info_t *ainfo = ginfo->allocs;
176
177   HERE ("start");
178
179   while (NULL != ainfo) {
180     ir_node *alloc = ainfo->alloc;
181     alloc_pto_t *alloc_pto = (alloc_pto_t*) get_irn_link (alloc);
182
183     alloc_pto->curr_pto = alloc_pto->ptos [ctx_idx];
184
185     DBGPRINT (0, (stdout, "%s:%i (%s[%li]): ctx_idx = %i\n",
186                   __FUNCTION__, __LINE__, OPNAME (alloc), OPNUM (alloc), ctx_idx));
187
188     ainfo = ainfo->prev;
189   }
190
191   HERE ("end");
192 }
193
194 \f
195 /*
196   $Log$
197   Revision 1.3  2004/11/18 16:37:07  liekweg
198   rewrite
199
200
201 */