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