summaryrefslogtreecommitdiffhomepage
path: root/ir/opt/iropt_dbg.h
blob: fcab9bd88c2d59983923e3e784eade1cf040b3e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
/*
 * This file is part of libFirm.
 * Copyright (C) 2012 University of Karlsruhe.
 */

/**
 * @file
 * @brief   Debug macros used in iropt.
 * @author  Goetz Lindenmaier, Michael Beck
 */
#ifndef FIRM_IR_IROPT_DBG_H
#define FIRM_IR_IROPT_DBG_H

#include "dbginfo_t.h"
#include "irhooks.h"
#include "util.h"

/**
 * Merge the debug info due to dead block elimination.
 *
 * @param oldn  the block that it is eliminated
 * @param n     the new node for this block, may be equal to oldn
 */
#define DBG_OPT_DEAD_BLOCK(oldn, n)                           \
	do {                                                      \
	  __dbg_info_merge_pair(n, oldn, dbg_dead_code);          \
	} while(0)


/**
 * Merge the debug info due to a straightening optimization.
 * Block oldn is merged with n.
 *
 * @param oldn  the old block
 * @param n     the new block the merges with oldn
 */
#define DBG_OPT_STG(oldn, n)                                                 \
	do {                                                                     \
	  ir_node *ons[2];                                                       \
	  ons[0] = oldn;                                                         \
	  ons[1] = get_Block_cfgpred(oldn, 0);                                   \
	  __dbg_info_merge_sets(&n, 1, ons, ARRAY_SIZE(ons), dbg_straightening); \
	} while(0)

/**
 * Merge the debug info due to an if simplification.
 *
 * @param oldn   the old Block
 * @param proj1  the first ProjX predecessor
 * @param proj2  the second ProjX predecessor
 * @param n      the new Block
 */
#define DBG_OPT_IFSIM1(oldn, proj1, proj2, n)                        \
	do {                                                             \
	  ir_node *ons[4];                                               \
	  ons[0] = oldn;                                                 \
	  ons[1] = proj1;                                                \
	  ons[2] = proj2;                                                \
	  ons[3] = get_Proj_pred(proj1);                                 \
	  __dbg_info_merge_sets(&n, 1, ons, ARRAY_SIZE(ons), dbg_if_simplification); \
	} while(0)

/**
 * Merge the debug info due to an if simplification.
 * @param oldn   the old Cond
 * @param n      the new Jmp
 */
#define DBG_OPT_IFSIM2(oldn, n)                              \
	do {                                                     \
	  __dbg_info_merge_pair(n, oldn, dbg_if_simplification); \
	} while(0)

/**
 * Merge the debug info due to an algebraic_simplification.
 * A node could be evaluated into a Constant.
 *
 * @param oldn  the node
 * @param n     the new constant holding the value
 */
#define DBG_OPT_CSTEVAL(oldn, n)                                  \
	do {                                                          \
	  __dbg_info_merge_pair(n, oldn, dbg_const_eval);             \
	} while(0)

/**
 * Merge the debug info due to an algebraic_simplification.
 *
 * @param oldn  the old node
 * @param n     the new node replacing oldn
 */
#define DBG_OPT_ALGSIM0(oldn, n)                                    \
	do {                                                            \
	  __dbg_info_merge_pair(n, oldn, dbg_algebraic_simplification); \
	} while(0)

/**
 * Merge the debug info due to an algebraic_simplification.
 *
 * @param oldn  the old node
 * @param a     a predecessor of oldn
 * @param b     a predecessor of oldn
 * @param n     the new node replacing oldn
 */
#define DBG_OPT_ALGSIM1(oldn, a, b, n)                            \
	do {                                                          \
	  ir_node *ons[3];                                            \
	  ons[0] = oldn;                                              \
	  ons[1] = a;                                                 \
	  ons[2] = b;                                                 \
	  __dbg_info_merge_sets(&n, 1, ons, ARRAY_SIZE(ons), dbg_algebraic_simplification); \
	} while(0)

/**
 * Merge the debug info due to an algebraic_simplification.
 *
 * @param oldn  the old node
 * @param pred  the predecessor of oldn
 * @param n     the new node replacing oldn
 */
#define DBG_OPT_ALGSIM2(oldn, pred, n)                            \
	do {                                                          \
	  ir_node *ons[3];                                            \
	  ons[0] = oldn;                                              \
	  ons[1] = pred;                                              \
	  ons[2] = n;                                                 \
	  __dbg_info_merge_sets(&n, 1, ons, ARRAY_SIZE(ons), dbg_algebraic_simplification); \
	} while(0)

/**
 * Merge the debug info due to an algebraic_simplification.
 */
#define DBG_OPT_ALGSIM3(oldn, a, n)                               \
	do {                                                          \
	  ir_node *ons[2];                                            \
	  ons[0] = oldn;                                              \
	  ons[1] = a;                                                 \
	  __dbg_info_merge_sets(&n, 1, ons, ARRAY_SIZE(ons), dbg_algebraic_simplification); \
	} while(0)

/**
 * Merge the debug info due to a Phi optimization.
 * A Phi node was replaced by one of its input (the only meaningful)
 *
 * @param phi  the Phi node that will be replaced
 * @param n    in Phi Input that will replace Phi
 */
#define DBG_OPT_PHI(phi, n)                                      \
	do {                                                         \
	  __dbg_info_merge_sets(&n, 1, &phi, 1, dbg_opt_ssa);        \
	} while(0)


/**
 * Merge the debug info due to a Sync optimization.
 * A Sync node was replaced by one of its input (the only meaningful)
 *
 * @param sync  the Sync node that will be replaced
 * @param n     in Sync Input that will replace Sync
 */
#define DBG_OPT_SYNC(sync, n)                                     \
	do {                                                          \
	  __dbg_info_merge_sets(&n, 1, &sync, 1, dbg_opt_ssa);        \
	} while(0)


/**
 * Merge the debug info due to Write-after-Write optimization:
 * Store oldst will be removed, because Store st overwrites it.
 *
 * @param oldst  the old store that will be removed
 * @param st     the other store that overwrites oldst
 */
#define DBG_OPT_WAW(oldst, st)                                      \
	do {                                                            \
	  ir_node *ons[2];                                              \
	  ons[0] = oldst;                                               \
	  ons[1] = st;                                                  \
	  __dbg_info_merge_sets(&st, 1, ons, ARRAY_SIZE(ons), dbg_write_after_write); \
	} while(0)

/**
 * Merge the debug info due to Write-after-Read optimization:
 * A store will be removed because it rite a value just read back.
 *
 * @param store  the store that will be removed
 * @param load   the load that produces the value that store will write back
 */
#define DBG_OPT_WAR(store, load)                                      \
	do {                                                              \
	  ir_node *ons[2];                                                \
	  ons[0] = store;                                                 \
	  ons[1] = load;                                                  \
	  __dbg_info_merge_sets(&load, 1, ons, ARRAY_SIZE(ons), dbg_write_after_read); \
	} while(0)

/**
 * Merge the debug info due to Read-after-Write optimization:
 * A load will be replaced by a value that was just stored.
 *
 * @param load   the load that will be replaced
 * @param value  the value that will replace the load
 */
#define DBG_OPT_RAW(load, value)                                       \
	do {                                                               \
	  ir_node *ons[2];                                                 \
	  ons[0] = load;                                                   \
	  ons[1] = value;                                                  \
	  __dbg_info_merge_sets(&value, 1, ons, ARRAY_SIZE(ons), dbg_read_after_write); \
	} while(0)

/**
 * Merge the debug info due to Read-after-Read optimization:
 * Load oldld will be replace by a reference to Load ld.
 *
 * @param oldld  the old load that can be replaced
 * @param ld     the load that produces the same values
 */
#define DBG_OPT_RAR(oldld, ld)                                      \
	do {                                                            \
	  ir_node *ons[2];                                              \
	  ons[0] = oldld;                                               \
	  ons[1] = ld;                                                  \
	  __dbg_info_merge_sets(&ld, 1, ons, ARRAY_SIZE(ons), dbg_read_after_read); \
	} while(0)

/**
 * Merge the debug info due to Read-a-Const optimization:
 * Load ld will be replace by a Constant if the value that
 * will be loaded is known and immutable.
 *
 * @param ld  the load
 * @param c   the constant value that will replace the load's result
 */
#define DBG_OPT_RC(ld, c)                                         \
	do {                                                          \
	  ir_node *ons[2];                                            \
	  ons[0] = ld;                                                \
	  ons[1] = c;                                                 \
	  __dbg_info_merge_sets(&ld, 1, ons, ARRAY_SIZE(ons), dbg_read_a_const); \
	} while(0)

/**
 * Merge the debug info after a tuple optimization.
 * a Proj(Tuple) is replaced by the associated tuple value.
 *
 * @param proj   the Proj node
 * @param tuple  the Tuple node
 * @param n      the Proj(Tuple) value
 */
#define DBG_OPT_TUPLE(proj, tuple, n)                                      \
	do {                                                                   \
	  ir_node *ons[3];                                                     \
	  ons[0] = proj;                                                       \
	  ons[1] = tuple;                                                      \
	  ons[2] = n;                                                          \
	  __dbg_info_merge_sets(&n, 1, ons, ARRAY_SIZE(ons), dbg_opt_auxnode); \
	} while(0)

/**
 * Merge the debug info after an Id optimization.
 * An Id node was replaced by its non-Id predecessor.
 *
 * @param id  the Id node
 * @param n   the predecessor
 */
#define DBG_OPT_ID(id, n)                                                  \
	do {                                                                   \
	  ir_node *ons[2];                                                     \
	  ons[0] = id;                                                         \
	  ons[1] = n;                                                          \
	  __dbg_info_merge_sets(&n, 1, ons, ARRAY_SIZE(ons), dbg_opt_auxnode); \
	} while(0)

/**
 * Merge the debug info due to common-subexpression elimination.
 *
 * @param oldn  the old node
 * @param n     the node that replaces oldn
 */
#define DBG_OPT_CSE(oldn, n)                                           \
	do {                                                               \
	  ir_node *ons[2];                                                 \
	  ons[0] = oldn;                                                   \
	  ons[1] = n;                                                      \
	  __dbg_info_merge_sets(&n, 1, ons, ARRAY_SIZE(ons), dbg_opt_cse); \
	} while(0)

/**
 * A node was replaced by another node due to a Confirmation.
 *
 * @param oldn  the old node
 * @param n     the new node
 */
#define DBG_OPT_CONFIRM(oldn, n)                                  \
	do {                                                          \
	  __dbg_info_merge_pair(n, oldn, dbg_opt_confirm);            \
	} while(0)

/**
 * A node was replaced by a constant due to a Confimation.
 *
 * @param oldn  the old node
 * @param c     the new constant node
 */
#define DBG_OPT_CONFIRM_C(oldn, c)                                \
	do {                                                          \
	  __dbg_info_merge_pair(c, oldn, dbg_opt_confirm);            \
	} while(0)

/**
 * Merge the debug info due to a GVN-PRE result.
 *
 * @param oldn  the old node
 * @param n     the new node replacing oldn
 */
#define DBG_OPT_GVN_PRE(oldn, n)                              \
	do {                                                      \
	  __dbg_info_merge_pair(n, oldn, dbg_gvn_pre);            \
	} while(0)

/**
 * Merge the debug info due to a combo result.
 *
 * @param oldn  the old node
 * @param n     the new node replacing oldn
 */
#define DBG_OPT_COMBO(oldn, n)                                \
	do {                                                      \
	  __dbg_info_merge_pair(n, oldn, dbg_combo);              \
	} while(0)

/**
 * Merge the debug info due to a jump threading result.
 *
 * @param oldn  the old control flow node
 * @param n     the new control flow node replacing oldn
 */
#define DBG_OPT_JUMPTHREADING(oldn, n)                         \
	do {                                                   \
	  __dbg_info_merge_pair(n, oldn, dbg_jumpthreading);       \
	} while(0)

#endif