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
279
280
281
282
283
284
	# TODO: attribute with call...
	attr_struct   = "callbegin_attr",
	java_noconstr = True,
	init = '''
	res->attr.callbegin.call = call;
	''',
),

285
Carry = dict(
286
287
	is_a     = "binop",
	flags    = "commutative",
288
289
),

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

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

311
312
313
Cond = dict(
	ins      = [ "selector" ],
	outs     = [ "false", "true" ],
314
	flags    = "cfopcode, forking",
315
	pinned   = "yes",
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
	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"
		)
332
333
	],
	attr_struct = "cond_attr"
334
335
),

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

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

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

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

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

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

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

463
464
End = dict(
	mode       = "mode_X",
465
	pinned     = "yes",
466
	arity      = "dynamic",
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
	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
485
486
487
),

Eor = dict(
488
489
	is_a     = "binop",
	flags    = "commutative",
490
491
),

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

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

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

528
Id = dict(
529
530
531
	ins    = [ "pred" ],
	pinned = "no",
	flags  = "none",
532
533
534
535
),

IJmp = dict(
	mode     = "mode_X",
536
	pinned   = "yes",
537
	ins      = [ "target" ],
538
	flags    = "cfopcode, forking, keep",
539
540
),

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

556
557
Jmp = dict(
	mode     = "mode_X",
558
	pinned   = "yes",
559
	ins      = [],
560
	flags    = "cfopcode",
561
562
),

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

590
Minus = dict(
591
592
	is_a     = "unop",
	flags    = "none",
593
594
595
),

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

617
Mul = dict(
618
619
	is_a     = "binop",
	flags    = "commutative",
620
621
622
),

Mulh = dict(
623
624
	is_a     = "binop",
	flags    = "commutative",
625
626
627
),

Mux = dict(
628
629
630
	ins    = [ "sel", "false", "true" ],
	flags  = "none",
	pinned = "no",
631
632
633
634
),

NoMem = dict(
	mode       = "mode_M",
635
	flags      = "dump_noblock, dump_noinput",
636
	pinned     = "yes",
637
	knownBlock = True,
638
	singleton  = True,
639
640
),

641
Not = dict(
642
643
	is_a     = "unop",
	flags    = "none",
644
645
646
),

Or = dict(
647
648
	is_a     = "binop",
	flags    = "commutative",
649
650
651
),

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

Pin = dict(
	ins      = [ "op" ],
662
663
	mode     = "get_irn_mode(irn_op)",
	flags    = "highlevel",
664
	pinned   = "yes",
665
666
667
668
),

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

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

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

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

719
Rotl = dict(
720
721
	is_a     = "binop",
	flags    = "none",
722
723
),

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

739
Shl = dict(
740
741
	is_a     = "binop",
	flags    = "none",
742
743
),

744
Shr = dict(
745
746
	is_a     = "binop",
	flags    = "none",
747
748
),

749
Shrs = dict(
750
751
	is_a     = "binop",
	flags    = "none",
752
753
),

754
755
Start = dict(
	mode       = "mode_T",
756
	pinned     = "yes",
757
758
	flags      = "cfopcode",
	singleton  = True,
759
760
),

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

781
Sub = dict(
782
783
	is_a     = "binop",
	flags    = "none",
784
785
),

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

801
802
Sync = dict(
	mode     = "mode_M",
803
	flags    = "none",
804
	pinned   = "no",
805
806
	optimize = False,
	arity    = "dynamic"
807
808
),

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

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