ir_spec.py 15 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
),

Bad = dict(
107
108
109
110
111
112
113
114
115
	mode        = "mode_Bad",
	flags       = "cfopcode, fragile, start_block, dump_noblock",
	pinned      = "yes",
	attr_struct = "irg_attr",
	knownBlock  = True,
	singleton   = True,
	init = '''
	res->attr.irg.irg = irg;
	''',
116
117
118
),

Block = dict(
119
120
121
	mode        = "mode_BB",
	knownBlock  = True,
	block       = "NULL",
122
	pinned      = "yes",
123
124
125
126
	optimize    = False,
	arity       = "variable",
	flags       = "labeled",
	attr_struct = "block_attr",
127
	java_noconstr = True,
Moritz Kroll's avatar
Moritz Kroll committed
128
129
130
131
132
133
134

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

	res->attr.block.is_dead     = 0;
	res->attr.block.is_mb_head  = 1;
135
	res->attr.block.irg.irg     = irg;
Moritz Kroll's avatar
Moritz Kroll committed
136
137
138
139
140
	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;
141
	res->attr.block.entity      = NULL;
Moritz Kroll's avatar
Moritz Kroll committed
142
143
144
145
146

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

147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
	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
168
169
	current_ir_graph->current_block = res;

170
171
172
	IRN_VRFY_IRG(res, current_ir_graph);
	''',

173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
	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);
193
194
195
196
197
198
	}

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

201
Borrow = dict(
202
203
	is_a     = "binop",
	flags    = "none",
204
205
),

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

220
Break = dict(
221
222
223
	mode   = "mode_X",
	flags  = "cfopcode",
	pinned = "yes",
224
225
),

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

	# TODO: No firm_alloc_frag_arr??
249
250
),

251
252
Call = dict(
	ins      = [ "mem", "ptr" ],
253
254
	arity    = "variable",
	outs     = [ "M_regular", "X_regular", "X_except", "T_result", "M_except", "P_value_res_base" ],
255
	flags    = "fragile, uses_memory",
256
	attrs    = [
257
258
259
		dict(
			type = "ir_type*",
			name = "type"
260
		)
261
	],
262
	attr_struct = "call_attr",
263
	pinned      = "memory",
264
	pinned_init = "op_pin_state_pinned",
265
266
267
268
269
270
271
272
	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
	'''
273
274
),

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

291
Carry = dict(
292
293
	is_a     = "binop",
	flags    = "commutative",
294
295
),

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

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

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

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

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

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

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

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

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

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

469
470
End = dict(
	mode       = "mode_X",
471
	pinned     = "yes",
472
	arity      = "dynamic",
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
	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
491
492
493
),

Eor = dict(
494
495
	is_a     = "binop",
	flags    = "commutative",
496
497
),

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

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

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

534
Id = dict(
535
536
537
	ins    = [ "pred" ],
	pinned = "no",
	flags  = "none",
538
539
540
541
),

IJmp = dict(
	mode     = "mode_X",
542
	pinned   = "yes",
543
	ins      = [ "target" ],
544
	flags    = "cfopcode, forking, keep",
545
546
),

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

562
563
Jmp = dict(
	mode     = "mode_X",
564
	pinned   = "yes",
565
	ins      = [],
566
	flags    = "cfopcode",
567
568
),

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

596
Minus = dict(
597
598
	is_a     = "unop",
	flags    = "none",
599
600
601
),

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

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

Mulh = dict(
629
630
	is_a     = "binop",
	flags    = "commutative",
631
632
633
),

Mux = dict(
634
635
636
	ins    = [ "sel", "false", "true" ],
	flags  = "none",
	pinned = "no",
637
638
639
640
),

NoMem = dict(
	mode       = "mode_M",
641
	flags      = "dump_noblock, dump_noinput",
642
	pinned     = "yes",
643
	knownBlock = True,
644
	singleton  = True,
645
646
),

647
Not = dict(
648
649
	is_a     = "unop",
	flags    = "none",
650
651
652
),

Or = dict(
653
654
	is_a     = "binop",
	flags    = "commutative",
655
656
657
),

Phi = dict(
658
659
660
661
662
663
	pinned      = "yes",
	arity       = "variable",
	flags       = "none",
	attr_struct = "phi_attr",
	custom_is   = True,
	java_noconstr = True,
Matthias Braun's avatar
Matthias Braun committed
664
665
666
667
668
669
670

	init = '''
	/* Memory Phis in endless loops must be kept alive.
	   As we can't distinguish these easily we keep all of them alive. */
   	if (is_Phi(res) && mode == mode_M)
		add_End_keepalive(get_irg_end(irg), res);
	'''
671
672
673
674
),

Pin = dict(
	ins      = [ "op" ],
675
676
	mode     = "get_irn_mode(irn_op)",
	flags    = "highlevel",
677
	pinned   = "yes",
678
679
680
681
),

Proj = dict(
	ins      = [ "pred" ],
682
	flags    = "none",
683
	pinned   = "no",
684
685
686
	attrs    = [
		dict(
			type = "long",
687
688
			name = "proj",
			initname = ""
689
		)
690
691
692
	],
	attr_struct = "long",
	custom_is   = True,
693
694
),

695
Quot = dict(
696
	ins   = [ "mem", "left", "right" ],
697
	outs  = [ "M", "X_regular", "X_except", "res" ],
698
	flags = "fragile, uses_memory",
699
	attrs_name = "divmod",
700
	attrs = [
701
		dict(
702
703
704
			type = "ir_mode*",
			name = "resmode"
		),
705
	],
706
	attr_struct = "divmod_attr",
707
708
	pinned      = "exception",
	op_index    = 1,
709
	arity_override = "oparity_binary",
710
711
712
713
714
	d_post = '''
	#if PRECISE_EXC_CONTEXT
	firm_alloc_frag_arr(res, op_Quot, &res->attr.except.frag_arr);
	#endif
	'''
715
716
),

717
Raise = dict(
718
719
720
721
	ins    = [ "mem", "exo_ptr" ],
	outs   = [ "M", "X" ],
	flags  = "highlevel, cfopcode",
	pinned = "yes",
722
723
),

724
725
Return = dict(
	ins      = [ "mem" ],
726
	arity    = "variable",
727
728
	mode     = "mode_X",
	flags    = "cfopcode",
729
	pinned   = "yes",
730
731
),

732
Rotl = dict(
733
734
	is_a     = "binop",
	flags    = "none",
735
736
),

737
738
739
Sel = dict(
	ins    = [ "mem", "ptr" ],
	arity  = "variable",
740
	flags  = "none",
741
	mode   = "is_Method_type(get_entity_type(entity)) ? mode_P_code : mode_P_data",
742
743
	pinned = "no",
	attrs  = [
744
		dict(
745
746
747
			type = "ir_entity*",
			name = "entity"
		)
748
749
	],
	attr_struct = "sel_attr",
750
751
),

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

757
Shr = dict(
758
759
	is_a     = "binop",
	flags    = "none",
760
761
),

762
Shrs = dict(
763
764
	is_a     = "binop",
	flags    = "none",
765
766
),

767
768
Start = dict(
	mode       = "mode_T",
769
	pinned     = "yes",
770
771
	flags      = "cfopcode",
	singleton  = True,
772
773
),

774
775
776
Store = dict(
	ins      = [ "mem", "ptr", "value" ],
	outs     = [ "M", "X_regular", "X_except" ],
777
	flags    = "fragile, uses_memory",
778
	pinned   = "exception",
779
	attr_struct = "store_attr",
780
	pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned",
781
	constructor_args = [
782
		dict(
783
784
			type = "ir_cons_flags",
			name = "flags",
785
		),
786
787
788
789
790
791
	],
	d_post = '''
#if PRECISE_EXC_CONTEXT
	firm_alloc_frag_arr(res, op_Store, &res->attr.store.exc.frag_arr);
#endif
	'''
792
793
),

794
Sub = dict(
795
796
	is_a     = "binop",
	flags    = "none",
797
798
),

799
800
SymConst = dict(
	mode       = "mode_P",
801
	flags      = "constlike, start_block",
802
	knownBlock = True,
803
	pinned     = "no",
804
	attrs      = [
805
		dict(
806
807
			type = "ir_entity*",
			name = "entity"
808
		)
809
	],
810
811
	attr_struct = "symconst_attr",
	java_noconstr = True,
812
813
),

814
815
Sync = dict(
	mode     = "mode_M",
816
	flags    = "none",
817
	pinned   = "no",
818
819
	optimize = False,
	arity    = "dynamic"
820
821
),

822
Tuple = dict(
823
824
825
826
	arity  = "variable",
	mode   = "mode_T",
	pinned = "no",
	flags  = "labeled",
827
	java_noconstr = True
828
),
Moritz Kroll's avatar
Moritz Kroll committed
829

830
831
Unknown = dict(
	knownBlock = True,
832
	pinned     = "yes",
833
	block      = "get_irg_start_block(irg)",
834
	flags      = "cfopcode, fragile, start_block, constlike, dump_noblock",
Moritz Kroll's avatar
Moritz Kroll committed
835
),
836
)