added initialisation
[libfirm] / ir / ana2 / pto_init.c
1 /* -*- c -*- */
2
3 /*
4  * Project:     libFIRM
5  * File name:   ir/ana2/pto_init.c
6  * Purpose:     Pto Initialization
7  * Author:      Florian
8  * Modified by:
9  * Created:     Wed  3 Nov 2004
10  * CVS-ID:      $Id$
11  * Copyright:   (c) 1999-2004 Universität Karlsruhe
12  * Licence:     This file is protected by GPL -  GNU GENERAL PUBLIC LICENSE.
13  */
14
15
16 # ifdef HAVE_CONFIG_H
17 #  include <config.h>
18 # endif
19
20 # include "pto.h"
21 # include "pto_util.h"
22
23 # include "entity.h"
24 # include "irnode.h"
25 # include "xmalloc.h"
26
27 # define DBGPRINT(lvl, msg) if (get_pto_verbose () > lvl) { fprintf msg; }
28
29 static void pto_init_proj_load (ir_node *proj, ir_node *load)
30 {
31   assert ((mode_P == get_irn_mode (proj)) && "wrong proj(load)");
32
33 # ifdef PTO_DUMMY
34   ir_node *ptr = get_Load_ptr (load);
35   entity *ent = get_ptr_ent (ptr);
36   type *tp = get_entity_type (ent);
37 # endif /* defined PTO_DUMMY */
38
39   pto_t *pto = pto_new_empty (proj);
40
41   DBGPRINT (1, (stdout, "%s: pto (%s[%li]) = 0x%08x\n",
42                 __FUNCTION__,
43                 get_op_name (get_irn_op (proj)),
44                 get_irn_node_nr (proj),
45                 (int) pto));
46
47   set_pto (proj, pto);
48 }
49
50 static void pto_init_call (ir_node *call)
51 {
52   /* check return value: */
53   ir_node *ptr = get_Call_ptr (call);
54   entity *ent = get_ptr_ent (ptr);
55   type *meth_tp = get_entity_type (ent);
56
57   if (0 == get_method_n_ress (meth_tp)) {
58     /* can't be a pointer */
59     return;
60   }
61
62   type *ret_tp  = get_method_res_type (meth_tp, 0);
63
64   if (mode_P != get_type_mode (ret_tp)) {
65     return;
66   }
67
68 # ifdef PTO_DUMMY
69   ir_node *ptr = get_Call_ptr (call);
70   entity *ent = get_ptr_ent (ptr);
71   type *tp = get_entity_type (ent);
72
73   obj_desc_t *obj_desc = obj_desc_new (tp);
74   obj_desc_set_dummy (obj_desc);
75 # endif /* defined PTO_DUMMY */
76
77   pto_t *pto = pto_new_empty (call);
78
79   DBGPRINT (1, (stdout, "%s: pto (%s[%li]) = 0x%08x\n",
80                 __FUNCTION__,
81                 get_op_name (get_irn_op (call)),
82                 get_irn_node_nr (call),
83                 (int) pto));
84
85   set_pto (call, pto);
86 }
87
88 static void pto_init_raise (ir_node *raise)
89 {
90   /* assert (0 && "initialise raise?"); */
91
92   /* right now, do nothing and hope that a raise can always be
93      analysed on-the-fly. */
94 }
95
96 static void pto_init_proj (ir_node *proj)
97 {
98   ir_node *in = get_Proj_pred (proj);
99   const opcode in_op = get_irn_opcode (in);
100
101   switch (in_op) {
102   case (iro_Proj): {
103     ir_node *in_in = get_Proj_pred (in);
104     const opcode in_in_op = get_irn_opcode (in_in);
105
106     switch (in_in_op) {
107     case (iro_Start): {
108       /* nothing (always initialised with actual values) */
109     } break;
110
111     case (iro_Call): {
112       /* nothing (must use call itself) */
113     } break;
114
115     default: {
116       fprintf (stderr, "%s: proj(proj(%s[%ld])) not handled\n",
117                __FUNCTION__,
118                get_op_name (get_irn_op (in_in)),
119                get_irn_node_nr (in_in));
120       assert (0);
121     }
122     } /* end switch(Proj.Proj.op) */
123   } break; /* iro_Proj */
124
125   case (iro_Start): {
126     /* ProjM (start) or ProjT (start) --- nothing */
127   } break;
128
129   case (iro_Call): {
130     /* ProjT (start) --- nothing */
131   } break;
132
133   case (iro_Load): {
134     /* Todo: ProjM (load) or ProjV(load) */
135     if (mode_P == get_irn_mode (proj)) {
136       pto_init_proj_load (proj, in);
137     } else {
138       /* nothing to do */
139     }
140   } break;
141
142   case (iro_Store): {
143     /* ProjM (store) --- nothing */
144   } break;
145
146   case (iro_Alloc): {
147     /* nothing to do --- can always be computed on-the-fly */
148   } break;
149
150   case (iro_Raise): {
151     /* ProjM (raise) or Proj???(raise) --- TODO */
152   } break;
153
154   case (iro_Cast): {
155     /* not needed */
156   } break;
157
158   default: {
159     fprintf (stderr, "%s: proj(%s[%ld]) not handled\n",
160              __FUNCTION__,
161              get_op_name (get_irn_op (in)),
162              get_irn_node_nr (in));
163     assert (0);
164   }
165   } /* end switch (Proj.op) */
166
167 }
168
169 void pto_init_node (ir_node *node)
170 {
171   const opcode op = get_irn_opcode (node);
172
173   DBGPRINT (1, (stdout, "%s (%s[%li])\n",
174                 __FUNCTION__,
175                 get_op_name (get_irn_op (node)),
176                 get_irn_node_nr (node)));
177
178   switch (op) {
179   case (iro_Start): {
180     /* nothing (not needed) */
181   } break;
182
183   case (iro_Load): {
184     /* nothing (not needed) */
185   } break;
186
187   case (iro_Store): {
188     /* nothing (not needed) */
189   } break;
190
191   case (iro_Alloc): {
192     /* nothing (can always be computed on-the-fly) */
193   } break;
194
195   case (iro_Raise): {
196     /* Todo: Check how a Raise works */
197     pto_init_raise (node);
198   } break;
199
200   case (iro_Call): {
201     /* pretend we have a return value */
202     pto_init_call (node);
203   } break;
204
205   case (iro_Proj): {
206     /* this actually does most of the work */
207     pto_init_proj (node);
208   } break;
209
210   case (iro_Cast): {
211     /* nothing (can always be computed on-the-fly) */
212   } break;
213
214   case (iro_SymConst): {
215     /* nothing (can always be computed on-the-fly) */
216   } break;
217
218   case (iro_Const): {
219     /* nothing (can always be computed on-the-fly) */
220   } break;
221
222   case (iro_Block): {
223     /* nothing (this is only interesting for the end block, and that
224        can always be computed on-the-fly) */
225   } break;
226
227   case (iro_Phi): {
228     /* nothing (This would need the predecessors to be initialized! Do this on-the-fly) */
229   } break;
230
231   /* now, enumerate everything else that is uninteresting */
232   case (iro_Return):
233   case (iro_Div):
234   case (iro_Quot):
235   case (iro_Mod):
236   case (iro_DivMod): {
237     /* nothing (not needed) */
238   } break;
239
240   default: {
241     fprintf (stderr, "%s: %s[%ld] not handled\n",
242              __FUNCTION__,
243              get_op_name (get_irn_op (node)),
244              get_irn_node_nr (node));
245     assert (0);
246   } break;
247
248   }
249 }
250
251
252 \f
253 /*
254  * $Log$
255  * Revision 1.1  2004/11/04 14:58:59  liekweg
256  * added initialisation
257  *
258  *
259  */