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