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

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

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

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

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

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

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

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

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

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

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

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

	# TODO: No firm_alloc_frag_arr??
245
246
),

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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