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