more
[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
19 /* This file contains makros that generate the calls to
20    update the debug information after a transformation. */
21
22 #define SIZ(x)    sizeof(x)/sizeof((x)[0])
23
24
25 /**
26  * Merge the debug info due to dead code elimination
27  */
28 #define DBG_OPT_DEAD(oldn, n)                                      \
29   do {                                                             \
30           ir_node *ons[2];                                         \
31           ons[0] = oldn;                                           \
32           ons[1] = get_Block_cfgpred(oldn, 0);                     \
33           hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_STG);    \
34           __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_dead_code); \
35         } while(0)
36
37
38 /**
39  * Merge the debug info due to a straightening optimization
40  */
41 #define DBG_OPT_STG(oldn, n)                                       \
42   do {                                                             \
43           ir_node *ons[2];                                         \
44           ons[0] = oldn;                                           \
45           ons[1] = get_Block_cfgpred(oldn, 0);                     \
46           hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_STG);    \
47           __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_straightening); \
48         } while(0)
49
50 /**
51  * Merge the debug info due to an if simplification
52  */
53 #define DBG_OPT_IFSIM(oldn, a, b, n)                                  \
54   do {                                                                \
55           ir_node *ons[4];                                            \
56           ons[0] = oldn;                                              \
57           ons[1] = a;                                                 \
58           ons[2] = b;                                                 \
59           ons[3] = get_Proj_pred(a);                                  \
60           hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_IFSIM);     \
61           __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_if_simplification); \
62         } while(0)
63
64 /**
65  * Merge the debug info due to an algebraic_simplification
66  */
67 #define DBG_OPT_CSTEVAL(oldn, n)                                  \
68   do {                                                                  \
69           hook_merge_nodes(&n, 1, &oldn, 1, HOOK_OPT_CONST_EVAL);         \
70           __dbg_info_merge_pair(n, oldn, dbg_const_eval);               \
71   } while(0)
72
73 #define DBG_OPT_ALGSIM0(oldn, n)                                  \
74   do {                                                            \
75     hook_merge_nodes(&n, 1, &oldn, 1, HOOK_OPT_ALGSIM);               \
76     __dbg_info_merge_pair(n, oldn, dbg_algebraic_simplification); \
77   } while(0)
78
79 #define DBG_OPT_ALGSIM1(oldn, a, b, n)                          \
80   do {                                                          \
81           ir_node *ons[3];                                            \
82           ons[0] = oldn;                                              \
83           ons[1] = a;                                                 \
84           ons[2] = b;                                                 \
85           hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_ALGSIM);    \
86           __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_algebraic_simplification); \
87   } while(0)
88
89 #define DBG_OPT_ALGSIM2(oldn, pred, n)                                \
90   do {                                                                \
91           ir_node *ons[3];                                            \
92           ons[0] = oldn;                                              \
93           ons[1] = pred;                                              \
94           ons[2] = n;                                                 \
95           hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_ALGSIM);    \
96           __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_algebraic_simplification); \
97   } while(0)
98
99 #define DBG_OPT_ALGSIM3(oldn, a, n)                                   \
100   do {                                                                \
101           ir_node *ons[2];                                            \
102           ons[0] = oldn;                                              \
103           ons[1] = a;                                                 \
104           hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_ALGSIM);    \
105           __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_algebraic_simplification); \
106   } while(0)
107
108 #define DBG_OPT_PHI(oldn, first_val, n)                               \
109   do {                                                                \
110           ir_node *ons[2];                                            \
111           ons[0] = oldn;                                              \
112           ons[1] = first_val;                                         \
113           hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_PHI);       \
114           __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_opt_ssa);   \
115   } while(0)
116
117
118 /**
119  * Merge the debug info due to Write-after-Write optimization:
120  * Store oldst will be replace by a reference to Store st
121  */
122 #define DBG_OPT_WAW(oldst, st)                                        \
123   do {                                                                \
124           ir_node *ons[2];                                            \
125           ons[0] = oldst;                                             \
126           ons[1] = st;                                                \
127           hook_merge_nodes(&st, 1, ons, SIZ(ons), HOOK_OPT_WAW);      \
128           __dbg_info_merge_sets(&st, 1, ons, SIZ(ons), dbg_write_after_write); \
129   } while(0)
130
131 /**
132  * Merge the debug info due to Write-after-Read optimization:
133  * store will be replace by a reference to load
134  */
135 #define DBG_OPT_WAR(store, load)                                      \
136   do {                                                                \
137           ir_node *ons[2];                                            \
138           ons[0] = store;                                             \
139           ons[1] = load;                                              \
140           hook_merge_nodes(&load, 1, ons, SIZ(ons), HOOK_OPT_WAR);    \
141           __dbg_info_merge_sets(&load, 1, ons, SIZ(ons), dbg_write_after_read); \
142   } while(0)
143
144 /**
145  * Merge the debug info due to Read-after-Write optimization:
146  * load will be replace by a reference to store
147  */
148 #define DBG_OPT_RAW(store, load)                                      \
149   do {                                                                \
150           ir_node *ons[2];                                            \
151           ons[0] = store;                                             \
152           ons[1] = load;                                              \
153           hook_merge_nodes(&store, 1, ons, SIZ(ons), HOOK_OPT_RAW);   \
154           __dbg_info_merge_sets(&store, 1, ons, SIZ(ons), dbg_read_after_write); \
155   } while(0)
156
157 /**
158  * Merge the debug info due to Read-after-Read optimization:
159  * Load oldld will be replace by a reference to Load ld
160  */
161 #define DBG_OPT_RAR(oldld, ld)                                        \
162   do {                                                                \
163           ir_node *ons[2];                                            \
164           ons[0] = oldld;                                             \
165           ons[1] = ld;                                                \
166           hook_merge_nodes(&ld, 1, ons, SIZ(ons), HOOK_OPT_RAR);      \
167           __dbg_info_merge_sets(&ld, 1, ons, SIZ(ons), dbg_read_after_read); \
168   } while(0)
169
170 /**
171  * Merge the debug info due to Read-a-Const optimization:
172  * Load ld will be replace by a Constant
173  */
174 #define DBG_OPT_RC(ld, c)                                             \
175   do {                                                                \
176           ir_node *ons[2];                                            \
177           ons[0] = ld;                                                \
178           ons[1] = c;                                                 \
179           hook_merge_nodes(&c, 1, ons, SIZ(ons), HOOK_OPT_RC);        \
180           __dbg_info_merge_sets(&ld, 1, ons, SIZ(ons), dbg_read_a_const); \
181         } while(0)
182
183 #define DBG_OPT_TUPLE(oldn, a, n)                                     \
184   do {                                                                \
185           ir_node *ons[3];                                            \
186           ons[0] = oldn;                                              \
187           ons[1] = a;                                                 \
188           ons[2] = n;                                                 \
189           hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_TUPLE);     \
190           __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_opt_auxnode);      \
191   } while(0)
192
193 #define DBG_OPT_ID(oldn, n)                                           \
194   do {                                                                \
195           ir_node *ons[2];                                            \
196           ons[0] = oldn;                                              \
197           ons[1] = n;                                                 \
198           hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_ID);        \
199           __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_opt_auxnode);      \
200   } while(0)
201
202 /**
203  * Merge the debug info due to ommon-subexpression elimination
204  */
205 #define DBG_OPT_CSE(oldn, n)                                          \
206   do {                                                                \
207           ir_node *ons[2];                                            \
208           ons[0] = oldn;                                              \
209           ons[1] = n;                                                 \
210           hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_CSE);       \
211           __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_opt_cse);   \
212   } while(0)
213
214 #define DBG_OPT_POLY_ALLOC(oldn, n)                                 \
215   do {                                                              \
216     ir_node *ons[3];                                                \
217     ons[0] = oldn;                                                  \
218     ons[1] = skip_Proj(get_Sel_ptr(oldn));                          \
219     ons[2] = n;                                                     \
220     hook_merge_nodes(&n, 1, ons, SIZ(ons), HOOK_OPT_POLY_CALL);     \
221     __dbg_info_merge_sets(&n, 1, ons, SIZ(ons), dbg_rem_poly_call); \
222   } while(0)
223
224 #define DBG_OPT_POLY(oldn, n)                                   \
225   do {                                                          \
226     hook_merge_nodes(&n, 1, &oldn, 1, HOOK_OPT_POLY_CALL);      \
227     __dbg_info_merge_pair(n, oldn, dbg_rem_poly_call);          \
228   } while(0)
229
230 #endif /* _IROPT_DBG_H_ */