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