ir_spec.py 14.7 KB
Newer Older
1
nodes = dict(
2
3
4
5
6
7

#
# Abstract node types
#
unop = dict(
	abstract = True,
8
9
	ins      = [ "op" ],
	op_index = 0,
10
	pinned   = "no",
11
12
),

13
14
binop = dict(
	abstract = True,
15
16
	ins      = [ "left", "right" ],
	op_index = 0,
17
	pinned   = "no",
18
19
),

20
21
22
23
#
# Real node types
#
Abs = dict(
24
25
	is_a     = "unop",
	flags    = "none",
26
27
),

28
Add = dict(
29
30
	is_a     = "binop",
	flags    = "commutative",
31
32
),

33
34
35
Alloc = dict(
	ins   = [ "mem", "size" ],
	outs  = [ "M", "X_regular", "X_except", "res" ],
36
	flags = "fragile, uses_memory",
37
38
39
40
41
42
43
44
45
	attrs = [
		dict(
			name = "type",
			type = "ir_type*"
		),
		dict(
			name = "where",
			type = "ir_where_alloc"
		)
46
	],
47
	pinned      = "yes",
48
	attr_struct = "alloc_attr",
49
50
51
52
53
	d_post = '''
	#if PRECISE_EXC_CONTEXT
	firm_alloc_frag_arr(res, op_Alloc, &res->attr.alloc.exc.frag_arr);
	#endif
	'''
54
55
),

56
Anchor = dict(
57
58
59
	mode        = "mode_ANY",
	arity       = "variable",
	flags       = "dump_noblock",
60
	pinned      = "yes",
61
62
	knownBlock  = True,
	singleton   = True,
63
64
),

65
And = dict(
66
67
68
69
70
71
72
73
74
75
	is_a     = "binop",
	flags    = "commutative",
),

ASM = dict(
	mode          = "mode_T",
	arity         = "variable",
	flags         = "keep, uses_memory",
	attr_struct   = "asm_attr",
	pinned        = "memory",
76
	pinned_init   = "op_pin_state_pinned",
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
	attrs = [
		dict(
			name = "input_constraints",
			type = "ir_asm_constraint*",
		),
		dict(
			name = "n_output_constraints",
			type = "int",
		),
		dict(
			name = "output_constraints",
			type = "ir_asm_constraint*",
		),
		dict(
			name = "n_clobbers",
			type = "int",
		),
		dict(
			name = "clobbers",
			type = "ident**",
		),
		dict(
			name = "text",
			type = "ident*",
		),
	],
	java_noconstr = True,
104
105
106
107
),

Bad = dict(
	mode       = "mode_Bad",
108
	flags      = "cfopcode, fragile, start_block, dump_noblock",
109
	pinned     = "yes",
110
	knownBlock = True,
111
	singleton  = True,
112
113
114
),

Block = dict(
115
116
117
	mode        = "mode_BB",
	knownBlock  = True,
	block       = "NULL",
118
	pinned      = "yes",
119
120
121
122
	optimize    = False,
	arity       = "variable",
	flags       = "labeled",
	attr_struct = "block_attr",
123
	java_noconstr = True,
Moritz Kroll's avatar
Moritz Kroll committed
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143

	init = '''
	/* macroblock header */
	res->in[0] = res;

	res->attr.block.is_dead     = 0;
	res->attr.block.is_mb_head  = 1;
	res->attr.block.has_label   = 0;
	res->attr.block.irg         = irg;
	res->attr.block.backedge    = new_backedge_arr(irg->obst, arity);
	res->attr.block.in_cg       = NULL;
	res->attr.block.cg_backedge = NULL;
	res->attr.block.extblk      = NULL;
	res->attr.block.mb_depth    = 0;
	res->attr.block.label       = 0;

	set_Block_matured(res, 1);
	set_Block_block_visited(res, 0);
	''',

144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
	d_pre = '''
	int i;
	int has_unknown = 0;
	''',

	d_post = '''
	/* Create and initialize array for Phi-node construction. */
	if (get_irg_phase_state(current_ir_graph) == phase_building) {
		res->attr.block.graph_arr = NEW_ARR_D(ir_node *, current_ir_graph->obst,
		                                      current_ir_graph->n_loc);
		memset(res->attr.block.graph_arr, 0, sizeof(ir_node *)*current_ir_graph->n_loc);
	}

	for (i = arity - 1; i >= 0; i--)
		if (is_Unknown(in[i])) {
			has_unknown = 1;
			break;
		}

	if (!has_unknown) res = optimize_node(res);

Moritz Kroll's avatar
Moritz Kroll committed
165
166
	current_ir_graph->current_block = res;

167
168
169
	IRN_VRFY_IRG(res, current_ir_graph);
	''',

170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
	java_add   = '''
	public void addPred(Node node) {
		binding_cons.add_immBlock_pred(ptr, node.ptr);
	}

	public void mature() {
		binding_cons.mature_immBlock(ptr);
	}

	@Override
	public Block getBlock() {
		return null;
	}

	public boolean blockVisited() {
		return 0 != binding.Block_block_visited(ptr);
	}

	public void markBlockVisited() {
		binding.mark_Block_block_visited(ptr);
190
191
192
193
194
195
	}

	public boolean isBad() {
		return binding.is_Bad(ptr) != 0;
	}
	''',
196
197
),

198
Borrow = dict(
199
200
	is_a     = "binop",
	flags    = "none",
201
202
),

203
Bound = dict(
204
205
	ins    = [ "mem", "index", "lower", "upper" ],
 	outs   = [ "M", "X_regular", "X_except", "res" ],
206
 	flags  = "fragile, highlevel",
207
	pinned = "exception",
208
	pinned_init = "op_pin_state_pinned",
209
	attr_struct = "bound_attr",
210
211
212
213
214
215
216
	d_post = '''
	#if PRECISE_EXC_CONTEXT
	firm_alloc_frag_arr(res, op_Bound, &res->attr.bound.exc.frag_arr);
	#endif
	'''
),

217
Break = dict(
218
219
220
	mode   = "mode_X",
	flags  = "cfopcode",
	pinned = "yes",
221
222
),

223
224
Builtin = dict(
	ins      = [ "mem" ],
225
226
	arity    = "variable",
	outs     = [ "M_regular", "X_regular", "X_except", "T_result", "M_except", "P_value_res_base" ],
227
	flags    = "uses_memory",
228
	attrs    = [
229
230
231
232
		dict(
			type = "ir_builtin_kind",
			name = "kind"
		),
233
		dict(
234
235
236
			type = "ir_type*",
			name = "type"
		)
237
	],
238
	pinned      = "memory",
239
240
	pinned_init = "op_pin_state_pinned",
	attr_struct = "builtin_attr",
241
	init   = '''
242
243
244
245
	assert((get_unknown_type() == type) || is_Method_type(type));
	'''

	# TODO: No firm_alloc_frag_arr??
246
247
),

248
249
Call = dict(
	ins      = [ "mem", "ptr" ],
250
251
	arity    = "variable",
	outs     = [ "M_regular", "X_regular", "X_except", "T_result", "M_except", "P_value_res_base" ],
252
	flags    = "fragile, uses_memory",
253
	attrs    = [
254
255
256
		dict(
			type = "ir_type*",
			name = "type"
257
		)
258
	],
259
	attr_struct = "call_attr",
260
	pinned      = "memory",
261
	pinned_init = "op_pin_state_pinned",
262
263
264
265
266
267
268
269
	init = '''
	assert((get_unknown_type() == type) || is_Method_type(type));
	''',
	d_post = '''
	#if PRECISE_EXC_CONTEXT
	firm_alloc_frag_arr(res, op_Call, &res->attr.call.exc.frag_arr);
	#endif
	'''
270
271
),

272
273
274
275
CallBegin = dict(
	ins   = [ "ptr" ],
	outs  = [ "" ], # TODO
	flags         = "cfopcode, ip_cfopcode",
276
	pinned        = "yes",
277
278
	# TODO: attribute with call...
	attr_struct   = "callbegin_attr",
279
280
281
282
283
284
	attrs         = [
		dict(
			type = "ir_node*",
			name = "call"
		)
	],
285
286
287
	java_noconstr = True,
),

288
Carry = dict(
289
290
	is_a     = "binop",
	flags    = "commutative",
291
292
),

293
294
295
Cast = dict(
	ins      = [ "op" ],
	mode     = "get_irn_mode(irn_op)",
296
	flags    = "highlevel",
297
	pinned   = "no",
298
299
300
301
302
303
	attrs    = [
		dict(
			type = "ir_type*",
			name = "type"
		)
	],
304
	attr_struct = "cast_attr",
305
306
307
	init     = "assert(is_atomic_type(type));"
),

308
309
310
Cmp = dict(
	is_a     = "binop",
	outs     = [ "False", "Eq", "Lt", "Le", "Gt", "Ge", "Lg", "Leg", "Uo", "Ue", "Ul", "Ule", "Ug", "Uge", "Ne", "True" ],
311
	flags    = "none",
312
313
),

314
315
316
Cond = dict(
	ins      = [ "selector" ],
	outs     = [ "false", "true" ],
317
	flags    = "cfopcode, forking",
318
	pinned   = "yes",
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
	attrs    = [
		dict(
			name = "kind",
			type = "cond_kind",
			init = "dense"
		),
		dict(
			name = "default_proj",
			type = "long",
			init = "0"
		),
		dict(
			name = "jmp_pred",
			type = "cond_jmp_predicate",
			init = "COND_JMP_PRED_NONE"
		)
335
336
	],
	attr_struct = "cond_attr"
337
338
),

339
340
341
Confirm = dict(
	ins      = [ "value", "bound" ],
	mode     = "get_irn_mode(irn_value)",
342
	flags    = "highlevel",
343
	pinned   = "yes",
344
345
346
347
348
349
	attrs    = [
		dict(
			name = "cmp",
			type = "pn_Cmp"
		),
	],
350
	attr_struct = "confirm_attr",
351
352
),

353
354
Const = dict(
	mode       = "",
355
	flags      = "constlike, start_block",
356
	knownBlock = True,
357
	pinned     = "no",
358
359
360
361
362
363
364
	attrs_name = "con",
	attrs      = [
		dict(
			type = "tarval*",
			name = "tarval",
		)
	],
365
	attr_struct = "const_attr",
366
367
),

368
369
Conv = dict(
	is_a     = "unop",
370
	flags    = "none",
371
372
373
374
375
376
377
378
379
380
	attrs = [
		dict(
			name = "strict",
			type = "int",
			init = "0",
			special = dict(
				prefix = "strict",
				init = "1"
			)
		)
381
382
	],
	attr_struct = "conv_attr",
383
384
),

385
386
387
CopyB = dict(
	ins   = [ "mem", "dst", "src" ],
	outs  = [ "M", "X_regular", "X_except" ],
388
	flags = "fragile, highlevel, uses_memory",
389
390
	attrs = [
		dict(
391
392
			name = "type",
			type = "ir_type*"
393
		)
394
	],
395
	attr_struct = "copyb_attr",
396
	pinned      = "memory",
397
	pinned_init = "op_pin_state_pinned",
398
399
400
401
402
	d_post = '''
	#if PRECISE_EXC_CONTEXT
	firm_alloc_frag_arr(res, op_CopyB, &res->attr.copyb.exc.frag_arr);
	#endif
	'''
403
404
),

405
Div = dict(
406
	ins   = [ "mem", "left", "right" ],
407
	outs  = [ "M", "X_regular", "X_except", "res" ],
408
	flags = "fragile, uses_memory",
409
	attrs_name = "divmod",
410
411
412
413
414
	attrs = [
		dict(
			type = "ir_mode*",
			name = "resmode"
		),
Moritz Kroll's avatar
Moritz Kroll committed
415
416
417
418
419
420
421
422
		dict(
			name = "no_remainder",
			type = "int",
			init = "0",
			special = dict(
				suffix = "RL",
				init = "1"
			)
423
		)
424
	],
425
	attr_struct = "divmod_attr",
426
427
	pinned      = "exception",
	op_index    = 1,
428
	arity_override = "oparity_binary",
429
430
431
432
433
	d_post = '''
	#if PRECISE_EXC_CONTEXT
	firm_alloc_frag_arr(res, op_Div, &res->attr.except.frag_arr);
	#endif
	'''
434
435
436
),

DivMod = dict(
437
	ins   = [ "mem", "left", "right" ],
438
	outs  = [ "M", "X_regular", "X_except", "res_div", "res_mod" ],
439
	flags = "fragile, uses_memory",
440
	attrs_name = "divmod",
441
442
443
444
445
	attrs = [
		dict(
			type = "ir_mode*",
			name = "resmode"
		),
446
	],
447
	attr_struct = "divmod_attr",
448
449
	pinned      = "exception",
	op_index    = 1,
450
	arity_override = "oparity_binary",
451
452
453
454
455
	d_post = '''
	#if PRECISE_EXC_CONTEXT
	firm_alloc_frag_arr(res, op_DivMod, &res->attr.except.frag_arr);
	#endif
	'''
456
457
),

458
459
460
461
Dummy = dict(
	ins   = [],
	flags = "cfopcode, fragile, start_block, constlike, dump_noblock",
	knownBlock = True,
462
	pinned     = "yes",
463
464
465
	block      = "get_irg_start_block(irg)",
),

466
467
End = dict(
	mode       = "mode_X",
468
	pinned     = "yes",
469
	arity      = "dynamic",
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
	flags      = "cfopcode",
	singleton  = True,
),

EndExcept = dict(
	mode      = "mode_X",
	pinned    = "yes",
	arity     = "dynamic",
	flags     = "cfopcode, ip_cfopcode",
	singleton = True
),

EndReg = dict(
	mode      = "mode_X",
	pinned    = "yes",
	arity     = "dynamic",
	flags     = "cfopcode, ip_cfopcode",
	singleton = True
488
489
490
),

Eor = dict(
491
492
	is_a     = "binop",
	flags    = "commutative",
493
494
),

495
496
Filter = dict(
	ins   = [ "pred" ],
497
	flags = "none",
498
499
500
501
502
	attrs = [
		dict(
			name = "proj",
			type = "long"
		)
503
	],
504
	pinned      = "yes",
505
506
	attr_struct = "filter_attr",
	java_noconstr = True
507
508
509
510
511
512

	# TODO: Broken asserts in original:
	# assert(get_Proj_pred(res));
	# assert(get_nodes_block(get_Proj_pred(res)));
),

513
Free = dict(
514
515
516
517
518
	ins    = [ "mem", "ptr", "size" ],
	mode   = "mode_M",
	flags  = "uses_memory",
	pinned = "yes",
	attrs  = [
519
		dict(
520
521
			name = "type",
			type = "ir_type*"
522
523
		),
		dict(
524
525
			name = "where",
			type = "ir_where_alloc"
526
		)
527
528
	],
	attr_struct = "free_attr",
529
530
),

531
Id = dict(
532
533
534
	ins    = [ "pred" ],
	pinned = "no",
	flags  = "none",
535
536
537
538
),

IJmp = dict(
	mode     = "mode_X",
539
	pinned   = "yes",
540
	ins      = [ "target" ],
541
	flags    = "cfopcode, forking, keep",
542
543
),

544
InstOf = dict(
545
	ins   = [ "store", "obj" ],
546
	outs  = [ "M", "X_regular", "X_except", "res", "M_except" ],
547
	flags = "highlevel",
548
549
550
551
552
	attrs = [
		dict(
			name = "type",
			type = "ir_type*"
		)
553
	],
554
	attr_struct = "io_attr",
555
	pinned      = "memory",
556
	pinned_init = "op_pin_state_floats",
557
558
),

559
560
Jmp = dict(
	mode     = "mode_X",
561
	pinned   = "yes",
562
	ins      = [],
563
	flags    = "cfopcode",
564
565
),

566
567
568
Load = dict(
	ins      = [ "mem", "ptr" ],
	outs     = [ "M", "X_regular", "X_except", "res" ],
569
	flags    = "fragile, uses_memory",
570
571
	pinned   = "exception",
	pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned",
572
573
574
575
576
577
578
	attrs    = [
		dict(
			type = "ir_mode*",
			name = "mode",
			java_name = "load_mode"
		),
	],
579
	attr_struct = "load_attr",
580
581
	constructor_args = [
		dict(
Moritz Kroll's avatar
Moritz Kroll committed
582
			type = "ir_cons_flags",
583
584
585
			name = "flags",
		),
	],
586
587
588
589
590
	d_post = '''
#if PRECISE_EXC_CONTEXT
	firm_alloc_frag_arr(res, op_Load, &res->attr.load.exc.frag_arr);
#endif
	'''
591
592
),

593
Minus = dict(
594
595
	is_a     = "unop",
	flags    = "none",
596
597
598
),

Mod = dict(
599
	ins   = [ "mem", "left", "right" ],
600
	outs  = [ "M", "X_regular", "X_except", "res" ],
601
	flags = "fragile, uses_memory",
602
	attrs_name = "divmod",
603
	attrs = [
604
		dict(
605
606
			type = "ir_mode*",
			name = "resmode"
607
		),
608
	],
609
	attr_struct = "divmod_attr",
610
611
	pinned      = "exception",
	op_index    = 1,
612
	arity_override = "oparity_binary",
613
614
615
616
617
	d_post = '''
	#if PRECISE_EXC_CONTEXT
	firm_alloc_frag_arr(res, op_Mod, &res->attr.except.frag_arr);
	#endif
	'''
618
619
),

620
Mul = dict(
621
622
	is_a     = "binop",
	flags    = "commutative",
623
624
625
),

Mulh = dict(
626
627
	is_a     = "binop",
	flags    = "commutative",
628
629
630
),

Mux = dict(
631
632
633
	ins    = [ "sel", "false", "true" ],
	flags  = "none",
	pinned = "no",
634
635
636
637
),

NoMem = dict(
	mode       = "mode_M",
638
	flags      = "dump_noblock, dump_noinput",
639
	pinned     = "yes",
640
	knownBlock = True,
641
	singleton  = True,
642
643
),

644
Not = dict(
645
646
	is_a     = "unop",
	flags    = "none",
647
648
649
),

Or = dict(
650
651
	is_a     = "binop",
	flags    = "commutative",
652
653
654
),

Phi = dict(
655
656
657
658
659
660
	pinned      = "yes",
	arity       = "variable",
	flags       = "none",
	attr_struct = "phi_attr",
	custom_is   = True,
	java_noconstr = True,
661
662
663
664
),

Pin = dict(
	ins      = [ "op" ],
665
666
	mode     = "get_irn_mode(irn_op)",
	flags    = "highlevel",
667
	pinned   = "yes",
668
669
670
671
),

Proj = dict(
	ins      = [ "pred" ],
672
	flags    = "none",
673
	pinned   = "no",
674
675
676
	attrs    = [
		dict(
			type = "long",
677
678
			name = "proj",
			initname = ""
679
		)
680
681
682
	],
	attr_struct = "long",
	custom_is   = True,
683
684
),

685
Quot = dict(
686
	ins   = [ "mem", "left", "right" ],
687
	outs  = [ "M", "X_regular", "X_except", "res" ],
688
	flags = "fragile, uses_memory",
689
	attrs_name = "divmod",
690
	attrs = [
691
		dict(
692
693
694
			type = "ir_mode*",
			name = "resmode"
		),
695
	],
696
	attr_struct = "divmod_attr",
697
698
	pinned      = "exception",
	op_index    = 1,
699
	arity_override = "oparity_binary",
700
701
702
703
704
	d_post = '''
	#if PRECISE_EXC_CONTEXT
	firm_alloc_frag_arr(res, op_Quot, &res->attr.except.frag_arr);
	#endif
	'''
705
706
),

707
Raise = dict(
708
709
710
711
	ins    = [ "mem", "exo_ptr" ],
	outs   = [ "M", "X" ],
	flags  = "highlevel, cfopcode",
	pinned = "yes",
712
713
),

714
715
Return = dict(
	ins      = [ "mem" ],
716
	arity    = "variable",
717
718
	mode     = "mode_X",
	flags    = "cfopcode",
719
	pinned   = "yes",
720
721
),

722
Rotl = dict(
723
724
	is_a     = "binop",
	flags    = "none",
725
726
),

727
728
729
Sel = dict(
	ins    = [ "mem", "ptr" ],
	arity  = "variable",
730
	flags  = "none",
731
	mode   = "is_Method_type(get_entity_type(entity)) ? mode_P_code : mode_P_data",
732
733
	pinned = "no",
	attrs  = [
734
		dict(
735
736
737
			type = "ir_entity*",
			name = "entity"
		)
738
739
	],
	attr_struct = "sel_attr",
740
741
),

742
Shl = dict(
743
744
	is_a     = "binop",
	flags    = "none",
745
746
),

747
Shr = dict(
748
749
	is_a     = "binop",
	flags    = "none",
750
751
),

752
Shrs = dict(
753
754
	is_a     = "binop",
	flags    = "none",
755
756
),

757
758
Start = dict(
	mode       = "mode_T",
759
	pinned     = "yes",
760
761
	flags      = "cfopcode",
	singleton  = True,
762
763
),

764
765
766
Store = dict(
	ins      = [ "mem", "ptr", "value" ],
	outs     = [ "M", "X_regular", "X_except" ],
767
	flags    = "fragile, uses_memory",
768
	pinned   = "exception",
769
	attr_struct = "store_attr",
770
	pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned",
771
	constructor_args = [
772
		dict(
773
774
			type = "ir_cons_flags",
			name = "flags",
775
		),
776
777
778
779
780
781
	],
	d_post = '''
#if PRECISE_EXC_CONTEXT
	firm_alloc_frag_arr(res, op_Store, &res->attr.store.exc.frag_arr);
#endif
	'''
782
783
),

784
Sub = dict(
785
786
	is_a     = "binop",
	flags    = "none",
787
788
),

789
790
SymConst = dict(
	mode       = "mode_P",
791
	flags      = "constlike, start_block",
792
	knownBlock = True,
793
	pinned     = "no",
794
	attrs      = [
795
		dict(
796
797
			type = "ir_entity*",
			name = "entity"
798
		)
799
	],
800
801
	attr_struct = "symconst_attr",
	java_noconstr = True,
802
803
),

804
805
Sync = dict(
	mode     = "mode_M",
806
	flags    = "none",
807
	pinned   = "no",
808
809
	optimize = False,
	arity    = "dynamic"
810
811
),

812
Tuple = dict(
813
814
815
816
	arity  = "variable",
	mode   = "mode_T",
	pinned = "no",
	flags  = "labeled",
817
	java_noconstr = True
818
),
Moritz Kroll's avatar
Moritz Kroll committed
819

820
821
Unknown = dict(
	knownBlock = True,
822
	pinned     = "yes",
823
	block      = "get_irg_start_block(irg)",
824
	flags      = "cfopcode, fragile, start_block, constlike, dump_noblock",
Moritz Kroll's avatar
Moritz Kroll committed
825
),
826
)