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