irverify.c 38.4 KB
Newer Older
Christian Würdig's avatar
Christian Würdig committed
1
2
/*
 * This file is part of libFirm.
3
 * Copyright (C) 2012 University of Karlsruhe.
Christian Würdig's avatar
Christian Würdig committed
4
5
 */

Matthias Braun's avatar
Matthias Braun committed
6
7
8
/**
 * @file
 * @brief    Check irnodes for correctness.
Matthias Braun's avatar
Matthias Braun committed
9
10
 * @author   Christian Schaefer, Goetz Lindenmaier, Till Riedel, Michael Beck,
 *           Matthias Braun
11
 */
12
#include "irnode_t.h"
13
14
15
#include "irprog.h"
#include "irop_t.h"
#include "irgraph_t.h"
16
#include "irverify_t.h"
17
18
19
20
21
22
#include "irgwalk.h"
#include "irdump.h"
#include "irdom_t.h"
#include "irprintf.h"
#include "irouts.h"
#include "irflag_t.h"
23
#include "irnodeset.h"
24
#include "ircons.h"
Christian Schäfer's avatar
Christian Schäfer committed
25

Matthias Braun's avatar
Matthias Braun committed
26
static void warn(const ir_node *n, const char *format, ...)
27
{
Matthias Braun's avatar
Matthias Braun committed
28
29
30
31
	FILE *out = stderr;
	fputs("Verify warning: ", out);
	if (n != NULL) {
		ir_fprintf(out, "%+F: ", n);
32
	}
Matthias Braun's avatar
Matthias Braun committed
33
34
35
36
37
	va_list ap;
	va_start(ap, format);
	ir_vfprintf(out, format, ap);
	va_end(ap);
	fputc('\n', out);
38
39
}

40
/**
Matthias Braun's avatar
Matthias Braun committed
41
42
 * Checks if node @p n has mode @p expected. Sisplays a message and returns
 * false in case of mismatch.
43
 */
Matthias Braun's avatar
Matthias Braun committed
44
static bool check_mode(const ir_node *n, const ir_mode *expected)
45
{
Matthias Braun's avatar
Matthias Braun committed
46
47
48
49
	ir_mode *mode = get_irn_mode(n);
	if (mode != expected) {
		warn(n, "expected mode %+F but found %+F", expected, mode);
		return false;
50
	}
Matthias Braun's avatar
Matthias Braun committed
51
	return true;
Michael Beck's avatar
Michael Beck committed
52
53
}

Matthias Braun's avatar
Matthias Braun committed
54
typedef int (*check_mode_func_ptr)(const ir_mode *mode);
Michael Beck's avatar
Michael Beck committed
55

Michael Beck's avatar
Michael Beck committed
56
/**
Matthias Braun's avatar
Matthias Braun committed
57
58
 * Checks if the mode of node @p fulfills the predicate function @p func.
 * Displays a message and returns false if predicate is not fulfilled.
Michael Beck's avatar
Michael Beck committed
59
 */
Matthias Braun's avatar
Matthias Braun committed
60
61
static bool check_mode_func(const ir_node *n, check_mode_func_ptr func,
                            const char *name)
62
{
Matthias Braun's avatar
Matthias Braun committed
63
64
65
66
	ir_mode *mode = get_irn_mode(n);
	if (!func(mode)) {
		warn(n, "expected %s mode but found %+F", name, mode);
		return false;
67
	}
Matthias Braun's avatar
Matthias Braun committed
68
	return true;
Michael Beck's avatar
Michael Beck committed
69
}
70

Michael Beck's avatar
Michael Beck committed
71
/**
Matthias Braun's avatar
Matthias Braun committed
72
73
 * Checks if input @p input of node @p n has mode @p expected. Displays a
 * message and returns false in case of mismatch.
Michael Beck's avatar
Michael Beck committed
74
 */
Matthias Braun's avatar
Matthias Braun committed
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
static bool check_input_mode(const ir_node *n, int input, const char *inputname,
                             const ir_mode *mode)
{
	ir_node *in      = get_irn_n(n, input);
	ir_mode *in_mode = get_irn_mode(in);
	if (in_mode != mode) {
		char num[16];
		if (inputname == NULL) {
			snprintf(num, sizeof(num), "input %d", input);
			inputname = num;
		}
		warn(n, "expected reference mode for input '%s' but found %+F (%+F)",
		     inputname, mode, in);
		return false;
	}
	return true;
Michael Beck's avatar
Michael Beck committed
91
92
93
}

/**
Matthias Braun's avatar
Matthias Braun committed
94
95
 * Checks if mode of input @p input of node @p n fulfills the predicate
 * functions @p func. Displays a message and returns false if unfulfilled.
Michael Beck's avatar
Michael Beck committed
96
 */
Matthias Braun's avatar
Matthias Braun committed
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
static bool check_input_func(const ir_node *n, int input, const char *inputname,
                             check_mode_func_ptr func, const char *modedescr)
{
	ir_node *in   = get_irn_n(n, input);
	ir_mode *mode = get_irn_mode(in);
	if (!func(mode)) {
		char num[16];
		if (inputname == NULL) {
			snprintf(num, sizeof(num), "input %d", input);
			inputname = num;
		}
		warn(n, "expected %s mode for input '%s' but found %+F (%+F)",
		     modedescr, inputname, mode, in);
		return false;
	}
	return true;
Michael Beck's avatar
Michael Beck committed
113
114
}

Matthias Braun's avatar
Matthias Braun committed
115
116
static bool check_mode_same_input(const ir_node *n, int input,
                                  const char *inputname)
117
{
Matthias Braun's avatar
Matthias Braun committed
118
119
120
121
122
123
124
125
126
127
128
129
130
131
	ir_mode *mode    = get_irn_mode(n);
	ir_node *in      = get_irn_n(n, input);
	ir_mode *in_mode = get_irn_mode(in);
	if (mode != in_mode) {
		char num[16];
		if (inputname == NULL) {
			snprintf(num, sizeof(num), "input %d", input);
			inputname = num;
		}
		warn(n, "mode of input '%s' different from output mode %+F",
		     inputname, mode);
		return false;
	}
	return true;
Michael Beck's avatar
Michael Beck committed
132
133
}

yb9976's avatar
yb9976 committed
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
static bool check_mode_same_size_input(const ir_node *n, int input,
                                       const char *inputname)
{
	ir_mode  *mode         = get_irn_mode(n);
	unsigned  mode_size    = get_mode_size_bits(mode);
	ir_node  *in           = get_irn_n(n, input);
	ir_mode  *in_mode      = get_irn_mode(in);
	unsigned  in_mode_size = get_mode_size_bits(in_mode);
	if (mode_size != in_mode_size) {
		char num[16];
		if (inputname == NULL) {
			snprintf(num, sizeof(num), "input %d", input);
			inputname = num;
		}
		warn(n, "mode size of input '%s' different from output mode size",
		     inputname);
		return false;
	}
	return true;
}

Michael Beck's avatar
Michael Beck committed
155
/**
Matthias Braun's avatar
Matthias Braun committed
156
 * Displays error message that a wrong proj number was found and returns false.
Michael Beck's avatar
Michael Beck committed
157
 */
Matthias Braun's avatar
Matthias Braun committed
158
static bool invalid_proj(const ir_node *proj)
159
{
Matthias Braun's avatar
Matthias Braun committed
160
161
162
	warn(proj, "invalid proj number %ld for predecessor %+F",
	     get_Proj_proj(proj), get_Proj_pred(proj));
	return false;
Michael Beck's avatar
Michael Beck committed
163
164
}

165
static int verify_node_Proj_Start(const ir_node *p)
166
{
Matthias Braun's avatar
Matthias Braun committed
167
168
169
170
171
172
173
	switch ((pn_Start)get_Proj_proj(p)) {
	case pn_Start_X_initial_exec: return check_mode(p, mode_X);
	case pn_Start_M:              return check_mode(p, mode_M);
	case pn_Start_P_frame_base:   return check_mode_func(p, mode_is_reference, "reference");
	case pn_Start_T_args:         return check_mode(p, mode_T);
	}
	return invalid_proj(p);
Michael Beck's avatar
Michael Beck committed
174
}
175

176
static int verify_node_Proj_Cond(const ir_node *p)
177
{
Matthias Braun's avatar
Matthias Braun committed
178
179
180
181
182
	switch ((pn_Cond)get_Proj_proj(p)) {
	case pn_Cond_true:
	case pn_Cond_false: return check_mode(p, mode_X);
	}
	return invalid_proj(p);
Michael Beck's avatar
Michael Beck committed
183
}
184

Matthias Braun's avatar
Matthias Braun committed
185
186
187
188
static int verify_node_Proj_Switch(const ir_node *p)
{
	long     pn   = get_Proj_proj(p);
	ir_node *pred = get_Proj_pred(p);
Matthias Braun's avatar
Matthias Braun committed
189
190
191
192
193
194
	bool     fine = check_mode(p, mode_X);
	if (pn < 0 || pn >= (long)get_Switch_n_outs(pred)) {
		warn(p, "invalid proj number %ld for predecessor %+F", pn, pred);
		fine = false;
	}
	return fine;
Matthias Braun's avatar
Matthias Braun committed
195
196
}

197
static int verify_node_Proj_Raise(const ir_node *p)
198
{
Matthias Braun's avatar
Matthias Braun committed
199
200
201
202
203
	switch ((pn_Raise)get_Proj_proj(p)) {
	case pn_Raise_X: return check_mode(p, mode_X);
	case pn_Raise_M: return check_mode(p, mode_M);
	}
	return invalid_proj(p);
Michael Beck's avatar
Michael Beck committed
204
}
205

206
static int verify_node_Proj_Call(const ir_node *p)
207
{
Matthias Braun's avatar
Matthias Braun committed
208
209
210
211
212
	switch ((pn_Call)get_Proj_proj(p)) {
	case pn_Call_M:         return check_mode(p, mode_M);
	case pn_Call_X_except:  return check_mode(p, mode_X);
	case pn_Call_X_regular: return check_mode(p, mode_X);
	case pn_Call_T_result:  return check_mode(p, mode_T);
Matthias Braun's avatar
Matthias Braun committed
213
	}
Matthias Braun's avatar
Matthias Braun committed
214
	return invalid_proj(p);
Michael Beck's avatar
Michael Beck committed
215
}
216

217
static int verify_node_Proj_Div(const ir_node *p)
218
{
Matthias Braun's avatar
Matthias Braun committed
219
220
221
222
223
224
225
	switch ((pn_Div)get_Proj_proj(p)) {
	case pn_Div_M:         return check_mode(p, mode_M);
	case pn_Div_X_regular: return check_mode(p, mode_X);
	case pn_Div_X_except:  return check_mode(p, mode_X);
	case pn_Div_res:       return check_mode(p, get_Div_resmode(get_Proj_pred(p)));
	}
	return invalid_proj(p);
Michael Beck's avatar
Michael Beck committed
226
}
Michael Beck's avatar
Michael Beck committed
227

228
static int verify_node_Proj_Mod(const ir_node *p)
229
{
Matthias Braun's avatar
Matthias Braun committed
230
231
232
233
234
235
236
	switch ((pn_Mod)get_Proj_proj(p)) {
	case pn_Mod_M:         return check_mode(p, mode_M);
	case pn_Mod_X_regular: return check_mode(p, mode_X);
	case pn_Mod_X_except:  return check_mode(p, mode_X);
	case pn_Mod_res:       return check_mode(p, get_Mod_resmode(get_Proj_pred(p)));
	}
	return invalid_proj(p);
Michael Beck's avatar
Michael Beck committed
237
}
238

239
static int verify_node_Proj_Load(const ir_node *p)
240
{
Matthias Braun's avatar
Matthias Braun committed
241
242
243
244
245
246
247
	switch ((pn_Load)get_Proj_proj(p)) {
	case pn_Load_M:         return check_mode(p, mode_M);
	case pn_Load_X_regular: return check_mode(p, mode_X);
	case pn_Load_X_except:  return check_mode(p, mode_X);
	case pn_Load_res:       return check_mode(p, get_Load_mode(get_Proj_pred(p)));
	}
	return invalid_proj(p);
Michael Beck's avatar
Michael Beck committed
248
}
249

250
static int verify_node_Proj_Store(const ir_node *p)
251
{
Matthias Braun's avatar
Matthias Braun committed
252
253
254
255
	switch ((pn_Store)get_Proj_proj(p)) {
	case pn_Store_M:         return check_mode(p, mode_M);
	case pn_Store_X_regular: return check_mode(p, mode_X);
	case pn_Store_X_except:  return check_mode(p, mode_X);
256
	}
Matthias Braun's avatar
Matthias Braun committed
257
	return invalid_proj(p);
Michael Beck's avatar
Michael Beck committed
258
259
}

260
static int verify_node_Proj_Alloc(const ir_node *p)
261
{
Matthias Braun's avatar
Matthias Braun committed
262
263
264
265
266
267
	switch ((pn_Alloc)get_Proj_proj(p)) {
	case pn_Alloc_M:   return check_mode(p, mode_M);
	case pn_Alloc_res: return check_mode_func(p, mode_is_reference, "reference");
	}
	return invalid_proj(p);
}
Michael Beck's avatar
Michael Beck committed
268

Matthias Braun's avatar
Matthias Braun committed
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
static int verify_node_Proj_Proj_Start(const ir_node *p)
{
	ir_graph *irg = get_irn_irg(p);
	ir_type  *mt  = get_entity_type(get_irg_entity(irg));
	if (!is_Method_type(mt))
		return true;
	long pn = get_Proj_proj(p);
	if (pn < 0 || pn >= (long)get_method_n_params(mt)) {
		warn(p, "invalid proj number %ld after Proj(%+F)", pn,
		     get_Proj_pred(get_Proj_pred(p)));
		return false;
	}
	if (!irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_BACKEND)) {
		ir_type *param_type = get_method_param_type(mt, pn);
		return check_mode(p, get_type_mode(param_type));
	}
	return true;
}

static int verify_node_Proj_Proj_Call(const ir_node *p)
{
	ir_node *pred = get_Proj_pred(p);
	ir_node *call = get_Proj_pred(pred);
	ir_type *mt   = get_Call_type(call);
	if (!is_Method_type(mt))
		return true;
	long pn = get_Proj_proj(p);
	if (pn < 0 || pn >= (long)get_method_n_ress(mt)) {
		warn(p, "invalid proj number %ld after %+F", pn, call);
		return false;
	}
	ir_type *type = get_method_res_type(mt, pn);
301
	ir_mode *mode = is_aggregate_type(type) ? mode_P : get_type_mode(type);
Matthias Braun's avatar
Matthias Braun committed
302
	return check_mode(p, mode);
Michael Beck's avatar
Michael Beck committed
303
}
304

305
static int verify_node_Proj_Proj(const ir_node *p)
306
{
307
308
309
	ir_node *pred     = get_Proj_pred(p);
	ir_node *predpred = get_Proj_pred(pred);
	switch (get_irn_opcode(predpred)) {
Matthias Braun's avatar
Matthias Braun committed
310
311
312
	case iro_Start: return verify_node_Proj_Proj_Start(p);
	case iro_Call:  return verify_node_Proj_Proj_Call(p);
	default:        return true;
313
	}
314
}
315

316
static int verify_node_Proj_Tuple(const ir_node *p)
317
{
Matthias Braun's avatar
Matthias Braun committed
318
319
320
321
322
323
324
325
	ir_node *tuple = get_Proj_pred(p);
	long     pn    = get_Proj_proj(p);
	if (pn < 0 || pn >= get_irn_arity(tuple)) {
		warn(p, "invalid proj number on %+F", tuple);
		return false;
	}
	ir_node *in = get_irn_n(tuple, pn);
	return check_mode(p, get_irn_mode(in));
Michael Beck's avatar
Michael Beck committed
326
}
Christian Schäfer's avatar
Christian Schäfer committed
327

Matthias Braun's avatar
Matthias Braun committed
328
static bool verify_node_Proj_fragile(const ir_node *node)
329
{
Matthias Braun's avatar
Matthias Braun committed
330
331
332
333
334
335
336
337
338
339
340
341
	ir_node *pred = get_Proj_pred(node);
	if (!is_fragile_op(pred))
		return true;

	if (!is_x_except_Proj(node) && !is_x_regular_Proj(node))
		return true;
	int throws_exception = ir_throws_exception(pred);
	if (!throws_exception) {
		warn(node, "exception Proj on %+F which is not marked as throwing exceptions", pred);
		return false;
	}
	return true;
342
343
}

344
static int verify_node_Proj(const ir_node *p)
345
{
Matthias Braun's avatar
Matthias Braun committed
346
	ir_graph *irg  = get_irn_irg(p);
Matthias Braun's avatar
Matthias Braun committed
347
348
	ir_node  *pred = get_Proj_pred(p);
	if (get_irn_mode(pred) != mode_T) {
Matthias Braun's avatar
Matthias Braun committed
349
		warn(p, "predecessor %+F does not have mode_T", pred);
Matthias Braun's avatar
Matthias Braun committed
350
		return false;
351
	}
Matthias Braun's avatar
Matthias Braun committed
352
353
354
	bool fine = true;
	if (get_irg_pinned(irg) != op_pin_state_floats
	    && get_nodes_block(pred) != get_nodes_block(p)) {
Matthias Braun's avatar
Matthias Braun committed
355
	    warn(p, "different block than predecessor %+F", pred);
Matthias Braun's avatar
Matthias Braun committed
356
357
358
	    fine = false;
	}
	fine &= verify_node_Proj_fragile(p);
359

Matthias Braun's avatar
Matthias Braun committed
360
	ir_op *op = get_irn_op(pred);
361
	if (op->ops.verify_proj_node)
Matthias Braun's avatar
Matthias Braun committed
362
		fine &= op->ops.verify_proj_node(p);
363

Matthias Braun's avatar
Matthias Braun committed
364
	return fine;
Michael Beck's avatar
Michael Beck committed
365
}
Götz Lindenmaier's avatar
Götz Lindenmaier committed
366

367
static int verify_node_Block(const ir_node *n)
368
{
Matthias Braun's avatar
Matthias Braun committed
369
370
371
	bool fine = check_mode(n, mode_BB);
	for (int i = 0, n_cfgpreds = get_Block_n_cfgpreds(n); i < n_cfgpreds; ++i) {
		fine &= check_input_mode(n, i, NULL, mode_X);
Matthias Braun's avatar
Matthias Braun committed
372
373
		ir_node *pred         = get_Block_cfgpred(n, i);
		ir_node *skipped_pred = skip_Proj(skip_Tuple(pred));
Matthias Braun's avatar
Matthias Braun committed
374
375
376
377
378
		if (!is_cfop(skipped_pred) && !is_Bad(skipped_pred)) {
			warn(n, "predecessor %d of block is not a cfop, but %+F", i,
			     skipped_pred);
			fine = false;
		}
379
380
	}

Matthias Braun's avatar
Matthias Braun committed
381
382
383
384
385
386
	ir_graph *irg = get_irn_irg(n);
	if (n == get_irg_start_block(irg) && get_Block_n_cfgpreds(n) != 0) {
		warn(n, "start block mustn't have inputs");
		fine = false;
	} else if (n == get_irg_end_block(irg)
	           && !irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_BACKEND)) {
387
		/* End block may only have Return, Raise or fragile ops as preds. */
Matthias Braun's avatar
Matthias Braun committed
388
389
390
391
392
393
394
395
396
397
		for (int i = 0, n_cfgpreds = get_Block_n_cfgpreds(n); i < n_cfgpreds;
		     ++i) {
		    ir_node *pred         = get_Block_cfgpred(n, i);
			ir_node *skipped_pred = skip_Proj(skip_Tuple(pred));
			if (!is_Return(skipped_pred) && !is_Bad(skipped_pred)
			    && !is_Raise(skipped_pred)) {
			    warn(n, "end block must have Return or Raise predecessor, found %+F",
			         skipped_pred);
			    fine = false;
			}
398
		}
399
	}
Matthias Braun's avatar
Matthias Braun committed
400
	return fine;
Michael Beck's avatar
Michael Beck committed
401
}
402

403
404
405
406
407
408
static int verify_node_Deleted(const ir_node *n)
{
	warn(n, "Deleted node %+F appears to be reachable");
	return false;
}

409
static int verify_node_Start(const ir_node *n)
410
{
Matthias Braun's avatar
Matthias Braun committed
411
	return check_mode(n, mode_T);
Michael Beck's avatar
Michael Beck committed
412
}
413

414
static int verify_node_Jmp(const ir_node *n)
415
{
Matthias Braun's avatar
Matthias Braun committed
416
	return check_mode(n, mode_X);
Michael Beck's avatar
Michael Beck committed
417
}
418

419
static int verify_node_IJmp(const ir_node *n)
420
{
Matthias Braun's avatar
Matthias Braun committed
421
422
423
	bool fine = check_input_func(n, n_IJmp_target, "target", mode_is_reference, "reference");
	fine &= check_mode(n, mode_X);
	return fine;
Michael Beck's avatar
Michael Beck committed
424
425
}

426
static int verify_node_Cond(const ir_node *n)
427
{
Matthias Braun's avatar
Matthias Braun committed
428
429
430
	bool fine = check_mode(n, mode_T);
	fine &= check_input_mode(n, n_Cond_selector, "selector", mode_b);
	return fine;
Matthias Braun's avatar
Matthias Braun committed
431
432
}

Matthias Braun's avatar
Matthias Braun committed
433
static bool verify_switch_table(const ir_node *n)
Matthias Braun's avatar
Matthias Braun committed
434
{
Matthias Braun's avatar
Matthias Braun committed
435
436
437
438
439
	const ir_switch_table *table = get_Switch_table(n);
	if (table == NULL) {
		warn(n, "switch table is NULL");
		return false;
	}
440

Matthias Braun's avatar
Matthias Braun committed
441
442
443
444
445
446
	unsigned  n_outs   = get_Switch_n_outs(n);
	ir_node  *selector = get_Switch_selector(n);
	ir_mode  *mode     = get_irn_mode(selector);
	bool      fine     = true;
	for (size_t e = 0, n_entries = ir_switch_table_get_n_entries(table);
	     e < n_entries; ++e) {
Matthias Braun's avatar
Matthias Braun committed
447
448
449
450
		const ir_switch_table_entry *entry
			= ir_switch_table_get_entry_const(table, e);
		if (entry->pn == 0)
			continue;
Matthias Braun's avatar
Matthias Braun committed
451
452
453
454
455
456
457
458
459
460
		if (entry->min == NULL || entry->max == NULL) {
			warn(n, "switch table entry %zu without min+max value", e);
			fine = false;
		}
		if (mode_is_int(mode) && (get_tarval_mode(entry->min) != mode
		                       || get_tarval_mode(entry->max) != mode)) {
			warn(n, "switch table entry %zu has wrong mode for min or max value",
				 e);
			fine = false;
		} else if (tarval_cmp(entry->min, entry->max) == ir_relation_greater) {
461
			warn(n, "switch table entry %zu min is not less or equal than max", e);
Matthias Braun's avatar
Matthias Braun committed
462
463
464
465
466
467
			fine = false;
		}
		if (entry->pn < 0 || entry->pn >= (long)n_outs) {
			warn(n, "switch table entry %zu has invalid proj number", e);
			fine = false;
		}
Matthias Braun's avatar
Matthias Braun committed
468
	}
Matthias Braun's avatar
Matthias Braun committed
469
	return fine;
Matthias Braun's avatar
Matthias Braun committed
470
}
471

Matthias Braun's avatar
Matthias Braun committed
472
473
static int verify_node_Switch(const ir_node *n)
{
Matthias Braun's avatar
Matthias Braun committed
474
475
476
477
	bool fine = check_mode(n, mode_T);
	fine &= check_input_func(n, n_Switch_selector, "selector", mode_is_int, "int");
	fine &= verify_switch_table(n);
	return fine;
Michael Beck's avatar
Michael Beck committed
478
479
}

480
static int verify_node_Return(const ir_node *n)
481
{
Matthias Braun's avatar
Matthias Braun committed
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
	bool fine = check_mode(n, mode_X);
	fine &= check_input_mode(n, n_Return_mem, "mem", mode_M);

	ir_graph *irg = get_irn_irg(n);
	ir_type  *mt  = get_entity_type(get_irg_entity(irg));
	if (!is_Method_type(mt)) /* someone else should report that problem */
		return true;
	if ((size_t)get_Return_n_ress(n) != get_method_n_ress(mt)) {
		warn(n, "number of inputs does not match metho type (%zu inputs, %zu declared)",
		     get_Return_n_ress(n), get_method_n_ress(mt));
	} else {
		for (int i = get_Return_n_ress(n); i-- > 0; ) {
			ir_type *expected = get_method_res_type(mt, i);
			if (is_atomic_type(expected)) {
				ir_mode *mode = get_type_mode(expected);
				fine &= check_input_mode(n, n_Return_max+1+i, NULL, mode);
498
			} else {
Matthias Braun's avatar
Matthias Braun committed
499
				fine &= check_input_func(n, n_Return_max+1+i, NULL, mode_is_reference, "reference");
500
			}
501
502
		}
	}
Matthias Braun's avatar
Matthias Braun committed
503
	return fine;
Michael Beck's avatar
Michael Beck committed
504
505
}

506
static int verify_node_Raise(const ir_node *n)
507
{
Matthias Braun's avatar
Matthias Braun committed
508
509
510
511
	bool fine = check_mode(n, mode_X);
	fine &= check_input_func(n, n_Raise_exo_ptr, "exo_ptr", mode_is_reference, "reference");
	fine &= check_input_mode(n, n_Raise_mem, "mem", mode_M);
	return fine;
Michael Beck's avatar
Michael Beck committed
512
513
}

Matthias Braun's avatar
Matthias Braun committed
514
515
516
517
518
static int mode_is_datab(const ir_mode *mode)
{
	return mode_is_data(mode) || mode == mode_b;
}

519
520
521
static int verify_node_Address(const ir_node *n)
{
	ir_entity *ent  = get_Address_entity(n);
522
523
	ir_type   *type = get_entity_type(ent);
	bool       fine = check_mode(n, get_type_pointer_mode(type));
524
525
526
527
528
529
530
	if (!(get_entity_owner(ent)->flags & tf_segment) && !is_method_entity(ent)) {
		warn(n, "entity of %+F is not in a segment type but %+F", ent, get_entity_owner(ent));
		fine = false;
	}
	return fine;
}

531
static int verify_node_Const(const ir_node *n)
532
{
Matthias Braun's avatar
Matthias Braun committed
533
534
535
536
537
538
539
540
541
	bool     fine    = check_mode_func(n, mode_is_datab, "data or b");
	ir_mode *mode    = get_irn_mode(n);
	ir_mode *tv_mode = get_tarval_mode(get_Const_tarval(n));
	if (fine && tv_mode != mode) {
		warn(n, "tarval mode (%+F) different from Const mode (%+F)", tv_mode,
		     mode);
		fine = false;
	}
	return fine;
Michael Beck's avatar
Michael Beck committed
542
543
}

544
static int verify_node_int(const ir_node *n)
Matthias Braun's avatar
Matthias Braun committed
545
{
546
	return check_mode_func(n, mode_is_int, "int");
547
548
}

549
static int verify_node_Sel(const ir_node *n)
550
{
Matthias Braun's avatar
Matthias Braun committed
551
552
553
	bool fine = check_mode_func(n, mode_is_reference, "reference");
	fine &= check_input_func(n, n_Sel_ptr, "ptr", mode_is_reference, "reference");
	fine &= check_input_mode(n, n_Sel_mem, "mem", mode_M);
554

Matthias Braun's avatar
Matthias Braun committed
555
556
	for (int i = 0, n_indexs = get_Sel_n_indexs(n); i < n_indexs; ++i) {
		fine &= check_input_func(n, n_Sel_max+i+1, NULL, mode_is_int, "int");
557
	}
Matthias Braun's avatar
Matthias Braun committed
558
	ir_entity *ent = get_Sel_entity(n);
Matthias Braun's avatar
Matthias Braun committed
559
560
561
562
563
564
565
566
567
	if (ent == NULL) {
		warn(n, "entity is NULL");
		fine = false;
	}
	if (get_entity_owner(ent)->flags & tf_segment) {
		warn(n, "Sel from entity with global/segment type entity", n);
		fine = false;
	}
	return fine;
568
569
}

570
static int verify_node_Call(const ir_node *n)
571
{
Matthias Braun's avatar
Matthias Braun committed
572
573
574
	bool fine = check_mode(n, mode_T);
	fine &= check_input_mode(n, n_Call_mem, "mem", mode_M);
	fine &= check_input_func(n, n_Call_ptr, "ptr", mode_is_reference, "reference");
575

Matthias Braun's avatar
Matthias Braun committed
576
	ir_type *mt = get_Call_type(n);
Matthias Braun's avatar
Matthias Braun committed
577
578
579
	if (!is_Method_type(mt)) {
		warn(n, "call_type is not a method type");
		return false;
580
581
	}

Matthias Braun's avatar
Matthias Braun committed
582
	if ((size_t)get_Call_n_params(n) < get_method_n_params(mt)) {
583
		warn(n, "call has fewer arguments than method type");
Matthias Braun's avatar
Matthias Braun committed
584
585
586
587
588
		return false;
	} else if ((size_t)get_Call_n_params(n) > get_method_n_params(mt) &&
	    get_method_variadicity(mt) != variadicity_variadic) {
		warn(n, "call has more arguments than method type");
		return false;
589
	} else {
Matthias Braun's avatar
Matthias Braun committed
590
591
592
593
594
595
596
597
598
599
		for (int i = 0, n_params = get_Call_n_params(n); i < n_params; ++i) {
			if (i < (int)get_method_n_params(mt)) {
				const ir_type *param_type = get_method_param_type(mt, i);
				if (is_atomic_type(param_type)) {
					ir_mode *mode = get_type_mode(param_type);
					fine &= check_input_mode(n, n_Call_max+1+i, NULL, mode);
				} else {
					fine &= check_input_func(n, n_Call_max+1+i, NULL,
											 mode_is_reference, "reference");
				}
600
			} else {
Matthias Braun's avatar
Matthias Braun committed
601
602
				fine &= check_input_func(n, n_Call_max+1+i, NULL,
				                         mode_is_data, "data");
603
			}
604
605
		}
	}
Matthias Braun's avatar
Matthias Braun committed
606
	return fine;
Michael Beck's avatar
Michael Beck committed
607
}
608

609
static int verify_node_Add(const ir_node *n)
610
{
Matthias Braun's avatar
Matthias Braun committed
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
	bool     fine = true;
	ir_mode *mode = get_irn_mode(n);
	if (mode_is_num(mode)) {
		fine &= check_mode_same_input(n, n_Add_left, "left");
		fine &= check_mode_same_input(n, n_Add_right, "right");
	} else if (mode_is_reference(mode)) {
		ir_mode *left_mode  = get_irn_mode(get_Add_left(n));
		ir_mode *right_mode = get_irn_mode(get_Add_right(n));
		if (mode_is_int(left_mode)) {
			fine &= check_mode_same_input(n, n_Add_right, "right");
		} else if (mode_is_int(right_mode)) {
			fine &= check_mode_same_input(n, n_Add_left, "left");
		} else {
			fine &= check_mode_same_input(n, n_Add_left, "left");
			fine &= check_mode_same_input(n, n_Add_right, "right");
		}
	} else {
		warn(n, "mode must be numeric or reference but is %+F", mode);
		fine = false;
	}
	return fine;
Michael Beck's avatar
Michael Beck committed
632
}
633

634
static int verify_node_Sub(const ir_node *n)
635
{
Matthias Braun's avatar
Matthias Braun committed
636
637
638
639
640
641
642
	bool     fine = true;
	ir_mode *mode = get_irn_mode(n);
	if (mode_is_num(mode)) {
		ir_mode *mode_left = get_irn_mode(get_Sub_left(n));
		if (mode_is_reference(mode_left)) {
			fine &= check_input_func(n, n_Sub_left, "left", mode_is_reference, "reference");
			fine &= check_input_func(n, n_Sub_right, "right", mode_is_reference, "reference");
yb9976's avatar
yb9976 committed
643
644
			fine &= check_mode_same_size_input(n, n_Sub_left, "left");
			fine &= check_mode_same_size_input(n, n_Sub_right, "right");
Matthias Braun's avatar
Matthias Braun committed
645
646
647
648
649
650
651
652
653
		} else {
			fine &= check_mode_same_input(n, n_Sub_left, "left");
			fine &= check_mode_same_input(n, n_Sub_right, "right");
		}
	} else if (mode_is_reference(mode)) {
		fine &= check_mode_same_input(n, n_Sub_left, "left");
		fine &= check_input_func(n, n_Sub_right, "right", mode_is_int, "int");
	}
	return fine;
Michael Beck's avatar
Michael Beck committed
654
}
655

656
static int verify_node_Minus(const ir_node *n)
657
{
Matthias Braun's avatar
Matthias Braun committed
658
659
660
	bool fine = check_mode_func(n, mode_is_num, "numeric");
	fine &= check_mode_same_input(n, n_Minus_op, "op");
	return fine;
Michael Beck's avatar
Michael Beck committed
661
}
662

663
static int verify_node_Mul(const ir_node *n)
664
{
Matthias Braun's avatar
Matthias Braun committed
665
666
667
668
	bool fine = check_mode_func(n, mode_is_num, "numeric");
	fine &= check_mode_same_input(n, n_Mul_left, "left");
	fine &= check_mode_same_input(n, n_Mul_right, "right");
	return fine;
Michael Beck's avatar
Michael Beck committed
669
}
670

671
static int verify_node_Mulh(const ir_node *n)
672
{
Matthias Braun's avatar
Matthias Braun committed
673
674
675
676
	bool fine = check_mode_func(n, mode_is_int, "int");
	fine &= check_mode_same_input(n, n_Mulh_left, "left");
	fine &= check_mode_same_input(n, n_Mulh_right, "right");
	return fine;
Michael Beck's avatar
Michael Beck committed
677
678
}

679
static int verify_node_Div(const ir_node *n)
680
{
Matthias Braun's avatar
Matthias Braun committed
681
682
683
684
685
686
687
688
689
690
	bool fine = check_mode(n, mode_T);
	ir_mode *mode = get_Div_resmode(n);
	fine &= check_input_mode(n, n_Div_left, "left", mode);
	fine &= check_input_mode(n, n_Div_right, "right", mode);
	fine &= check_input_mode(n, n_Div_mem, "mem", mode_M);
	if (!mode_is_num(mode)) {
		warn(n, "div resmode is not a numeric mode");
		fine = false;
	}
	return fine;
Michael Beck's avatar
Michael Beck committed
691
}
692

693
static int verify_node_Mod(const ir_node *n)
694
{
Matthias Braun's avatar
Matthias Braun committed
695
696
697
698
699
700
701
702
703
704
	bool fine = check_mode(n, mode_T);
	ir_mode *mode = get_Mod_resmode(n);
	fine &= check_input_mode(n, n_Mod_left, "left", mode);
	fine &= check_input_mode(n, n_Mod_right, "right", mode);
	fine &= check_input_mode(n, n_Mod_mem, "mem", mode_M);
	if (!mode_is_int(mode)) {
		warn(n, "mod resmode is not a int mode");
		fine = false;
	}
	return fine;
Michael Beck's avatar
Michael Beck committed
705
}
706

Matthias Braun's avatar
Matthias Braun committed
707
708
709
static int mode_is_intrefb(const ir_mode *mode)
{
	return mode_is_int(mode) || mode_is_reference(mode) || mode == mode_b;
Michael Beck's avatar
Michael Beck committed
710
}
Götz Lindenmaier's avatar
Götz Lindenmaier committed
711

712
713
static int verify_node_And(const ir_node *n)
{
Matthias Braun's avatar
Matthias Braun committed
714
715
716
717
	bool fine = check_mode_func(n, mode_is_intrefb, "int, reference or mode_b");
	fine &= check_mode_same_input(n, n_And_left, "left");
	fine &= check_mode_same_input(n, n_And_right, "right");
	return fine;
718
719
720
721
}

static int verify_node_Or(const ir_node *n)
{
Matthias Braun's avatar
Matthias Braun committed
722
723
724
725
	bool fine = check_mode_func(n, mode_is_intrefb, "int, reference or mode_b");
	fine &= check_mode_same_input(n, n_Or_left, "left");
	fine &= check_mode_same_input(n, n_Or_right, "right");
	return fine;
726
727
728
729
}

static int verify_node_Eor(const ir_node *n)
{
Matthias Braun's avatar
Matthias Braun committed
730
731
732
733
	bool fine = check_mode_func(n, mode_is_intrefb, "int, reference or mode_b");
	fine &= check_mode_same_input(n, n_Eor_left, "left");
	fine &= check_mode_same_input(n, n_Eor_right, "right");
	return fine;
734
}
Götz Lindenmaier's avatar
bugfix    
Götz Lindenmaier committed
735

Matthias Braun's avatar
Matthias Braun committed
736
static int mode_is_intb(const ir_mode *mode)
737
{
Matthias Braun's avatar
Matthias Braun committed
738
739
	return mode_is_int(mode) || mode == mode_b;
}
Michael Beck's avatar
Michael Beck committed
740

Matthias Braun's avatar
Matthias Braun committed
741
742
743
744
745
static int verify_node_Not(const ir_node *n)
{
	bool fine = check_mode_func(n, mode_is_intb, "int or mode_b");
	fine &= check_mode_same_input(n, n_Not_op, "op");
	return fine;
Michael Beck's avatar
Michael Beck committed
746
}
Michael Beck's avatar
Michael Beck committed
747

748
static int verify_node_Cmp(const ir_node *n)
749
{
Matthias Braun's avatar
Matthias Braun committed
750
	bool fine = check_mode(n, mode_b);
751
752
	fine &= check_input_func(n, n_Cmp_left, "left", mode_is_datab, "datab");
	fine &= check_input_func(n, n_Cmp_right, "right", mode_is_datab, "datab");
Matthias Braun's avatar
Matthias Braun committed
753
754
755
756
757
758
759
760
	ir_mode *model = get_irn_mode(get_Cmp_left(n));
	ir_mode *moder = get_irn_mode(get_Cmp_right(n));
	if (model != moder) {
		warn(n, "modes of left+right input are different: %+F and %+F", model,
		     moder);
		fine = false;
	}
	return fine;
Michael Beck's avatar
Michael Beck committed
761
}
Michael Beck's avatar
Michael Beck committed
762

Matthias Braun's avatar
Matthias Braun committed
763
764
765
static int mode_is_uint(const ir_mode *mode)
{
	return mode_is_int(mode) && !mode_is_signed(mode);
Michael Beck's avatar
Michael Beck committed
766
}
767

768
769
static int verify_node_Shl(const ir_node *n)
{
Matthias Braun's avatar
Matthias Braun committed
770
771
772
773
	bool fine = check_mode_func(n, mode_is_int, "int");
	fine &= check_mode_same_input(n, n_Shl_left, "left");
	fine &= check_input_func(n, n_Shl_right, "right", mode_is_uint, "unsigned int");
	return fine;
774
775
776
777
}

static int verify_node_Shr(const ir_node *n)
{
Matthias Braun's avatar
Matthias Braun committed
778
779
780
781
	bool fine = check_mode_func(n, mode_is_int, "int");
	fine &= check_mode_same_input(n, n_Shr_left, "left");
	fine &= check_input_func(n, n_Shr_right, "right", mode_is_uint, "unsigned int");
	return fine;
782
783
784
785
}

static int verify_node_Shrs(const ir_node *n)
{
Matthias Braun's avatar
Matthias Braun committed
786
787
788
789
	bool fine = check_mode_func(n, mode_is_int, "int");
	fine &= check_mode_same_input(n, n_Shrs_left, "left");
	fine &= check_input_func(n, n_Shrs_right, "right", mode_is_uint, "unsigned int");
	return fine;
790
}
791

792
static int verify_node_Conv(const ir_node *n)
793
{
Matthias Braun's avatar
Matthias Braun committed
794
795
796
797
	bool fine = check_mode_func(n, mode_is_data, "data");
	fine &= check_input_func(n, n_Conv_op, "op", mode_is_data, "data");
	return fine;
}
Michael Beck's avatar
Michael Beck committed
798

Matthias Braun's avatar
Matthias Braun committed
799
800
801
static int mode_is_dataMb(const ir_mode *mode)
{
	return mode_is_data(mode) || mode == mode_M || mode == mode_b;
Michael Beck's avatar
Michael Beck committed
802
}
803

804
static int verify_node_Phi(const ir_node *n)
805
{
806
807
808
	/* a Phi node MUST have the same number of inputs as its block
	 * Exception is a phi with 0 inputs which is used when (re)constructing the
	 * SSA form */
Matthias Braun's avatar
Matthias Braun committed
809
810
811
812
813
814
815
816
	bool      fine  = true;
	ir_node  *block = get_nodes_block(n);
	ir_graph *irg   = get_irn_irg(block);
	if (!is_Bad(block) && get_irn_arity(n) != get_irn_arity(block)
	    && (!irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_CONSTRUCTION)
	        || get_irn_arity(n) != 0)) {
	    warn(n, "wrong number of inputs in Phi node");
	    fine = false;
817
818
	}

Matthias Braun's avatar
Matthias Braun committed
819
	/* Phi: BB x dataM --> dataM */
Matthias Braun's avatar
Matthias Braun committed
820
821
822
	fine &= check_mode_func(n, mode_is_dataMb, "data, memory or mode_b");
	for (int i = 0, n_preds = get_Phi_n_preds(n); i < n_preds; ++i) {
		fine &= check_mode_same_input(n, i, NULL);
823
	}
Matthias Braun's avatar
Matthias Braun committed
824
	return fine;
Michael Beck's avatar
Michael Beck committed
825
}
826

827
static int verify_node_Load(const ir_node *n)
828
{
Matthias Braun's avatar
Matthias Braun committed
829
830
831
	bool fine = check_mode(n, mode_T);
	fine &= check_input_mode(n, n_Load_mem, "mem", mode_M);
	ir_graph *irg = get_irn_irg(n);
832
	if (!irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_BACKEND)) {
Matthias Braun's avatar
Matthias Braun committed
833
		fine &= check_input_func(n, n_Load_ptr, "ptr", mode_is_reference, "reference");
834
	}
Matthias Braun's avatar
Matthias Braun committed
835
836
837
838
839
840
	ir_mode *loadmode = get_Load_mode(n);
	if (!mode_is_data(loadmode)) {
		warn(n, "load mode is not a data mode, but %+F", loadmode);
		fine = false;
	}
	return fine;
Michael Beck's avatar
Michael Beck committed
841
842
}

843
static int verify_node_Store(const ir_node *n)
844
{
Matthias Braun's avatar
Matthias Braun committed
845
846
	bool fine = check_mode(n, mode_T);
	fine &= check_input_mode(n, n_Store_mem, "mem", mode_M);
Matthias Braun's avatar
Matthias Braun committed
847
	ir_graph *irg = get_irn_irg(n);
848
	if (!irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_BACKEND)) {
Matthias Braun's avatar
Matthias Braun committed
849
		fine &= check_input_func(n, n_Store_ptr, "ptr", mode_is_reference, "reference");
850
	}
Matthias Braun's avatar
Matthias Braun committed
851
852
853
854
855
856
	ir_mode *storemode = get_irn_mode(get_Store_value(n));
	if (!mode_is_data(storemode)) {
		warn(n, "store mode is not a data mode, but %+F", storemode);
		fine = false;
	}
	return fine;
Michael Beck's avatar
Michael Beck committed
857
858
}

859
static int verify_node_Alloc(const ir_node *n)
860
{
Matthias Braun's avatar
Matthias Braun committed
861
862
863
864
	bool fine = check_mode(n, mode_T);
	fine &= check_input_mode(n, n_Alloc_mem, "mem", mode_M);
	fine &= check_input_func(n, n_Alloc_size, "size", mode_is_uint, "unsigned int");
	return fine;
Michael Beck's avatar
Michael Beck committed
865
866
}

867
static int verify_node_Free(const ir_node *n)
868
{
Matthias Braun's avatar
Matthias Braun committed
869
870
871
872
	bool fine = check_mode(n, mode_M);
	fine &= check_input_mode(n, n_Free_mem, "mem", mode_M);
	fine &= check_input_func(n, n_Free_ptr, "ptr", mode_is_reference, "reference");
	return fine;
Michael Beck's avatar
Michael Beck committed
873
874
}

875
static int verify_node_Sync(const ir_node *n)
876
{
Matthias Braun's avatar
Matthias Braun committed
877
878
879
	bool fine = check_mode(n, mode_M);
	for (int i = 0, n_preds = get_Sync_n_preds(n); i < n_preds; ++i) {
		fine &= check_input_mode(n, i, NULL, mode_M);
880
	}
Matthias Braun's avatar
Matthias Braun committed
881
	return fine;
Michael Beck's avatar
Michael Beck committed
882
883
}

884
static int verify_node_Confirm(const ir_node *n)
885
{
Matthias Braun's avatar
Matthias Braun committed
886
887
888
	bool fine = check_mode_same_input(n, n_Confirm_value, "value");
	fine &= check_mode_same_input(n, n_Confirm_bound, "bound");
	return fine;
Michael Beck's avatar
Michael Beck committed
889
890
}

891
static int verify_node_Mux(const ir_node *n)
892
{
893
	bool fine = check_mode_func(n, mode_is_datab, "data or mode_b");
Matthias Braun's avatar
Matthias Braun committed
894
895
896
897
	fine &= check_input_mode(n, n_Mux_sel, "sel", mode_b);
	fine &= check_mode_same_input(n, n_Mux_true, "true");
	fine &= check_mode_same_input(n, n_Mux_false, "false");
	return fine;
Michael Beck's avatar
Michael Beck committed
898
899
}

900
static int verify_node_CopyB(const ir_node *n)
901
{
Matthias Braun's avatar
Matthias Braun committed
902
903
	bool      fine = check_mode(n, mode_M);
	ir_graph *irg  = get_irn_irg(n);
904
	if (!irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_BACKEND)) {
Matthias Braun's avatar
Matthias Braun committed
905
906
		fine &= check_input_func(n, n_CopyB_src, "src", mode_is_reference, "reference");
		fine &= check_input_func(n, n_CopyB_dst, "dst", mode_is_reference, "reference");
907
	}
Matthias Braun's avatar
Matthias Braun committed
908
909
910
911
912
913
	fine &= check_input_mode(n, n_CopyB_mem, "mem", mode_M);
	ir_type *type = get_CopyB_type(n);
	if (!is_compound_type(type) && !is_Array_type(type)) {
		warn(n, "CopyB_type is no compound or Array type but %+F", type);
	}
	return fine;
Michael Beck's avatar
Michael Beck committed
914
915
}

916
/**
Sebastian Hack's avatar
Sebastian Hack committed
917
918
919
920
 * Check dominance.
 * For each usage of a node, it is checked, if the block of the
 * node dominates the block of the usage (for phis: the predecessor
 * block of the phi for the corresponding edge).
921
 *
Matthias Braun's avatar
Matthias Braun committed
922
 * @return true on success, false on dominance error
Sebastian Hack's avatar
Sebastian Hack committed
923
 */
Matthias Braun's avatar
Matthias Braun committed
924
static bool check_dominance_for_node(const ir_node *use)
925
{
Matthias Braun's avatar
Matthias Braun committed
926
	bool fine = true;
927
	/* This won't work for blocks and the end node */
Matthias Braun's avatar
Matthias Braun committed
928
929
930
931
932
	if (is_Block(use) || is_End(use) || is_Anchor(use))
		return true;

	ir_node *bl = get_nodes_block(use);
	for (int i = get_irn_arity(use); i-- > 0; ) {
933
		ir_node *def    = get_irn_n(use, i);
Matthias Braun's avatar
Matthias Braun committed
934
935
936
937
938
		ir_node *def_bl = get_nodes_block(def);
		/* we have no dominance relation for unreachable blocks, so we can't
		 * check the dominance property there */
		if (!is_Block(def_bl) || get_Block_dom_depth(def_bl) == -1)
			continue;
939

Matthias Braun's avatar
Matthias Braun committed
940
941
942
943
944
945
946
		ir_node *use_bl = bl;
		if (is_Phi(use))
			use_bl = get_Block_cfgpred_block(bl, i);
		if (!is_Block(use_bl) || get_Block_dom_depth(use_bl) == -1)
			continue;

		if (!block_dominates(def_bl, use_bl)) {
yb9976's avatar
yb9976 committed
947
			warn(use, "not dominated by operand %+F", def);
Matthias Braun's avatar
Matthias Braun committed
948
			fine = false;
949
950
		}
	}
Matthias Braun's avatar
Matthias Braun committed
951
952
953
	return fine;
}

954
#ifdef DEBUG_libfirm
Matthias Braun's avatar
Matthias Braun committed
955
956
957
958
959
960
961
962
963
964
/**
 * Check if node is stored on the obstack belonging to the ir graph
 */
static bool check_irn_storage(ir_graph *irg, const ir_node *node)
{
	if (!node_is_in_irgs_storage(irg, node)) {
		warn(node, "node is not stored on graph obstack");
		return false;
	}
	return true;
965
}
966
#endif
Sebastian Hack's avatar
Sebastian Hack committed
967

968
int irn_verify_irg(const ir_node *n, ir_graph *irg)
969
{
Matthias Braun's avatar
Matthias Braun committed
970
971
972
973
974
	/* early abort if we have an irg mismatch */
	if (get_irn_irg(n) != irg) {
		warn(n, "get_irn_irg() != %+F", irg);
		return false;
	}
975

Matthias Braun's avatar
Matthias Braun committed
976
977
978
979
	bool fine = true;
	/* check_irn_storage is an expensive check for large graphs (it has a
	 * quadratic runtime but with a small constant); so do NOT run it in
	 * release mode */
980
#ifdef DEBUG_libfirm
Matthias Braun's avatar
Matthias Braun committed
981
	fine &= check_irn_storage(irg, n);
982
#endif
Matthias Braun's avatar
Matthias Braun committed
983
	/* abort if idx map is corrupt */