irverify.c 37.6 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
}

Michael Beck's avatar
Michael Beck committed
134
/**
Matthias Braun's avatar
Matthias Braun committed
135
 * Displays error message that a wrong proj number was found and returns false.
Michael Beck's avatar
Michael Beck committed
136
 */
Matthias Braun's avatar
Matthias Braun committed
137
static bool invalid_proj(const ir_node *proj)
138
{
Matthias Braun's avatar
Matthias Braun committed
139
140
141
	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
142
143
}

144
static int verify_node_Proj_Start(const ir_node *p)
145
{
Matthias Braun's avatar
Matthias Braun committed
146
147
148
149
150
151
152
	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
153
}
154

155
static int verify_node_Proj_Cond(const ir_node *p)
156
{
Matthias Braun's avatar
Matthias Braun committed
157
158
159
160
161
	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
162
}
163

Matthias Braun's avatar
Matthias Braun committed
164
165
166
167
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
168
169
170
171
172
173
	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
174
175
}

176
static int verify_node_Proj_Raise(const ir_node *p)
177
{
Matthias Braun's avatar
Matthias Braun committed
178
179
180
181
182
	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
183
}
184

185
static int verify_node_Proj_Call(const ir_node *p)
186
{
Matthias Braun's avatar
Matthias Braun committed
187
188
189
190
191
	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
192
	}
Matthias Braun's avatar
Matthias Braun committed
193
	return invalid_proj(p);
Michael Beck's avatar
Michael Beck committed
194
}
195

196
static int verify_node_Proj_Div(const ir_node *p)
197
{
Matthias Braun's avatar
Matthias Braun committed
198
199
200
201
202
203
204
	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
205
}
Michael Beck's avatar
Michael Beck committed
206

207
static int verify_node_Proj_Mod(const ir_node *p)
208
{
Matthias Braun's avatar
Matthias Braun committed
209
210
211
212
213
214
215
	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
216
}
217

218
static int verify_node_Proj_Load(const ir_node *p)
219
{
Matthias Braun's avatar
Matthias Braun committed
220
221
222
223
224
225
226
	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
227
}
228

229
static int verify_node_Proj_Store(const ir_node *p)
230
{
Matthias Braun's avatar
Matthias Braun committed
231
232
233
234
	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);
235
	}
Matthias Braun's avatar
Matthias Braun committed
236
	return invalid_proj(p);
Michael Beck's avatar
Michael Beck committed
237
238
}

239
static int verify_node_Proj_Alloc(const ir_node *p)
240
{
Matthias Braun's avatar
Matthias Braun committed
241
242
243
244
245
246
	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
247

Matthias Braun's avatar
Matthias Braun committed
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
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);
280
	ir_mode *mode = is_aggregate_type(type) ? mode_P : get_type_mode(type);
Matthias Braun's avatar
Matthias Braun committed
281
	return check_mode(p, mode);
Michael Beck's avatar
Michael Beck committed
282
}
283

284
static int verify_node_Proj_Proj(const ir_node *p)
285
{
286
287
288
	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
289
290
291
	case iro_Start: return verify_node_Proj_Proj_Start(p);
	case iro_Call:  return verify_node_Proj_Proj_Call(p);
	default:        return true;
292
	}
293
}
294

295
static int verify_node_Proj_Tuple(const ir_node *p)
296
{
Matthias Braun's avatar
Matthias Braun committed
297
298
299
300
301
302
303
304
	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
305
}
Christian Schäfer's avatar
Christian Schäfer committed
306

Matthias Braun's avatar
Matthias Braun committed
307
static bool verify_node_Proj_fragile(const ir_node *node)
308
{
Matthias Braun's avatar
Matthias Braun committed
309
310
311
312
313
314
315
316
317
318
319
320
	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;
321
322
}

323
static int verify_node_Proj(const ir_node *p)
324
{
Matthias Braun's avatar
Matthias Braun committed
325
	ir_graph *irg  = get_irn_irg(p);
Matthias Braun's avatar
Matthias Braun committed
326
327
328
329
	ir_node  *pred = get_Proj_pred(p);
	if (get_irn_mode(pred) != mode_T) {
		warn(p, "predecessor %+F does not have mode_T", p, pred);
		return false;
330
	}
Matthias Braun's avatar
Matthias Braun committed
331
332
333
334
335
336
337
	bool fine = true;
	if (get_irg_pinned(irg) != op_pin_state_floats
	    && get_nodes_block(pred) != get_nodes_block(p)) {
	    warn(p, "different block than predecessor %+F", p, pred);
	    fine = false;
	}
	fine &= verify_node_Proj_fragile(p);
338

Matthias Braun's avatar
Matthias Braun committed
339
	ir_op *op = get_irn_op(pred);
340
	if (op->ops.verify_proj_node)
Matthias Braun's avatar
Matthias Braun committed
341
		fine &= op->ops.verify_proj_node(p);
342

Matthias Braun's avatar
Matthias Braun committed
343
	return fine;
Michael Beck's avatar
Michael Beck committed
344
}
Götz Lindenmaier's avatar
Götz Lindenmaier committed
345

346
static int verify_node_Block(const ir_node *n)
347
{
Matthias Braun's avatar
Matthias Braun committed
348
349
350
	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
351
352
		ir_node *pred         = get_Block_cfgpred(n, i);
		ir_node *skipped_pred = skip_Proj(skip_Tuple(pred));
Matthias Braun's avatar
Matthias Braun committed
353
354
355
356
357
		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;
		}
358
359
	}

Matthias Braun's avatar
Matthias Braun committed
360
361
362
363
364
365
	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)) {
366
		/* End block may only have Return, Raise or fragile ops as preds. */
Matthias Braun's avatar
Matthias Braun committed
367
368
369
370
371
372
373
374
375
376
		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;
			}
377
		}
378
	}
Matthias Braun's avatar
Matthias Braun committed
379
	return fine;
Michael Beck's avatar
Michael Beck committed
380
}
381

382
383
384
385
386
387
static int verify_node_Deleted(const ir_node *n)
{
	warn(n, "Deleted node %+F appears to be reachable");
	return false;
}

388
static int verify_node_Start(const ir_node *n)
389
{
Matthias Braun's avatar
Matthias Braun committed
390
	return check_mode(n, mode_T);
Michael Beck's avatar
Michael Beck committed
391
}
392

393
static int verify_node_Jmp(const ir_node *n)
394
{
Matthias Braun's avatar
Matthias Braun committed
395
	return check_mode(n, mode_X);
Michael Beck's avatar
Michael Beck committed
396
}
397

398
static int verify_node_IJmp(const ir_node *n)
399
{
Matthias Braun's avatar
Matthias Braun committed
400
401
402
	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
403
404
}

405
static int verify_node_Cond(const ir_node *n)
406
{
Matthias Braun's avatar
Matthias Braun committed
407
408
409
	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
410
411
}

Matthias Braun's avatar
Matthias Braun committed
412
static bool verify_switch_table(const ir_node *n)
Matthias Braun's avatar
Matthias Braun committed
413
{
Matthias Braun's avatar
Matthias Braun committed
414
415
416
417
418
	const ir_switch_table *table = get_Switch_table(n);
	if (table == NULL) {
		warn(n, "switch table is NULL");
		return false;
	}
419

Matthias Braun's avatar
Matthias Braun committed
420
421
422
423
424
425
	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
426
427
428
429
		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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
		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) {
			warn(n,
			     "switch table entry %zu min is not lesser or equal than max",
			     e);
			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
449
	}
Matthias Braun's avatar
Matthias Braun committed
450
	return fine;
Matthias Braun's avatar
Matthias Braun committed
451
}
452

Matthias Braun's avatar
Matthias Braun committed
453
454
static int verify_node_Switch(const ir_node *n)
{
Matthias Braun's avatar
Matthias Braun committed
455
456
457
458
	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
459
460
}

461
static int verify_node_Return(const ir_node *n)
462
{
Matthias Braun's avatar
Matthias Braun committed
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
	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);
479
			} else {
Matthias Braun's avatar
Matthias Braun committed
480
				fine &= check_input_func(n, n_Return_max+1+i, NULL, mode_is_reference, "reference");
481
			}
482
483
		}
	}
Matthias Braun's avatar
Matthias Braun committed
484
	return fine;
Michael Beck's avatar
Michael Beck committed
485
486
}

487
static int verify_node_Raise(const ir_node *n)
488
{
Matthias Braun's avatar
Matthias Braun committed
489
490
491
492
	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
493
494
}

495
static int verify_node_Const(const ir_node *n)
496
{
Matthias Braun's avatar
Matthias Braun committed
497
498
499
500
501
502
503
504
505
	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
506
507
}

508
static int verify_node_SymConst(const ir_node *n)
Matthias Braun's avatar
Matthias Braun committed
509
{
Matthias Braun's avatar
Matthias Braun committed
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
	switch (get_SymConst_kind(n)) {
	case symconst_type_size:
	case symconst_type_align:
	case symconst_ofs_ent:
		return check_mode_func(n, mode_is_int, "int");
	case symconst_addr_ent: {
		bool       fine = check_mode_func(n, mode_is_reference, "reference");
		ir_entity *ent  = get_SymConst_entity(n);
		if (!(get_entity_owner(ent)->flags & tf_segment)
		    && !is_method_entity(ent)) {
			warn(n, "symconst_addr_ent entity %+F is not in a segment type but %+F",
			     ent, get_entity_owner(ent));
			fine = false;
		}
		return fine;
	}
526
	}
Matthias Braun's avatar
Matthias Braun committed
527
528
	warn(n, "invalid SymConst kind");
	return false;
Michael Beck's avatar
Michael Beck committed
529
}
530

531
static int verify_node_Sel(const ir_node *n)
532
{
Matthias Braun's avatar
Matthias Braun committed
533
534
535
	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);
536

Matthias Braun's avatar
Matthias Braun committed
537
538
	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");
539
	}
Matthias Braun's avatar
Matthias Braun committed
540
	ir_entity *ent = get_Sel_entity(n);
Matthias Braun's avatar
Matthias Braun committed
541
542
543
544
545
546
547
548
549
	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;
550
551
}

552
static int verify_node_Call(const ir_node *n)
553
{
Matthias Braun's avatar
Matthias Braun committed
554
555
556
	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");
557

Matthias Braun's avatar
Matthias Braun committed
558
	ir_type *mt = get_Call_type(n);
Matthias Braun's avatar
Matthias Braun committed
559
560
561
	if (!is_Method_type(mt)) {
		warn(n, "call_type is not a method type");
		return false;
562
563
	}

Matthias Braun's avatar
Matthias Braun committed
564
565
566
567
568
569
570
	if ((size_t)get_Call_n_params(n) < get_method_n_params(mt)) {
		warn(n, "call has less arguments than method type");
		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;
571
	} else {
Matthias Braun's avatar
Matthias Braun committed
572
573
574
575
576
577
578
579
580
581
		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");
				}
582
			} else {
Matthias Braun's avatar
Matthias Braun committed
583
584
				fine &= check_input_func(n, n_Call_max+1+i, NULL,
				                         mode_is_data, "data");
585
			}
586
587
		}
	}
Matthias Braun's avatar
Matthias Braun committed
588
	return fine;
Michael Beck's avatar
Michael Beck committed
589
}
590

591
static int verify_node_Add(const ir_node *n)
592
{
Matthias Braun's avatar
Matthias Braun committed
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
	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
614
}
615

616
static int verify_node_Sub(const ir_node *n)
617
{
Matthias Braun's avatar
Matthias Braun committed
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
	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");
		} 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
634
}
635

636
static int verify_node_Minus(const ir_node *n)
637
{
Matthias Braun's avatar
Matthias Braun committed
638
639
640
	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
641
}
642

643
static int verify_node_Mul(const ir_node *n)
644
{
Matthias Braun's avatar
Matthias Braun committed
645
646
647
648
	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
649
}
650

651
static int verify_node_Mulh(const ir_node *n)
652
{
Matthias Braun's avatar
Matthias Braun committed
653
654
655
656
	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
657
658
}

659
static int verify_node_Div(const ir_node *n)
660
{
Matthias Braun's avatar
Matthias Braun committed
661
662
663
664
665
666
667
668
669
670
	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
671
}
672

673
static int verify_node_Mod(const ir_node *n)
674
{
Matthias Braun's avatar
Matthias Braun committed
675
676
677
678
679
680
681
682
683
684
	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
685
}
686

Matthias Braun's avatar
Matthias Braun committed
687
688
689
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
690
}
Götz Lindenmaier's avatar
Götz Lindenmaier committed
691

692
693
static int verify_node_And(const ir_node *n)
{
Matthias Braun's avatar
Matthias Braun committed
694
695
696
697
	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;
698
699
700
701
}

static int verify_node_Or(const ir_node *n)
{
Matthias Braun's avatar
Matthias Braun committed
702
703
704
705
	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;
706
707
708
709
}

static int verify_node_Eor(const ir_node *n)
{
Matthias Braun's avatar
Matthias Braun committed
710
711
712
713
	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;
714
}
Götz Lindenmaier's avatar
bugfix    
Götz Lindenmaier committed
715

Matthias Braun's avatar
Matthias Braun committed
716
static int mode_is_intb(const ir_mode *mode)
717
{
Matthias Braun's avatar
Matthias Braun committed
718
719
	return mode_is_int(mode) || mode == mode_b;
}
Michael Beck's avatar
Michael Beck committed
720

Matthias Braun's avatar
Matthias Braun committed
721
722
723
724
725
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
726
}
Michael Beck's avatar
Michael Beck committed
727

728
static int verify_node_Cmp(const ir_node *n)
729
{
Matthias Braun's avatar
Matthias Braun committed
730
	bool fine = check_mode(n, mode_b);
731
732
	fine &= check_input_func(n, n_Cmp_left, "left", mode_is_data, "data");
	fine &= check_input_func(n, n_Cmp_right, "right", mode_is_data, "data");
Matthias Braun's avatar
Matthias Braun committed
733
734
735
736
737
738
739
740
	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
741
}
Michael Beck's avatar
Michael Beck committed
742

Matthias Braun's avatar
Matthias Braun committed
743
744
745
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
746
}
747

748
749
static int verify_node_Shl(const ir_node *n)
{
Matthias Braun's avatar
Matthias Braun committed
750
751
752
753
	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;
754
755
756
757
}

static int verify_node_Shr(const ir_node *n)
{
Matthias Braun's avatar
Matthias Braun committed
758
759
760
761
	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;
762
763
764
765
}

static int verify_node_Shrs(const ir_node *n)
{
Matthias Braun's avatar
Matthias Braun committed
766
767
768
769
	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;
770
}
771

772
static int verify_node_Conv(const ir_node *n)
773
{
Matthias Braun's avatar
Matthias Braun committed
774
775
776
777
	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
778

Matthias Braun's avatar
Matthias Braun committed
779
780
781
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
782
}
783

784
static int verify_node_Phi(const ir_node *n)
785
{
786
787
788
	/* 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
789
790
791
792
793
794
795
796
	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;
797
798
	}

Matthias Braun's avatar
Matthias Braun committed
799
	/* Phi: BB x dataM --> dataM */
Matthias Braun's avatar
Matthias Braun committed
800
801
802
	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);
803
	}
Matthias Braun's avatar
Matthias Braun committed
804
	return fine;
Michael Beck's avatar
Michael Beck committed
805
}
806

807
static int verify_node_Load(const ir_node *n)
808
{
Matthias Braun's avatar
Matthias Braun committed
809
810
811
	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);
812
	if (!irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_BACKEND)) {
Matthias Braun's avatar
Matthias Braun committed
813
		fine &= check_input_func(n, n_Load_ptr, "ptr", mode_is_reference, "reference");
814
	}
Matthias Braun's avatar
Matthias Braun committed
815
816
817
818
819
820
	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
821
822
}

823
static int verify_node_Store(const ir_node *n)
824
{
Matthias Braun's avatar
Matthias Braun committed
825
826
	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
827
	ir_graph *irg = get_irn_irg(n);
828
	if (!irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_BACKEND)) {
Matthias Braun's avatar
Matthias Braun committed
829
		fine &= check_input_func(n, n_Store_ptr, "ptr", mode_is_reference, "reference");
830
	}
Matthias Braun's avatar
Matthias Braun committed
831
832
833
834
835
836
	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
837
838
}

839
static int verify_node_Alloc(const ir_node *n)
840
{
Matthias Braun's avatar
Matthias Braun committed
841
842
843
844
	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
845
846
}

847
static int verify_node_Free(const ir_node *n)
848
{
Matthias Braun's avatar
Matthias Braun committed
849
850
851
852
	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
853
854
}

855
static int verify_node_Sync(const ir_node *n)
856
{
Matthias Braun's avatar
Matthias Braun committed
857
858
859
	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);
860
	}
Matthias Braun's avatar
Matthias Braun committed
861
	return fine;
Michael Beck's avatar
Michael Beck committed
862
863
}

864
static int verify_node_Confirm(const ir_node *n)
865
{
Matthias Braun's avatar
Matthias Braun committed
866
867
868
	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
869
870
}

871
static int verify_node_Mux(const ir_node *n)
872
{
873
	bool fine = check_mode_func(n, mode_is_data, "data or mode_b");
Matthias Braun's avatar
Matthias Braun committed
874
875
876
877
	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
878
879
}

880
static int verify_node_CopyB(const ir_node *n)
881
{
Matthias Braun's avatar
Matthias Braun committed
882
883
	bool      fine = check_mode(n, mode_M);
	ir_graph *irg  = get_irn_irg(n);
884
	if (!irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_BACKEND)) {
Matthias Braun's avatar
Matthias Braun committed
885
886
		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");
887
	}
Matthias Braun's avatar
Matthias Braun committed
888
889
890
891
892
893
	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
894
895
}

896
/**
Sebastian Hack's avatar
Sebastian Hack committed
897
898
899
900
 * 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).
901
 *
Matthias Braun's avatar
Matthias Braun committed
902
 * @return true on success, false on dominance error
Sebastian Hack's avatar
Sebastian Hack committed
903
 */
Matthias Braun's avatar
Matthias Braun committed
904
static bool check_dominance_for_node(const ir_node *use)
905
{
Matthias Braun's avatar
Matthias Braun committed
906
	bool fine = true;
907
	/* This won't work for blocks and the end node */
Matthias Braun's avatar
Matthias Braun committed
908
909
910
911
912
913
914
915
916
917
918
919
920
	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; ) {
		ir_node *def = get_irn_n(use, i);
		if (is_Bad(def))
			continue;
		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;
921

Matthias Braun's avatar
Matthias Braun committed
922
923
924
925
926
927
928
929
930
		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)) {
			warn(use, "not dominated by operand %+F", use, def);
			fine = false;
931
932
		}
	}
Matthias Braun's avatar
Matthias Braun committed
933
934
935
	return fine;
}

936
#ifdef DEBUG_libfirm
Matthias Braun's avatar
Matthias Braun committed
937
938
939
940
941
942
943
944
945
946
/**
 * 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;
947
}
948
#endif
Sebastian Hack's avatar
Sebastian Hack committed
949

950
int irn_verify_irg(const ir_node *n, ir_graph *irg)
951
{
Matthias Braun's avatar
Matthias Braun committed
952
953
954
955
956
	/* early abort if we have an irg mismatch */
	if (get_irn_irg(n) != irg) {
		warn(n, "get_irn_irg() != %+F", irg);
		return false;
	}
957

Matthias Braun's avatar
Matthias Braun committed
958
959
960
961
	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 */
962
#ifdef DEBUG_libfirm
Matthias Braun's avatar
Matthias Braun committed
963
	fine &= check_irn_storage(irg, n);
964
#endif
Matthias Braun's avatar
Matthias Braun committed
965
	/* abort if idx map is corrupt */
Matthias Braun's avatar
Matthias Braun committed
966
967
	unsigned idx           = get_irn_idx(n);
	ir_node *node_from_map = get_idx_irn(irg, idx);
Matthias Braun's avatar
Matthias Braun committed
968
969
970
971
	if (node_from_map != n) {
		warn(n, "node index and index map entry differ");
		return false;
	}
Michael Beck's avatar
Michael Beck committed
972

Matthias Braun's avatar
Matthias Braun committed
973
	ir_op *op = get_irn_op(n);
Matthias Braun's avatar
Matthias Braun committed
974
975
976
977
978
979
980
981
982
983
984
985
	if (op != op_Block && op != op_Anchor) {
		ir_node *block = get_nodes_block(n);
		if (!is_Block(block) && (!is_Bad(block)
		    || !irg_has_properties(irg, IR_GRAPH_PROPERTY_NO_BADS))) {
			warn(n, "block input is not a block (but %+F)", block);
		    fine = false;
		} else if (is_op_start_block_placed(op)
		           && block != get_irg_start_block(irg)) {
			warn(n, "not placed in start block");
			fine = false;
		}
	}
986
	if (get_op_pinned(op) >= op_pin_state_exc_pinned) {
987
		op_pin_state state = get_irn_pinned(n);
Matthias Braun's avatar
Matthias Braun committed
988
989
990
991
992
		if (state != op_pin_state_floats && state != op_pin_state_pinned) {
			warn(n, "invalid pin state (%d)", (int)state);
			fine = false;
		}
	}
993

Matthias Braun's avatar
Matthias Braun committed
994
995
	if (op->ops.verify_node != NULL)
		fine &= op->ops.verify_node(n);
Michael Beck's avatar
Michael Beck committed
996

Matthias Braun's avatar
Matthias Braun committed
997
	return fine;
Christian Schäfer's avatar
Christian Schäfer committed
998
999
}

1000
int irn_verify(const ir_node *n)
Christoph Mallon's avatar