iropt_dbg.h 16.6 KB
Newer Older
Christian Würdig's avatar
Christian Würdig committed
1
/*
Michael Beck's avatar
Michael Beck committed
2
 * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
Christian Würdig's avatar
Christian Würdig committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 *
 * This file is part of libFirm.
 *
 * This file may be distributed and/or modified under the terms of the
 * GNU General Public License version 2 as published by the Free Software
 * Foundation and appearing in the file LICENSE.GPL included in the
 * packaging of this file.
 *
 * Licensees holding valid libFirm Professional Edition licenses may use
 * this file in accordance with the libFirm Commercial License.
 * Agreement provided with the Software.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE.
 */

Matthias Braun's avatar
Matthias Braun committed
20
21
/**
 * @file
Michael Beck's avatar
Michael Beck committed
22
23
 * @brief   Debug macros used in iropt.
 * @author  Goetz Lindenmaier, Michael Beck
Matthias Braun's avatar
Matthias Braun committed
24
 * @version $Id$
Götz Lindenmaier's avatar
Götz Lindenmaier committed
25
 */
Matthias Braun's avatar
Matthias Braun committed
26
27
#ifndef FIRM_IR_IROPT_DBG_H
#define FIRM_IR_IROPT_DBG_H
28
29
30

#include "dbginfo_t.h"
#include "irhooks.h"
Michael Beck's avatar
Michael Beck committed
31
#include "firmstat.h"
32
#include "util.h"
33

34
/**
Michael Beck's avatar
Michael Beck committed
35
36
37
38
 * 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
39
 */
Michael Beck's avatar
Michael Beck committed
40
41
42
43
#define DBG_OPT_DEAD_BLOCK(oldn, n)                           \
	do {                                                      \
	  hook_merge_nodes(&n, 1, &oldn, 1, HOOK_OPT_DEAD_BLOCK); \
	  __dbg_info_merge_pair(n, oldn, dbg_dead_code);          \
44
45
46
	} while(0)


Michael Beck's avatar
Michael Beck committed
47
/**
Michael Beck's avatar
Michael Beck committed
48
49
50
51
52
 * 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
Michael Beck's avatar
Michael Beck committed
53
 */
54
55
56
57
58
59
60
#define DBG_OPT_STG(oldn, n)                                                 \
	do {                                                                     \
	  ir_node *ons[2];                                                       \
	  ons[0] = oldn;                                                         \
	  ons[1] = get_Block_cfgpred(oldn, 0);                                   \
	  hook_merge_nodes(&n, 1, ons, ARRAY_SIZE(ons), HOOK_OPT_STG);           \
	  __dbg_info_merge_sets(&n, 1, ons, ARRAY_SIZE(ons), dbg_straightening); \
Michael Beck's avatar
Michael Beck committed
61
	} while(0)
62

Michael Beck's avatar
Michael Beck committed
63
/**
Michael Beck's avatar
Michael Beck committed
64
65
66
67
68
69
 * 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
Michael Beck's avatar
Michael Beck committed
70
 */
71
72
73
74
75
76
77
78
79
#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);                                 \
	  hook_merge_nodes(&n, 1, ons, ARRAY_SIZE(ons), HOOK_OPT_IFSIM); \
	  __dbg_info_merge_sets(&n, 1, ons, ARRAY_SIZE(ons), dbg_if_simplification); \
Michael Beck's avatar
Michael Beck committed
80
	} while(0)
81

Michael Beck's avatar
Michael Beck committed
82
/**
Michael Beck's avatar
Michael Beck committed
83
84
85
86
 * Merge the debug info due to an if simplification.
 * @param oldn   the old Cond
 * @param n      the new Jmp
 */
Michael Beck's avatar
Michael Beck committed
87
88
#define DBG_OPT_IFSIM2(oldn, n)                              \
	do {                                                     \
Michael Beck's avatar
Michael Beck committed
89
90
91
92
93
94
	  hook_merge_nodes(&n, 1, &oldn, 1, HOOK_OPT_IFSIM);     \
	  __dbg_info_merge_pair(n, oldn, dbg_if_simplification); \
	} while(0)

/**
 * Merge the debug info due to an algebraic_simplification.
95
 * A node could be evaluated into a Constant.
Michael Beck's avatar
Michael Beck committed
96
97
98
 *
 * @param oldn  the node
 * @param n     the new constant holding the value
Michael Beck's avatar
Michael Beck committed
99
 */
Michael Beck's avatar
Michael Beck committed
100
#define DBG_OPT_CSTEVAL(oldn, n)                                  \
Michael Beck's avatar
Michael Beck committed
101
102
103
104
	do {                                                          \
	  hook_merge_nodes(&n, 1, &oldn, 1, HOOK_OPT_CONST_EVAL);     \
	  __dbg_info_merge_pair(n, oldn, dbg_const_eval);             \
	} while(0)
105

Michael Beck's avatar
Michael Beck committed
106
107
108
109
110
111
112
/**
 * Merge the debug info due to an algebraic_simplification.
 *
 * @param oldn  the old node
 * @param n     the new node replacing oldn
 * @param flag  firm statistics option
 */
Michael Beck's avatar
Michael Beck committed
113
114
115
116
117
#define DBG_OPT_ALGSIM0(oldn, n, flag)                              \
	do {                                                            \
	  hook_merge_nodes(&n, 1, &oldn, 1, flag);                      \
	  __dbg_info_merge_pair(n, oldn, dbg_algebraic_simplification); \
	} while(0)
Michael Beck's avatar
Michael Beck committed
118

Michael Beck's avatar
Michael Beck committed
119
120
121
122
123
124
125
126
127
/**
 * 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
 * @param flag  firm statistics option
 */
Michael Beck's avatar
Michael Beck committed
128
129
#define DBG_OPT_ALGSIM1(oldn, a, b, n, flag)                      \
	do {                                                          \
130
131
132
133
	  ir_node *ons[3];                                            \
	  ons[0] = oldn;                                              \
	  ons[1] = a;                                                 \
	  ons[2] = b;                                                 \
134
135
	  hook_merge_nodes(&n, 1, ons, ARRAY_SIZE(ons), flag);        \
	  __dbg_info_merge_sets(&n, 1, ons, ARRAY_SIZE(ons), dbg_algebraic_simplification); \
Michael Beck's avatar
Michael Beck committed
136
	} while(0)
137

Michael Beck's avatar
Michael Beck committed
138
139
/**
 * Merge the debug info due to an algebraic_simplification.
Michael Beck's avatar
Michael Beck committed
140
141
142
143
144
 *
 * @param oldn  the old node
 * @param pred  the predecessor of oldn
 * @param n     the new node replacing oldn
 * @param flag  firm statistics option
Michael Beck's avatar
Michael Beck committed
145
 */
Michael Beck's avatar
Michael Beck committed
146
147
#define DBG_OPT_ALGSIM2(oldn, pred, n, flag)                      \
	do {                                                          \
148
149
	  ir_node *ons[3];                                            \
	  ons[0] = oldn;                                              \
150
	  ons[1] = pred;                                              \
Michael Beck's avatar
Michael Beck committed
151
	  ons[2] = n;                                                 \
152
153
	  hook_merge_nodes(&n, 1, ons, ARRAY_SIZE(ons), flag);        \
	  __dbg_info_merge_sets(&n, 1, ons, ARRAY_SIZE(ons), dbg_algebraic_simplification); \
Michael Beck's avatar
Michael Beck committed
154
	} while(0)
155

Michael Beck's avatar
Michael Beck committed
156
157
158
/**
 * Merge the debug info due to an algebraic_simplification.
 */
159
#define DBG_OPT_ALGSIM3(oldn, a, n, flag)                         \
Michael Beck's avatar
Michael Beck committed
160
	do {                                                          \
161
162
163
	  ir_node *ons[2];                                            \
	  ons[0] = oldn;                                              \
	  ons[1] = a;                                                 \
164
165
	  hook_merge_nodes(&n, 1, ons, ARRAY_SIZE(ons), flag);        \
	  __dbg_info_merge_sets(&n, 1, ons, ARRAY_SIZE(ons), dbg_algebraic_simplification); \
Michael Beck's avatar
Michael Beck committed
166
	} while(0)
167

Michael Beck's avatar
Michael Beck committed
168
/**
Michael Beck's avatar
Michael Beck committed
169
 * Merge the debug info due to a Phi optimization.
Michael Beck's avatar
Michael Beck committed
170
171
172
173
174
 * 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
 */
Michael Beck's avatar
Michael Beck committed
175
176
177
178
179
#define DBG_OPT_PHI(phi, n)                                      \
	do {                                                         \
	  hook_merge_nodes(&n, 1, &phi, 1, HOOK_OPT_PHI);            \
	  __dbg_info_merge_sets(&n, 1, &phi, 1, dbg_opt_ssa);        \
	} while(0)
180
181


Michael Beck's avatar
Michael Beck committed
182
183
184
185
186
187
188
/**
 * 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
 */
Michael Beck's avatar
Michael Beck committed
189
190
191
#define DBG_OPT_SYNC(sync, n)                                     \
	do {                                                          \
	  hook_merge_nodes(&n, 1, &sync, 1, HOOK_OPT_SYNC);           \
Michael Beck's avatar
Michael Beck committed
192
	  __dbg_info_merge_sets(&n, 1, &sync, 1, dbg_opt_ssa);        \
Michael Beck's avatar
Michael Beck committed
193
	} while(0)
Michael Beck's avatar
Michael Beck committed
194
195


196
197
/**
 * Merge the debug info due to Write-after-Write optimization:
Michael Beck's avatar
Michael Beck committed
198
199
200
201
 * 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
202
 */
203
204
205
206
207
208
209
#define DBG_OPT_WAW(oldst, st)                                      \
	do {                                                            \
	  ir_node *ons[2];                                              \
	  ons[0] = oldst;                                               \
	  ons[1] = st;                                                  \
	  hook_merge_nodes(&st, 1, ons, ARRAY_SIZE(ons), HOOK_OPT_WAW); \
	  __dbg_info_merge_sets(&st, 1, ons, ARRAY_SIZE(ons), dbg_write_after_write); \
Michael Beck's avatar
Michael Beck committed
210
	} while(0)
211

212
213
/**
 * Merge the debug info due to Write-after-Read optimization:
Michael Beck's avatar
Michael Beck committed
214
215
216
217
 * 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
218
 */
219
220
221
222
223
224
225
#define DBG_OPT_WAR(store, load)                                      \
	do {                                                              \
	  ir_node *ons[2];                                                \
	  ons[0] = store;                                                 \
	  ons[1] = load;                                                  \
	  hook_merge_nodes(&load, 1, ons, ARRAY_SIZE(ons), HOOK_OPT_WAR); \
	  __dbg_info_merge_sets(&load, 1, ons, ARRAY_SIZE(ons), dbg_write_after_read); \
Michael Beck's avatar
Michael Beck committed
226
	} while(0)
227

228
229
/**
 * Merge the debug info due to Read-after-Write optimization:
Michael Beck's avatar
Michael Beck committed
230
231
232
233
 * 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
234
 */
235
236
237
238
239
240
241
#define DBG_OPT_RAW(load, value)                                       \
	do {                                                               \
	  ir_node *ons[2];                                                 \
	  ons[0] = load;                                                   \
	  ons[1] = value;                                                  \
	  hook_merge_nodes(&value, 1, ons, ARRAY_SIZE(ons), HOOK_OPT_RAW); \
	  __dbg_info_merge_sets(&value, 1, ons, ARRAY_SIZE(ons), dbg_read_after_write); \
Michael Beck's avatar
Michael Beck committed
242
	} while(0)
243
244
245

/**
 * Merge the debug info due to Read-after-Read optimization:
Michael Beck's avatar
Michael Beck committed
246
247
248
249
 * 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
250
 */
251
252
253
254
255
256
257
#define DBG_OPT_RAR(oldld, ld)                                      \
	do {                                                            \
	  ir_node *ons[2];                                              \
	  ons[0] = oldld;                                               \
	  ons[1] = ld;                                                  \
	  hook_merge_nodes(&ld, 1, ons, ARRAY_SIZE(ons), HOOK_OPT_RAR); \
	  __dbg_info_merge_sets(&ld, 1, ons, ARRAY_SIZE(ons), dbg_read_after_read); \
Michael Beck's avatar
Michael Beck committed
258
	} while(0)
Götz Lindenmaier's avatar
Götz Lindenmaier committed
259

260
261
/**
 * Merge the debug info due to Read-a-Const optimization:
Michael Beck's avatar
Michael Beck committed
262
263
264
265
266
 * 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
267
 */
Michael Beck's avatar
Michael Beck committed
268
269
#define DBG_OPT_RC(ld, c)                                         \
	do {                                                          \
Götz Lindenmaier's avatar
Götz Lindenmaier committed
270
	  ir_node *ons[2];                                            \
271
272
	  ons[0] = ld;                                                \
	  ons[1] = c;                                                 \
273
274
	  hook_merge_nodes(&c, 1, ons, ARRAY_SIZE(ons), HOOK_OPT_RC); \
	  __dbg_info_merge_sets(&ld, 1, ons, ARRAY_SIZE(ons), dbg_read_a_const); \
275
276
	} while(0)

Michael Beck's avatar
Michael Beck committed
277
278
279
280
/**
 * Merge the debug info after a tuple optimization.
 * a Proj(Tuple) is replaced by the associated tuple value.
 *
Michael Beck's avatar
Michael Beck committed
281
 * @param proj   the Proj node
Michael Beck's avatar
Michael Beck committed
282
283
284
 * @param tuple  the Tuple node
 * @param n      the Proj(Tuple) value
 */
285
286
287
288
289
290
291
292
#define DBG_OPT_TUPLE(proj, tuple, n)                                      \
	do {                                                                   \
	  ir_node *ons[3];                                                     \
	  ons[0] = proj;                                                       \
	  ons[1] = tuple;                                                      \
	  ons[2] = n;                                                          \
	  hook_merge_nodes(&n, 1, ons, ARRAY_SIZE(ons), HOOK_OPT_TUPLE);       \
	  __dbg_info_merge_sets(&n, 1, ons, ARRAY_SIZE(ons), dbg_opt_auxnode); \
Michael Beck's avatar
Michael Beck committed
293
	} while(0)
Michael Beck's avatar
Michael Beck committed
294

Michael Beck's avatar
Michael Beck committed
295
296
297
298
299
300
301
/**
 * 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
 */
302
303
304
305
306
307
308
#define DBG_OPT_ID(id, n)                                                  \
	do {                                                                   \
	  ir_node *ons[2];                                                     \
	  ons[0] = id;                                                         \
	  ons[1] = n;                                                          \
	  hook_merge_nodes(&n, 1, ons, ARRAY_SIZE(ons), HOOK_OPT_ID);          \
	  __dbg_info_merge_sets(&n, 1, ons, ARRAY_SIZE(ons), dbg_opt_auxnode); \
Michael Beck's avatar
Michael Beck committed
309
	} while(0)
Michael Beck's avatar
Michael Beck committed
310

311
/**
Michael Beck's avatar
Michael Beck committed
312
313
314
315
 * Merge the debug info due to common-subexpression elimination.
 *
 * @param oldn  the old node
 * @param n     the node that replaces oldn
316
 */
317
318
319
320
321
322
323
#define DBG_OPT_CSE(oldn, n)                                           \
	do {                                                               \
	  ir_node *ons[2];                                                 \
	  ons[0] = oldn;                                                   \
	  ons[1] = n;                                                      \
	  hook_merge_nodes(&n, 1, ons, ARRAY_SIZE(ons), HOOK_OPT_CSE);     \
	  __dbg_info_merge_sets(&n, 1, ons, ARRAY_SIZE(ons), dbg_opt_cse); \
Michael Beck's avatar
Michael Beck committed
324
	} while(0)
325

Michael Beck's avatar
Michael Beck committed
326
327
328
329
330
331
332
/**
 * Merge the debug info due to polymorphic call optimization.
 * A Sel node was replaced by a constant.
 *
 * @param sel   the Sel node that will be replaced.
 * @param c     the constant node that replaces sel
 */
333
334
335
336
337
338
339
340
#define DBG_OPT_POLY(sel, c)                                                 \
	do {                                                                     \
	  ir_node *ons[3];                                                       \
	  ons[0] = sel;                                                          \
	  ons[1] = skip_Proj(get_Sel_ptr(sel));                                  \
	  ons[2] = c;                                                            \
	  hook_merge_nodes(&c, 1, ons, ARRAY_SIZE(ons), HOOK_OPT_POLY_CALL);     \
	  __dbg_info_merge_sets(&c, 1, ons, ARRAY_SIZE(ons), dbg_rem_poly_call); \
Michael Beck's avatar
Michael Beck committed
341
	} while(0)
342

343
/**
Michael Beck's avatar
Michael Beck committed
344
345
346
347
 * A node was replaced by another node due to a Confirmation.
 *
 * @param oldn  the old node
 * @param n     the new node
348
 */
Michael Beck's avatar
Michael Beck committed
349
350
351
352
353
#define DBG_OPT_CONFIRM(oldn, n)                                  \
	do {                                                          \
	  hook_merge_nodes(&n, 1, &oldn, 1, HOOK_OPT_CONFIRM);        \
	  __dbg_info_merge_pair(n, oldn, dbg_opt_confirm);            \
	} while(0)
354
355

/**
Michael Beck's avatar
Michael Beck committed
356
357
358
 * A node was replaced by a constant due to a Confimation.
 *
 * @param oldn  the old node
359
 * @param c     the new constant node
360
 */
Michael Beck's avatar
Michael Beck committed
361
362
363
364
365
#define DBG_OPT_CONFIRM_C(oldn, c)                                \
	do {                                                          \
	  hook_merge_nodes(&c, 1, &oldn, 1, HOOK_OPT_CONFIRM_C);      \
	  __dbg_info_merge_pair(c, oldn, dbg_opt_confirm);            \
	} while(0)
366

367
368
369
370
371
/**
 * A exception exdge was removed due to a Confirmation prove.
 *
 * @param oldn  the old node
 */
Michael Beck's avatar
Michael Beck committed
372
373
374
375
#define DBG_OPT_EXC_REM(oldn)                                     \
	do {                                                          \
	  hook_merge_nodes(NULL, 0, &oldn, 1, HOOK_OPT_EXC_REM);      \
	} while(0)
376

377
/**
Michael Beck's avatar
Michael Beck committed
378
379
380
381
 * A node could be evaluated to a value due to a Confirm.
 * This will lead to a constant evaluation.
 *
 * @param n  the node that could be evaluated
382
 */
Michael Beck's avatar
Michael Beck committed
383
384
385
386
#define DBG_EVAL_CONFIRM(n)                                    \
	do {                                                       \
	  hook_merge_nodes(NULL, 0, &n, 1, HOOK_OPT_CONFIRM_E);    \
	} while(0)
Michael Beck's avatar
Michael Beck committed
387

388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
/**
 * Merge the debug info due to a GVN-PRE result.
 *
 * @param oldn  the old node
 * @param n     the new node replacing oldn
 * @param flag  firm statistics option
 */
#define DBG_OPT_GVN_PRE(oldn, n, flag)             \
	do {                                           \
	  hook_merge_nodes(&n, 1, &oldn, 1, flag);     \
	  __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
 * @param flag  firm statistics option
 */
#define DBG_OPT_COMBO(oldn, n, flag)             \
	do {                                         \
	  hook_merge_nodes(&n, 1, &oldn, 1, flag);   \
	  __dbg_info_merge_pair(n, oldn, dbg_combo); \
	} while(0)

414
/**
yb9976's avatar
yb9976 committed
415
 * Merge the debug info due to a jump threading result.
416
417
418
419
 *
 * @param oldn  the old control flow node
 * @param n     the new control flow node replacing oldn
 */
yb9976's avatar
yb9976 committed
420
#define DBG_OPT_JUMPTHREADING(oldn, n)                         \
421
	do {                                                   \
yb9976's avatar
yb9976 committed
422
423
	  hook_merge_nodes(&n, 1, &oldn, 1, FS_OPT_JUMPTHREADING); \
	  __dbg_info_merge_pair(n, oldn, dbg_jumpthreading);       \
424
425
	} while(0)

Matthias Braun's avatar
Matthias Braun committed
426
#endif