Allow the Bad node to be set in set_store(). This is neccessary, because Bad might...
[libfirm] / ir / ir / iropt_dbg.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/ir/iropt_dbg.h
4  * Purpose:     Debug makros used in iropt.
5  * Author:      Goetz Lindenmaier
6  * Modified by:
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 2001-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13 #ifndef _IROPT_DBG_H_
14 #define _IROPT_DBG_H_
15
16 #include "dbginfo_t.h"
17 #include "irhooks.h"
18 #include "firmstat.h"
19
20 /* This file contains makros that generate the calls to
21    update the debug information after a transformation. */
22
23 #define SIZ(x)    sizeof(x)/sizeof((x)[0])
24
25
26 /**
27  * Merge the debug info due to dead block elimination.
28  *
29  * @param oldn  the block that it is eliminated
30  * @param n     the new node for this block, may be equal to oldn
31  */
32 #define DBG_OPT_DEAD_BLOCK(oldn, n)                         \
33   do {                                                      \
34     hook_merge_nodes(&n, 1, &oldn, 1, HOOK_OPT_DEAD_BLOCK); \
35     __dbg_info_merge_pair(n, oldn, dbg_dead_code);          \
36         } while(0)
37
38
39 /**
40  * Merge the debug info due to a straightening optimization.
41  * Block oldn is merged with n.
42  *
43  * @param oldn  the old block
44  * @param n     the new block the merges with oldn
45  */
46 #define DBG_OPT_STG(oldn, n)                                 \
47   do {                                                       \
48           ir_node *ons[2];                                         \
49           ons[0] = oldn;                                           \
50           ons[1] = get_Block_cfgpred(oldn, 0);                     \
51           hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_STG);    \
52           __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_straightening); \
53         } while(0)
54
55 /**
56  * Merge the debug info due to an if simplification.
57  *
58  * @param oldn   the old Block
59  * @param proj1  the first ProjX predecessor
60  * @param proj2  the second ProjX predecessor
61  * @param n      the new Block
62  */
63 #define DBG_OPT_IFSIM1(oldn, proj1, proj2, n)                   \
64   do {                                                          \
65           ir_node *ons[4];                                            \
66           ons[0] = oldn;                                              \
67           ons[1] = proj1;                                             \
68           ons[2] = proj2;                                             \
69           ons[3] = get_Proj_pred(proj1);                              \
70           hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_IFSIM);     \
71           __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_if_simplification); \
72         } while(0)
73
74 /**
75  * Merge the debug info due to an if simplification.
76  * @param oldn   the old Cond
77  * @param n      the new Jmp
78  */
79 #define DBG_OPT_IFSIM2(oldn, n)                            \
80   do {                                                     \
81           hook_merge_nodes(&n, 1, &oldn, 1, HOOK_OPT_IFSIM);     \
82           __dbg_info_merge_pair(n, oldn, dbg_if_simplification); \
83         } while(0)
84
85 /**
86  * Merge the debug info due to an algebraic_simplification.
87  * A node could be avaluated into a Constant.
88  *
89  * @param oldn  the node
90  * @param n     the new constant holding the value
91  */
92 #define DBG_OPT_CSTEVAL(oldn, n)                                  \
93   do {                                                                  \
94           hook_merge_nodes(&n, 1, &oldn, 1, HOOK_OPT_CONST_EVAL);         \
95     __dbg_info_merge_pair(n, oldn, dbg_const_eval);                  \
96   } while(0)
97
98 /**
99  * Merge the debug info due to an algebraic_simplification.
100  *
101  * @param oldn  the old node
102  * @param n     the new node replacing oldn
103  * @param flag  firm statistics option
104  */
105 #define DBG_OPT_ALGSIM0(oldn, n, flag)                            \
106   do {                                                            \
107     hook_merge_nodes(&n, 1, &oldn, 1, flag);                            \
108     __dbg_info_merge_pair(n, oldn, dbg_algebraic_simplification); \
109   } while(0)
110
111 /**
112  * Merge the debug info due to an algebraic_simplification.
113  *
114  * @param oldn  the old node
115  * @param a     a predecessor of oldn
116  * @param b     a predecessor of oldn
117  * @param n     the new node replacing oldn
118  * @param flag  firm statistics option
119  */
120 #define DBG_OPT_ALGSIM1(oldn, a, b, n, flag)                    \
121   do {                                                          \
122           ir_node *ons[3];                                            \
123           ons[0] = oldn;                                              \
124           ons[1] = a;                                                 \
125           ons[2] = b;                                                 \
126           hook_merge_nodes(&n, 1, ons, SIZ(ons), flag);               \
127           __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_algebraic_simplification); \
128   } while(0)
129
130 /**
131  * Merge the debug info due to an algebraic_simplification.
132  */
133 #define DBG_OPT_ALGSIM2(oldn, pred, n)                          \
134   do {                                                          \
135           ir_node *ons[3];                                            \
136           ons[0] = oldn;                                              \
137           ons[1] = pred;                                              \
138           ons[2] = n;                                                 \
139           hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_ALGSIM);    \
140           __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_algebraic_simplification); \
141   } while(0)
142
143 /**
144  * Merge the debug info due to an algebraic_simplification.
145  */
146 #define DBG_OPT_ALGSIM3(oldn, a, n)                             \
147   do {                                                          \
148           ir_node *ons[2];                                            \
149           ons[0] = oldn;                                              \
150           ons[1] = a;                                                 \
151           hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_ALGSIM);    \
152           __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_algebraic_simplification); \
153   } while(0)
154
155 /**
156  * Merge the debug info due to a Phi optimization.
157  * A Phi node was replaced by one of its input (the only meaningful)
158  *
159  * @param phi  the Phi node that will be replaced
160  * @param n    in Phi Input that will replace Phi
161  */
162 #define DBG_OPT_PHI(phi, n)                                     \
163   do {                                                          \
164           hook_merge_nodes(&n, 1, &phi, 1, HOOK_OPT_PHI);                   \
165           __dbg_info_merge_sets(&n, 1, &phi, 1, dbg_opt_ssa);         \
166   } while(0)
167
168
169 /**
170  * Merge the debug info due to a Sync optimization.
171  * A Sync node was replaced by one of its input (the only meaningful)
172  *
173  * @param sync  the Sync node that will be replaced
174  * @param n     in Sync Input that will replace Sync
175  */
176 #define DBG_OPT_SYNC(sync, n)                                   \
177   do {                                                          \
178           hook_merge_nodes(&n, 1, &sync, 1, HOOK_OPT_SYNC);               \
179           __dbg_info_merge_sets(&n, 1, &sync, 1, dbg_opt_ssa);        \
180   } while(0)
181
182
183 /**
184  * Merge the debug info due to Write-after-Write optimization:
185  * Store oldst will be removed, because Store st overwrites it.
186  *
187  * @param oldst  the old store that will be removed
188  * @param st     the other store that overwrites oldst
189  */
190 #define DBG_OPT_WAW(oldst, st)                                  \
191   do {                                                          \
192           ir_node *ons[2];                                            \
193           ons[0] = oldst;                                             \
194           ons[1] = st;                                                \
195           hook_merge_nodes(&st, 1, ons, SIZ(ons), HOOK_OPT_WAW);      \
196           __dbg_info_merge_sets(&st, 1, ons, SIZ(ons), dbg_write_after_write); \
197   } while(0)
198
199 /**
200  * Merge the debug info due to Write-after-Read optimization:
201  * A store will be removed because it rite a value just read back.
202  *
203  * @param store  the store that will be removed
204  * @param load   the load that produces the value that store will write back
205  */
206 #define DBG_OPT_WAR(store, load)                                \
207   do {                                                          \
208           ir_node *ons[2];                                            \
209           ons[0] = store;                                             \
210           ons[1] = load;                                              \
211           hook_merge_nodes(&load, 1, ons, SIZ(ons), HOOK_OPT_WAR);    \
212           __dbg_info_merge_sets(&load, 1, ons, SIZ(ons), dbg_write_after_read); \
213   } while(0)
214
215 /**
216  * Merge the debug info due to Read-after-Write optimization:
217  * A load will be replaced by a value that was just stored.
218  *
219  * @param load   the load that will be replaced
220  * @param value  the value that will replace the load
221  */
222 #define DBG_OPT_RAW(load, value)                                \
223   do {                                                          \
224           ir_node *ons[2];                                            \
225           ons[0] = load;                                              \
226           ons[1] = value;                                             \
227           hook_merge_nodes(&value, 1, ons, SIZ(ons), HOOK_OPT_RAW);   \
228           __dbg_info_merge_sets(&value, 1, ons, SIZ(ons), dbg_read_after_write); \
229   } while(0)
230
231 /**
232  * Merge the debug info due to Read-after-Read optimization:
233  * Load oldld will be replace by a reference to Load ld.
234  *
235  * @param oldld  the old load that can be replaced
236  * @param ld     the load that produces the same values
237  */
238 #define DBG_OPT_RAR(oldld, ld)                                  \
239   do {                                                          \
240           ir_node *ons[2];                                            \
241           ons[0] = oldld;                                             \
242           ons[1] = ld;                                                \
243           hook_merge_nodes(&ld, 1, ons, SIZ(ons), HOOK_OPT_RAR);      \
244           __dbg_info_merge_sets(&ld, 1, ons, SIZ(ons), dbg_read_after_read); \
245   } while(0)
246
247 /**
248  * Merge the debug info due to Read-a-Const optimization:
249  * Load ld will be replace by a Constant if the value that
250  * will be loaded is known and immutable.
251  *
252  * @param ld  the load
253  * @param c   the constant value that will replace the load's result
254  */
255 #define DBG_OPT_RC(ld, c)                                       \
256   do {                                                          \
257           ir_node *ons[2];                                            \
258           ons[0] = ld;                                                \
259           ons[1] = c;                                                 \
260           hook_merge_nodes(&c, 1, ons, SIZ(ons), HOOK_OPT_RC);        \
261           __dbg_info_merge_sets(&ld, 1, ons, SIZ(ons), dbg_read_a_const); \
262         } while(0)
263
264 /**
265  * Merge the debug info after a tuple optimization.
266  * a Proj(Tuple) is replaced by the associated tuple value.
267  *
268  * @param proj   the Proj node
269  * @param tuple  the Tuple node
270  * @param n      the Proj(Tuple) value
271  */
272 #define DBG_OPT_TUPLE(proj, tuple, n)                           \
273   do {                                                          \
274           ir_node *ons[3];                                            \
275           ons[0] = proj;                                              \
276           ons[1] = tuple;                                             \
277           ons[2] = n;                                                 \
278           hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_TUPLE);     \
279           __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_opt_auxnode);      \
280   } while(0)
281
282 /**
283  * Merge the debug info after an Id optimization.
284  * An Id node was replaced by its non-Id predecessor.
285  *
286  * @param id  the Id node
287  * @param n   the predecessor
288  */
289 #define DBG_OPT_ID(id, n)                                       \
290   do {                                                          \
291           ir_node *ons[2];                                            \
292           ons[0] = id;                                                \
293           ons[1] = n;                                                 \
294           hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_ID);        \
295           __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_opt_auxnode);      \
296   } while(0)
297
298 /**
299  * Merge the debug info due to common-subexpression elimination.
300  *
301  * @param oldn  the old node
302  * @param n     the node that replaces oldn
303  */
304 #define DBG_OPT_CSE(oldn, n)                                    \
305   do {                                                          \
306           ir_node *ons[2];                                            \
307           ons[0] = oldn;                                              \
308           ons[1] = n;                                                 \
309           hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_CSE);       \
310           __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_opt_cse);   \
311   } while(0)
312
313 /**
314  * Merge the debug info due to polymorphic call optimization.
315  * A Sel node was replaced by a constant.
316  *
317  * @param sel   the Sel node that will be replaced.
318  * @param c     the constant node that replaces sel
319  */
320 #define DBG_OPT_POLY(sel, c)                                        \
321   do {                                                              \
322     ir_node *ons[3];                                                \
323     ons[0] = sel;                                                   \
324     ons[1] = skip_Proj(get_Sel_ptr(sel));                           \
325     ons[2] = c;                                                     \
326     hook_merge_nodes(&c, 1, ons, SIZ(ons), HOOK_OPT_POLY_CALL);     \
327     __dbg_info_merge_sets(&c, 1, ons, SIZ(ons), dbg_rem_poly_call); \
328   } while(0)
329
330 /**
331  * A node was replaced by another node due to a Confirmation.
332  *
333  * @param oldn  the old node
334  * @param n     the new node
335  */
336 #define DBG_OPT_CONFIRM(oldn, n)                                \
337   do {                                                          \
338     hook_merge_nodes(&n, 1, &oldn, 1, HOOK_OPT_CONFIRM);        \
339     __dbg_info_merge_pair(n, oldn, dbg_opt_confirm);            \
340   } while(0)
341
342 /**
343  * A node was replaced by a constant due to a Confimation.
344  *
345  * @param oldn  the old node
346  * @param c     the new constant node
347  */
348 #define DBG_OPT_CONFIRM_C(oldn, c)                              \
349   do {                                                          \
350     hook_merge_nodes(&c, 1, &oldn, 1, HOOK_OPT_CONFIRM_C);      \
351     __dbg_info_merge_pair(c, oldn, dbg_opt_confirm);            \
352   } while(0)
353
354 /**
355  * A exception exdge was removed due to a Confirmation prove.
356  *
357  * @param oldn  the old node
358  */
359 #define DBG_OPT_EXC_REM(oldn)                                   \
360   do {                                                          \
361     hook_merge_nodes(NULL, 0, &oldn, 1, HOOK_OPT_EXC_REM);      \
362   } while(0)
363
364 /**
365  * A node could be evaluated to a value due to a Confirm.
366  * This will lead to a constant evaluation.
367  *
368  * @param n  the node that could be evaluated
369  */
370 #define DBG_EVAL_CONFIRM(n)                                  \
371   do {                                                       \
372     hook_merge_nodes(NULL, 0, &n, 1, HOOK_OPT_CONFIRM_E);    \
373   } while(0)
374
375 #endif /* _IROPT_DBG_H_ */