DBG_OPT_EXC_REM() added (a exception edge was removed due to a comfirmation prove)
[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 debuig 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 Write-after-Write optimization:
171  * Store oldst will be removed, because Store st overwrites it.
172  *
173  * @param oldst  the old store that will be removed
174  * @param st     the other store that overwrites oldst
175  */
176 #define DBG_OPT_WAW(oldst, st)                                  \
177   do {                                                          \
178           ir_node *ons[2];                                            \
179           ons[0] = oldst;                                             \
180           ons[1] = st;                                                \
181           hook_merge_nodes(&st, 1, ons, SIZ(ons), HOOK_OPT_WAW);      \
182           __dbg_info_merge_sets(&st, 1, ons, SIZ(ons), dbg_write_after_write); \
183   } while(0)
184
185 /**
186  * Merge the debug info due to Write-after-Read optimization:
187  * A store will be removed because it rite a value just read back.
188  *
189  * @param store  the store that will be removed
190  * @param load   the load that produces the value that store will write back
191  */
192 #define DBG_OPT_WAR(store, load)                                \
193   do {                                                          \
194           ir_node *ons[2];                                            \
195           ons[0] = store;                                             \
196           ons[1] = load;                                              \
197           hook_merge_nodes(&load, 1, ons, SIZ(ons), HOOK_OPT_WAR);    \
198           __dbg_info_merge_sets(&load, 1, ons, SIZ(ons), dbg_write_after_read); \
199   } while(0)
200
201 /**
202  * Merge the debug info due to Read-after-Write optimization:
203  * A load will be replaced by a value that was just stored.
204  *
205  * @param load   the load that will be replaced
206  * @param value  the value that will replace the load
207  */
208 #define DBG_OPT_RAW(load, value)                                \
209   do {                                                          \
210           ir_node *ons[2];                                            \
211           ons[0] = load;                                              \
212           ons[1] = value;                                             \
213           hook_merge_nodes(&value, 1, ons, SIZ(ons), HOOK_OPT_RAW);   \
214           __dbg_info_merge_sets(&value, 1, ons, SIZ(ons), dbg_read_after_write); \
215   } while(0)
216
217 /**
218  * Merge the debug info due to Read-after-Read optimization:
219  * Load oldld will be replace by a reference to Load ld.
220  *
221  * @param oldld  the old load that can be replaced
222  * @param ld     the load that produces the same values
223  */
224 #define DBG_OPT_RAR(oldld, ld)                                  \
225   do {                                                          \
226           ir_node *ons[2];                                            \
227           ons[0] = oldld;                                             \
228           ons[1] = ld;                                                \
229           hook_merge_nodes(&ld, 1, ons, SIZ(ons), HOOK_OPT_RAR);      \
230           __dbg_info_merge_sets(&ld, 1, ons, SIZ(ons), dbg_read_after_read); \
231   } while(0)
232
233 /**
234  * Merge the debug info due to Read-a-Const optimization:
235  * Load ld will be replace by a Constant if the value that
236  * will be loaded is known and immutable.
237  *
238  * @param ld  the load
239  * @param c   the constant value that will replace the load's result
240  */
241 #define DBG_OPT_RC(ld, c)                                       \
242   do {                                                          \
243           ir_node *ons[2];                                            \
244           ons[0] = ld;                                                \
245           ons[1] = c;                                                 \
246           hook_merge_nodes(&c, 1, ons, SIZ(ons), HOOK_OPT_RC);        \
247           __dbg_info_merge_sets(&ld, 1, ons, SIZ(ons), dbg_read_a_const); \
248         } while(0)
249
250 /**
251  * Merge the debug info after a tuple optimization.
252  * a Proj(Tuple) is replaced by the associated tuple value.
253  *
254  * @param proj   the Proj node
255  * @param tuple  the Tuple node
256  * @param n      the Proj(Tuple) value
257  */
258 #define DBG_OPT_TUPLE(proj, tuple, n)                           \
259   do {                                                          \
260           ir_node *ons[3];                                            \
261           ons[0] = proj;                                              \
262           ons[1] = tuple;                                             \
263           ons[2] = n;                                                 \
264           hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_TUPLE);     \
265           __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_opt_auxnode);      \
266   } while(0)
267
268 /**
269  * Merge the debug info after an Id optimization.
270  * An Id node was replaced by its non-Id predecessor.
271  *
272  * @param id  the Id node
273  * @param n   the predecessor
274  */
275 #define DBG_OPT_ID(id, n)                                       \
276   do {                                                          \
277           ir_node *ons[2];                                            \
278           ons[0] = id;                                                \
279           ons[1] = n;                                                 \
280           hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_ID);        \
281           __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_opt_auxnode);      \
282   } while(0)
283
284 /**
285  * Merge the debug info due to common-subexpression elimination.
286  *
287  * @param oldn  the old node
288  * @param n     the node that replaces oldn
289  */
290 #define DBG_OPT_CSE(oldn, n)                                    \
291   do {                                                          \
292           ir_node *ons[2];                                            \
293           ons[0] = oldn;                                              \
294           ons[1] = n;                                                 \
295           hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_CSE);       \
296           __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_opt_cse);   \
297   } while(0)
298
299 /**
300  * Merge the debug info due to polymorphic call optimization.
301  * A Sel node was replaced by a constant.
302  *
303  * @param sel   the Sel node that will be replaced.
304  * @param c     the constant node that replaces sel
305  */
306 #define DBG_OPT_POLY(sel, c)                                        \
307   do {                                                              \
308     ir_node *ons[3];                                                \
309     ons[0] = sel;                                                   \
310     ons[1] = skip_Proj(get_Sel_ptr(sel));                           \
311     ons[2] = c;                                                     \
312     hook_merge_nodes(&c, 1, ons, SIZ(ons), HOOK_OPT_POLY_CALL);     \
313     __dbg_info_merge_sets(&c, 1, ons, SIZ(ons), dbg_rem_poly_call); \
314   } while(0)
315
316 /**
317  * A node was replaced by another node due to a Confirmation.
318  *
319  * @param oldn  the old node
320  * @param n     the new node
321  */
322 #define DBG_OPT_CONFIRM(oldn, n)                                \
323   do {                                                          \
324     hook_merge_nodes(&n, 1, &oldn, 1, HOOK_OPT_CONFIRM);        \
325     __dbg_info_merge_pair(n, oldn, dbg_opt_confirm);            \
326   } while(0)
327
328 /**
329  * A node was replaced by a constant due to a Confimation.
330  *
331  * @param oldn  the old node
332  * @param c     the new constant node
333  */
334 #define DBG_OPT_CONFIRM_C(oldn, c)                              \
335   do {                                                          \
336     hook_merge_nodes(&c, 1, &oldn, 1, HOOK_OPT_CONFIRM_C);      \
337     __dbg_info_merge_pair(c, oldn, dbg_opt_confirm);            \
338   } while(0)
339
340 /**
341  * A exception exdge was removed due to a Confirmation prove.
342  *
343  * @param oldn  the old node
344  */
345 #define DBG_OPT_EXC_REM(oldn)                                   \
346   do {                                                          \
347     hook_merge_nodes(NULL, 0, &oldn, 1, HOOK_OPT_EXC_REM);      \
348   } while(0)
349
350 /**
351  * A node could be evaluated to a value due to a Confirm.
352  * This will lead to a constant evaluation.
353  *
354  * @param n  the node that could be evaluated
355  */
356 #define DBG_EVAL_CONFIRM(n)                                  \
357   do {                                                       \
358     hook_merge_nodes(NULL, 0, &n, 1, HOOK_OPT_CONFIRM_E);    \
359   } while(0)
360
361 #endif /* _IROPT_DBG_H_ */