ir_spec.py 17.2 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from spec_util import abstract, setnodedefaults

class Op(object):
	"Base class for firm nodes"
abstract(Op)

class Unop(Op):
	"Unary nodes have exactly 1 input"
	name     = "unop"
	ins      = [ "op" ]
	op_index = 0
	pinned   = "no"
abstract(Unop)

class Binop(Op):
	"Binary nodes have exactly 2 inputs"
	name     = "binop"
	ins      = [ "left", "right" ]
	op_index = 0
	pinned   = "no"
abstract(Binop)

class Abs(Unop):
	flags = []

class Add(Binop):
	flags = ["commutative"]

class Alloc(Op):
30
	ins   = [ "mem", "count" ]
31
32
33
34
35
36
	outs  = [
		("M",         "memory result",                         "pn_Generic_M"),
		("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
		("X_except",  "control flow when exception occured",   "pn_Generic_X_except"),
		("res",       "pointer to newly allocated memory",     "pn_Generic_other"),
	]
37
	flags = [ "fragile", "uses_memory" ]
38
39
40
41
42
43
44
45
46
	attrs = [
		dict(
			name = "type",
			type = "ir_type*"
		),
		dict(
			name = "where",
			type = "ir_where_alloc"
		)
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
	]
	pinned      = "yes"
	attr_struct = "alloc_attr"

class Anchor(Op):
	mode        = "mode_ANY"
	arity       = "variable"
	flags       = [ "dump_noblock" ]
	pinned      = "yes"
	knownBlock  = True
	singleton   = True

class And(Binop):
	flags    = [ "commutative" ]

class ASM(Op):
	mode          = "mode_T"
	arity         = "variable"
	flags         = [ "keep", "uses_memory" ]
	pinned        = "memory"
	pinned_init   = "op_pin_state_pinned"
68
69
	attr_struct   = "asm_attr"
	attrs_name    = "assem"
70
71
72
73
74
75
76
77
	attrs = [
		dict(
			name = "input_constraints",
			type = "ir_asm_constraint*",
		),
		dict(
			name = "n_output_constraints",
			type = "int",
78
			noprop = True,
79
80
81
82
83
84
85
86
		),
		dict(
			name = "output_constraints",
			type = "ir_asm_constraint*",
		),
		dict(
			name = "n_clobbers",
			type = "int",
87
			noprop = True,
88
89
90
91
92
93
94
95
96
		),
		dict(
			name = "clobbers",
			type = "ident**",
		),
		dict(
			name = "text",
			type = "ident*",
		),
97
98
99
100
	]
	java_noconstr = True

class Bad(Op):
Matthias Braun's avatar
Matthias Braun committed
101
	mode        = "mode_Bad"
102
	flags       = [ "cfopcode", "start_block", "dump_noblock" ]
Matthias Braun's avatar
Matthias Braun committed
103
104
105
106
	pinned      = "yes"
	knownBlock  = True
	singleton   = True
	attr_struct = "irg_attr"
107
108
	init = '''
	res->attr.irg.irg = irg;
109
110
111
112
113
114
115
116
117
118
119
120
	'''

class Block(Op):
	mode        = "mode_BB"
	knownBlock  = True
	block       = "NULL"
	pinned      = "yes"
	optimize    = False
	arity       = "variable"
	flags       = [ "labeled" ]
	attr_struct = "block_attr"
	java_noconstr = True
Moritz Kroll's avatar
Moritz Kroll committed
121
122
123
124
125
126
127

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

	res->attr.block.is_dead     = 0;
	res->attr.block.is_mb_head  = 1;
128
	res->attr.block.irg.irg     = irg;
Moritz Kroll's avatar
Moritz Kroll committed
129
130
131
132
133
	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;
134
	res->attr.block.entity      = NULL;
Moritz Kroll's avatar
Moritz Kroll committed
135
136
137

	set_Block_matured(res, 1);
	set_Block_block_visited(res, 0);
138
139

	/* Create and initialize array for Phi-node construction. */
140
141
142
	if (get_irg_phase_state(irg) == phase_building) {
		res->attr.block.graph_arr = NEW_ARR_D(ir_node *, irg->obst, irg->n_loc);
		memset(res->attr.block.graph_arr, 0, irg->n_loc * sizeof(ir_node*));
143
	}
144
	'''
145

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

	public boolean isBad() {
		return binding.is_Bad(ptr) != 0;
	}
171
172
173
174
	'''

class Bound(Op):
	ins    = [ "mem", "index", "lower", "upper" ]
175
176
177
178
179
180
	outs  = [
		("M",         "memory result",                         "pn_Generic_M"),
		("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
		("X_except",  "control flow when exception occured",   "pn_Generic_X_except"),
		("res",       "the checked index",                     "pn_Generic_other"),
	]
181
182
183
184
 	flags  = [ "fragile", "highlevel" ]
	pinned = "exception"
	pinned_init = "op_pin_state_pinned"
	attr_struct = "bound_attr"
185
	attrs_name  = "bound"
186
187
188
189

class Builtin(Op):
	ins      = [ "mem" ]
	arity    = "variable"
190
191
192
193
	outs     = [
		("M",        "memory result", "pn_Generic_M"),
		("1_result", "first result",  "pn_Generic_other"),
	]
194
	flags    = [ "uses_memory" ]
195
	attrs    = [
196
197
198
199
		dict(
			type = "ir_builtin_kind",
			name = "kind"
		),
200
		dict(
201
202
203
			type = "ir_type*",
			name = "type"
		)
204
205
206
207
	]
	pinned      = "memory"
	pinned_init = "op_pin_state_pinned"
	attr_struct = "builtin_attr"
208
	init   = '''
209
210
211
	assert((get_unknown_type() == type) || is_Method_type(type));
	'''

212
213
214
class Call(Op):
	ins      = [ "mem", "ptr" ]
	arity    = "variable"
215
216
217
218
219
220
221
	outs     = [
		("M",                "memory result",                         "pn_Generic_M"),
		("X_regular",        "control flow when no exception occurs", "pn_Generic_X_regular"),
		("X_except",         "control flow when exception occured",   "pn_Generic_X_except"),
		("T_result",         "tuple containing all results",          "pn_Generic_other"),
		("P_value_res_base", "pointer to memory register containing copied results passed by value"),
	]
222
	flags    = [ "fragile", "uses_memory" ]
223
	attrs    = [
224
225
226
		dict(
			type = "ir_type*",
			name = "type"
227
228
229
230
231
232
		),
		dict(
			type = "unsigned",
			name = "tail_call",
			# the tail call attribute can only be set by analysis
			init = "0"
233
		)
234
235
236
237
	]
	attr_struct = "call_attr"
	pinned      = "memory"
	pinned_init = "op_pin_state_pinned"
238
239
	init = '''
	assert((get_unknown_type() == type) || is_Method_type(type));
240
	'''
241

Michael Beck's avatar
Michael Beck committed
242
class Cast(Unop):
243
244
	mode     = "get_irn_mode(irn_op)"
	flags    = [ "highlevel" ]
245
246
247
248
249
	attrs    = [
		dict(
			type = "ir_type*",
			name = "type"
		)
250
251
	]
	attr_struct = "cast_attr"
252
	init     = "assert(is_atomic_type(type));"
253
254

class Cmp(Binop):
255
	outs  = [
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
		("False", "always false",                            "0"),
		("Eq",    "equal",                                   "1"),
		("Lt",    "less",                                    "2"),
		("Le",    "less or equal",                           "pn_Cmp_Eq|pn_Cmp_Lt"),
		("Gt",    "greater",                                 "4"),
		("Ge",    "greater or equal",                        "pn_Cmp_Eq|pn_Cmp_Gt"),
		("Lg",    "less or greater ('not equal' for integer numbers)", "pn_Cmp_Lt|pn_Cmp_Gt"),
		("Leg",   "less, equal or greater ('not unordered')", "pn_Cmp_Lt|pn_Cmp_Eq|pn_Cmp_Gt"),
		("Uo",    "unordered",                               "8"),
		("Ue",    "unordered or equal",                      "pn_Cmp_Uo|pn_Cmp_Eq"),
		("Ul",    "unordered or less",                       "pn_Cmp_Uo|pn_Cmp_Lt"),
		("Ule",   "unordered, less or equal",                "pn_Cmp_Uo|pn_Cmp_Lt|pn_Cmp_Eq"),
		("Ug",    "unordered or greater",                    "pn_Cmp_Uo|pn_Cmp_Gt"),
		("Uge",   "onordered, greater or equal",             "pn_Cmp_Uo|pn_Cmp_Gt|pn_Cmp_Eq"),
		("Ne",    "unordered, less or greater ('not equal' for floatingpoint numbers)", "pn_Cmp_Uo|pn_Cmp_Lt|pn_Cmp_Gt"),
		("True",  "always true",                             "15"),
272
	]
273
274
275
276
	flags = []

class Cond(Op):
	ins      = [ "selector" ]
277
278
279
280
	outs     = [
		("false", "control flow if operand is \"false\""),
		("true",  "control flow if operand is \"true\""),
	]
281
282
	flags    = [ "cfopcode", "forking" ]
	pinned   = "yes"
283
284
285
286
287
288
289
290
291
292
293
	attrs    = [
		dict(
			name = "default_proj",
			type = "long",
			init = "0"
		),
		dict(
			name = "jmp_pred",
			type = "cond_jmp_predicate",
			init = "COND_JMP_PRED_NONE"
		)
294
	]
295
	attr_struct = "cond_attr"
296

297
298
299
300
301
class Confirm(Op):
	ins      = [ "value", "bound" ]
	mode     = "get_irn_mode(irn_value)"
	flags    = [ "highlevel" ]
	pinned   = "yes"
302
303
304
305
306
	attrs    = [
		dict(
			name = "cmp",
			type = "pn_Cmp"
		),
307
308
	]
	attr_struct = "confirm_attr"
309
	attrs_name  = "confirm"
310
311
312
313
314
315
316

class Const(Op):
	mode       = ""
	flags      = [ "constlike", "start_block" ]
	knownBlock = True
	pinned     = "no"
	attrs_name = "con"
317
318
319
320
321
	attrs      = [
		dict(
			type = "tarval*",
			name = "tarval",
		)
322
323
	]
	attr_struct = "const_attr"
324

325
326
class Conv(Unop):
	flags = []
327
328
329
330
331
332
333
334
335
336
	attrs = [
		dict(
			name = "strict",
			type = "int",
			init = "0",
			special = dict(
				prefix = "strict",
				init = "1"
			)
		)
337
338
	]
	attr_struct = "conv_attr"
339
	attrs_name  = "conv"
340
341
342

class CopyB(Op):
	ins   = [ "mem", "dst", "src" ]
343
344
345
346
347
	outs  = [
		("M",         "memory result",                         "pn_Generic_M"),
		("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
		("X_except",  "control flow when exception occured",   "pn_Generic_X_except"),
	]
348
	flags = [ "fragile", "highlevel", "uses_memory" ]
349
350
	attrs = [
		dict(
351
352
			name = "type",
			type = "ir_type*"
353
		)
354
355
	]
	attr_struct = "copyb_attr"
356
	attrs_name  = "copyb"
357
358
	pinned      = "memory"
	pinned_init = "op_pin_state_pinned"
359

360
361
class Div(Op):
	ins   = [ "mem", "left", "right" ]
362
363
364
365
366
367
	outs  = [
		("M",         "memory result",                         "pn_Generic_M"),
		("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
		("X_except",  "control flow when exception occured",   "pn_Generic_X_except"),
		("res",       "result of computation",                 "pn_Generic_other"),
	]
368
369
	flags = [ "fragile", "uses_memory" ]
	attrs_name = "divmod"
370
371
372
373
374
	attrs = [
		dict(
			type = "ir_mode*",
			name = "resmode"
		),
Moritz Kroll's avatar
Moritz Kroll committed
375
376
377
378
379
380
381
382
		dict(
			name = "no_remainder",
			type = "int",
			init = "0",
			special = dict(
				suffix = "RL",
				init = "1"
			)
383
		)
384
385
386
387
388
	]
	attr_struct = "divmod_attr"
	pinned      = "exception"
	op_index    = 1
	arity_override = "oparity_binary"
389

390
391
class DivMod(Op):
	ins   = [ "mem", "left", "right" ]
392
393
394
395
396
397
398
	outs  = [
		("M",         "memory result",                         "pn_Generic_M"),
		("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
		("X_except",  "control flow when exception occured",   "pn_Generic_X_except"),
		("res_div",   "result of computation a/b",             "pn_Generic_other"),
		("res_mod",   "result of computation a%b"),
	]
399
400
	flags = [ "fragile", "uses_memory" ]
	attrs_name = "divmod"
401
402
403
404
405
	attrs = [
		dict(
			type = "ir_mode*",
			name = "resmode"
		),
406
407
408
409
410
411
412
413
	]
	attr_struct = "divmod_attr"
	pinned      = "exception"
	op_index    = 1
	arity_override = "oparity_binary"

class Dummy(Op):
	ins   = []
414
	flags = [ "cfopcode", "start_block", "constlike", "dump_noblock" ]
415
416
417
418
419
420
421
422
423
424
425
426
427
	knownBlock = True
	pinned     = "yes"
	block      = "get_irg_start_block(irg)"

class End(Op):
	mode       = "mode_X"
	pinned     = "yes"
	arity      = "dynamic"
	flags      = [ "cfopcode" ]
	singleton  = True

class Eor(Binop):
	flags    = [ "commutative" ]
428

429
430
431
432
433
class Free(Op):
	ins    = [ "mem", "ptr", "size" ]
	mode   = "mode_M"
	flags  = [ "uses_memory" ]
	pinned = "yes"
434
	attrs  = [
435
		dict(
436
437
			name = "type",
			type = "ir_type*"
438
439
		),
		dict(
440
441
			name = "where",
			type = "ir_where_alloc"
442
		)
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
	]
	attr_struct = "free_attr"

class Id(Op):
	ins    = [ "pred" ]
	pinned = "no"
	flags  = []

class IJmp(Op):
	mode     = "mode_X"
	pinned   = "yes"
	ins      = [ "target" ]
	flags    = [ "cfopcode", "forking", "keep" ]

class InstOf(Op):
	ins   = [ "store", "obj" ]
459
460
461
462
463
464
	outs  = [
		("M",         "memory result",                         "pn_Generic_M"),
		("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
		("X_except",  "control flow when exception occured",   "pn_Generic_X_except"),
		("res",       "checked object pointer",                "pn_Generic_other"),
	]
465
	flags = [ "highlevel" ]
466
467
468
469
470
	attrs = [
		dict(
			name = "type",
			type = "ir_type*"
		)
471
472
473
474
475
476
477
478
479
480
481
482
483
	]
	attr_struct = "io_attr"
	pinned      = "memory"
	pinned_init = "op_pin_state_floats"

class Jmp(Op):
	mode     = "mode_X"
	pinned   = "yes"
	ins      = []
	flags    = [ "cfopcode" ]

class Load(Op):
	ins      = [ "mem", "ptr" ]
484
485
486
487
488
489
	outs  = [
		("M",         "memory result",                         "pn_Generic_M"),
		("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
		("X_except",  "control flow when exception occured",   "pn_Generic_X_except"),
		("res",       "result of load operation",              "pn_Generic_other"),
	]
490
491
492
	flags    = [ "fragile", "uses_memory" ]
	pinned   = "exception"
	pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
493
494
495
496
497
498
	attrs    = [
		dict(
			type = "ir_mode*",
			name = "mode",
			java_name = "load_mode"
		),
499
500
	]
	attr_struct = "load_attr"
501
502
	constructor_args = [
		dict(
Moritz Kroll's avatar
Moritz Kroll committed
503
			type = "ir_cons_flags",
504
505
			name = "flags",
		),
506
507
508
509
510
511
512
	]

class Minus(Unop):
	flags = []

class Mod(Op):
	ins   = [ "mem", "left", "right" ]
513
514
515
516
517
518
	outs  = [
		("M",         "memory result",                         "pn_Generic_M"),
		("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
		("X_except",  "control flow when exception occured",   "pn_Generic_X_except"),
		("res",       "result of computation",                 "pn_Generic_other"),
	]
519
520
	flags = [ "fragile", "uses_memory" ]
	attrs_name = "divmod"
521
	attrs = [
522
		dict(
523
524
			type = "ir_mode*",
			name = "resmode"
525
		),
526
527
528
529
530
	]
	attr_struct = "divmod_attr"
	pinned      = "exception"
	op_index    = 1
	arity_override = "oparity_binary"
Matthias Braun's avatar
Matthias Braun committed
531

532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
class Mul(Binop):
	flags = [ "commutative" ]

class Mulh(Binop):
	flags = [ "commutative" ]

class Mux(Op):
	ins    = [ "sel", "false", "true" ]
	flags  = []
	pinned = "no"

class NoMem(Op):
	mode       = "mode_M"
	flags      = [ "dump_noblock", "dump_noinput" ]
	pinned     = "yes"
	knownBlock = True
	singleton  = True

class Not(Unop):
	flags = []

class Or(Binop):
	flags = [ "commutative" ]

class Phi(Op):
557
558
559
560
	pinned        = "yes"
	arity         = "variable"
	flags         = []
	attr_struct   = "phi_attr"
561
	java_noconstr = True
Matthias Braun's avatar
Matthias Braun committed
562
563
564
565
566
567
	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);
	'''
568
569
570
571
572
573
574
575

class Pin(Op):
	ins      = [ "op" ]
	mode     = "get_irn_mode(irn_op)"
	flags    = [ "highlevel" ]
	pinned   = "yes"

class Proj(Op):
576
577
578
579
580
581
582
583
	ins        = [ "pred" ]
	flags      = []
	pinned     = "no"
	knownBlock = True
	knownGraph = True
	block      = "get_nodes_block(irn_pred)"
	graph      = "get_irn_irg(irn_pred)"
	attrs      = [
584
585
		dict(
			type = "long",
586
			name = "proj",
587
588
			initname = "",
			noprop = False,
589
		)
590
591
592
593
594
	]
	attr_struct = "long"

class Quot(Op):
	ins   = [ "mem", "left", "right" ]
595
596
597
598
599
600
	outs  = [
		("M",         "memory result",                         "pn_Generic_M"),
		("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
		("X_except",  "control flow when exception occured",   "pn_Generic_X_except"),
		("res",       "result of computation",                 "pn_Generic_other"),
	]
601
602
	flags = [ "fragile", "uses_memory" ]
	attrs_name = "divmod"
603
	attrs = [
604
		dict(
605
606
607
			type = "ir_mode*",
			name = "resmode"
		),
608
609
610
611
612
613
614
615
	]
	attr_struct = "divmod_attr"
	pinned      = "exception"
	op_index    = 1
	arity_override = "oparity_binary"

class Raise(Op):
	ins    = [ "mem", "exo_ptr" ]
616
617
618
619
	outs  = [
		("M", "memory result",                     "pn_Generic_M"),
		("X", "control flow to exception handler", "pn_Generic_X_regular"),
	]
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
	flags  = [ "highlevel", "cfopcode" ]
	pinned = "yes"

class Return(Op):
	ins      = [ "mem" ]
	arity    = "variable"
	mode     = "mode_X"
	flags    = [ "cfopcode" ]
	pinned   = "yes"

class Rotl(Binop):
	flags    = []

class Sel(Op):
	ins    = [ "mem", "ptr" ]
	arity  = "variable"
	flags  = []
	mode   = "is_Method_type(get_entity_type(entity)) ? mode_P_code : mode_P_data"
	pinned = "no"
639
	attrs  = [
640
		dict(
641
642
643
			type = "ir_entity*",
			name = "entity"
		)
644
645
646
647
648
649
650
651
652
653
654
655
656
	]
	attr_struct = "sel_attr"

class Shl(Binop):
	flags = []

class Shr(Binop):
	flags = []

class Shrs(Binop):
	flags = []

class Start(Op):
657
658
659
660
661
662
663
	outs       = [
		("X_initial_exec", "control flow"),
		("M",              "initial memory"),
		("P_frame_base",   "frame base pointer"),
		("P_tls",          "pointer to thread local storage segment"),
		("T_args",         "function arguments")
	]
664
665
666
667
668
669
670
	mode       = "mode_T"
	pinned     = "yes"
	flags      = [ "cfopcode" ]
	singleton  = True

class Store(Op):
	ins      = [ "mem", "ptr", "value" ]
671
672
673
674
675
	outs  = [
		("M",         "memory result",                         "pn_Generic_M"),
		("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
		("X_except",  "control flow when exception occured",   "pn_Generic_X_except"),
	]
676
677
678
679
	flags    = [ "fragile", "uses_memory" ]
	pinned   = "exception"
	attr_struct = "store_attr"
	pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
680
	constructor_args = [
681
		dict(
682
683
			type = "ir_cons_flags",
			name = "flags",
684
		),
685
686
687
688
689
690
691
692
693
694
	]

class Sub(Binop):
	flags = []

class SymConst(Op):
	mode       = "mode_P"
	flags      = [ "constlike", "start_block" ]
	knownBlock = True
	pinned     = "no"
695
	attrs      = [
696
		dict(
697
			type = "ir_entity*",
698
699
			name = "entity",
			noprop = True
700
		)
701
702
703
704
705
706
707
708
709
	]
	attr_struct = "symconst_attr"
	java_noconstr = True

class Sync(Op):
	mode     = "mode_M"
	flags    = []
	pinned   = "no"
	optimize = False
710
	arity    = "dynamic"
711

712
713
714
715
716
class Tuple(Op):
	arity  = "variable"
	mode   = "mode_T"
	pinned = "no"
	flags  = [ "labeled" ]
717
	java_noconstr = True
718
719
720
721
722

class Unknown(Op):
	knownBlock = True
	pinned     = "yes"
	block      = "get_irg_start_block(irg)"
723
	flags      = [ "cfopcode", "start_block", "constlike", "dump_noblock" ]
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739

# Prepare node list

def getOpList(namespace):
	nodes = []
	for t in namespace.values():
		if type(t) != type:
			continue

		if issubclass(t, Op):
			setnodedefaults(t)
			nodes.append(t)
	return nodes

nodes = getOpList(globals())
nodes = sorted(nodes, lambda x,y: cmp(x.name, y.name))