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
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 Add(Binop):
	flags = ["commutative"]

class Alloc(Op):
27
	ins   = [ "mem", "count" ]
28
29
30
31
32
33
	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"),
	]
34
	flags = [ "fragile", "uses_memory" ]
35
36
37
38
39
40
41
42
43
	attrs = [
		dict(
			name = "type",
			type = "ir_type*"
		),
		dict(
			name = "where",
			type = "ir_where_alloc"
		)
44
45
46
47
48
49
50
51
52
	]
	pinned      = "yes"
	attr_struct = "alloc_attr"

class Anchor(Op):
	mode        = "mode_ANY"
	arity       = "variable"
	flags       = [ "dump_noblock" ]
	pinned      = "yes"
53
	attr_struct = "irg_attr"
54
55
	knownBlock  = True
	singleton   = True
56
	noconstructor = True
57
58
59
60
61
62
63
64
65
66

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"
67
68
	attr_struct   = "asm_attr"
	attrs_name    = "assem"
69
70
71
72
73
74
75
76
	attrs = [
		dict(
			name = "input_constraints",
			type = "ir_asm_constraint*",
		),
		dict(
			name = "n_output_constraints",
			type = "int",
77
			noprop = True,
78
79
80
81
82
83
84
85
		),
		dict(
			name = "output_constraints",
			type = "ir_asm_constraint*",
		),
		dict(
			name = "n_clobbers",
			type = "int",
86
			noprop = True,
87
88
89
90
91
92
93
94
95
		),
		dict(
			name = "clobbers",
			type = "ident**",
		),
		dict(
			name = "text",
			type = "ident*",
		),
96
97
98
	]

class Bad(Op):
99
	mode          = "mode_T"
100
101
102
	flags         = [ "cfopcode", "start_block", "dump_noblock" ]
	pinned        = "yes"
	knownBlock    = True
103
	block         = "get_irg_start_block(irg)"
104
105
	singleton     = True
	attr_struct   = "bad_attr"
106
	init = '''
107
	res->attr.bad.irg.irg = irg;
108
109
	'''

110
class Deleted(Op):
111
112
113
114
	mode          = "mode_Bad"
	flags         = [ ]
	pinned        = "yes"
	noconstructor = True
115

116
117
118
119
120
121
122
123
class Block(Op):
	mode        = "mode_BB"
	knownBlock  = True
	block       = "NULL"
	pinned      = "yes"
	arity       = "variable"
	flags       = [ "labeled" ]
	attr_struct = "block_attr"
Moritz Kroll's avatar
Moritz Kroll committed
124
125

	init = '''
126
	res->attr.block.irg.irg     = irg;
Moritz Kroll's avatar
Moritz Kroll committed
127
128
	res->attr.block.backedge    = new_backedge_arr(irg->obst, arity);
	set_Block_matured(res, 1);
129
130

	/* Create and initialize array for Phi-node construction. */
131
132
133
	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*));
134
	}
135
	'''
136

137
138
	java_add   = '''
	public void addPred(Node node) {
139
		binding_ircons.add_immBlock_pred(ptr, node.ptr);
140
141
142
	}

	public void mature() {
143
		binding_ircons.mature_immBlock(ptr);
144
145
146
147
148
149
150
151
	}

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

	public boolean blockVisited() {
152
		return 0 != binding_irnode.Block_block_visited(ptr);
153
154
155
	}

	public void markBlockVisited() {
156
		binding_irnode.mark_Block_block_visited(ptr);
157
158
159
	}

	public boolean isBad() {
160
		return binding_irnode.is_Bad(ptr) != 0;
161
	}
162
163
	'''

164
165
166
class Borrow(Binop):
	flags = []

167
168
class Bound(Op):
	ins    = [ "mem", "index", "lower", "upper" ]
169
170
171
172
173
174
	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"),
	]
175
176
177
178
 	flags  = [ "fragile", "highlevel" ]
	pinned = "exception"
	pinned_init = "op_pin_state_pinned"
	attr_struct = "bound_attr"
179
	attrs_name  = "bound"
180
181
182
183

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

206
207
208
class Call(Op):
	ins      = [ "mem", "ptr" ]
	arity    = "variable"
209
210
211
212
213
214
215
	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"),
	]
216
	flags    = [ "fragile", "uses_memory" ]
217
	attrs    = [
218
219
220
		dict(
			type = "ir_type*",
			name = "type"
221
222
223
224
225
226
		),
		dict(
			type = "unsigned",
			name = "tail_call",
			# the tail call attribute can only be set by analysis
			init = "0"
227
		)
228
229
230
231
	]
	attr_struct = "call_attr"
	pinned      = "memory"
	pinned_init = "op_pin_state_pinned"
232
233
	init = '''
	assert((get_unknown_type() == type) || is_Method_type(type));
234
	'''
235

236
237
238
class Carry(Binop):
	flags = [ "commutative" ]

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

class Cmp(Binop):
252
	outs  = [
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
		("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"),
269
	]
270
271
272
273
	flags = []

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

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

class Const(Op):
	mode       = ""
	flags      = [ "constlike", "start_block" ]
	knownBlock = True
	pinned     = "no"
	attrs_name = "con"
314
315
	attrs      = [
		dict(
Matthias Braun's avatar
Matthias Braun committed
316
			type = "ir_tarval*",
317
318
			name = "tarval",
		)
319
320
	]
	attr_struct = "const_attr"
321

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

class CopyB(Op):
	ins   = [ "mem", "dst", "src" ]
340
341
342
343
344
	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"),
	]
345
	flags = [ "fragile", "highlevel", "uses_memory" ]
346
347
	attrs = [
		dict(
348
349
			name = "type",
			type = "ir_type*"
350
		)
351
352
	]
	attr_struct = "copyb_attr"
353
	attrs_name  = "copyb"
354
355
	pinned      = "memory"
	pinned_init = "op_pin_state_pinned"
356

357
358
class Div(Op):
	ins   = [ "mem", "left", "right" ]
359
360
361
362
363
364
	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"),
	]
365
366
	flags = [ "fragile", "uses_memory" ]
	attrs_name = "divmod"
367
368
369
370
371
	attrs = [
		dict(
			type = "ir_mode*",
			name = "resmode"
		),
Moritz Kroll's avatar
Moritz Kroll committed
372
373
374
375
376
377
378
379
		dict(
			name = "no_remainder",
			type = "int",
			init = "0",
			special = dict(
				suffix = "RL",
				init = "1"
			)
380
		)
381
382
383
384
385
	]
	attr_struct = "divmod_attr"
	pinned      = "exception"
	op_index    = 1
	arity_override = "oparity_binary"
386

387
388
class DivMod(Op):
	ins   = [ "mem", "left", "right" ]
389
390
391
392
393
394
395
	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"),
	]
396
397
	flags = [ "fragile", "uses_memory" ]
	attrs_name = "divmod"
398
399
400
401
402
	attrs = [
		dict(
			type = "ir_mode*",
			name = "resmode"
		),
403
404
405
406
407
408
409
410
	]
	attr_struct = "divmod_attr"
	pinned      = "exception"
	op_index    = 1
	arity_override = "oparity_binary"

class Dummy(Op):
	ins   = []
411
	flags = [ "cfopcode", "start_block", "constlike", "dump_noblock" ]
412
413
414
415
416
417
418
419
420
	knownBlock = True
	pinned     = "yes"
	block      = "get_irg_start_block(irg)"

class End(Op):
	mode       = "mode_X"
	pinned     = "yes"
	arity      = "dynamic"
	flags      = [ "cfopcode" ]
421
422
	knownBlock = True
	block      = "get_irg_end_block(irg)"
423
424
425
426
	singleton  = True

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

428
429
430
431
432
class Free(Op):
	ins    = [ "mem", "ptr", "size" ]
	mode   = "mode_M"
	flags  = [ "uses_memory" ]
	pinned = "yes"
433
	attrs  = [
434
		dict(
435
436
			name = "type",
			type = "ir_type*"
437
438
		),
		dict(
439
440
			name = "where",
			type = "ir_where_alloc"
441
		)
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
	]
	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" ]
458
459
460
461
462
463
	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"),
	]
464
	flags = [ "highlevel" ]
465
466
467
468
469
	attrs = [
		dict(
			name = "type",
			type = "ir_type*"
		)
470
471
472
473
474
475
476
477
478
479
480
481
482
	]
	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" ]
483
484
485
486
487
488
	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"),
	]
489
490
491
	flags    = [ "fragile", "uses_memory" ]
	pinned   = "exception"
	pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
492
493
494
495
496
497
	attrs    = [
		dict(
			type = "ir_mode*",
			name = "mode",
			java_name = "load_mode"
		),
498
499
	]
	attr_struct = "load_attr"
500
501
	constructor_args = [
		dict(
Moritz Kroll's avatar
Moritz Kroll committed
502
			type = "ir_cons_flags",
503
504
			name = "flags",
		),
505
506
507
508
509
510
511
	]

class Minus(Unop):
	flags = []

class Mod(Op):
	ins   = [ "mem", "left", "right" ]
512
513
514
515
516
517
	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"),
	]
518
519
	flags = [ "fragile", "uses_memory" ]
	attrs_name = "divmod"
520
	attrs = [
521
		dict(
522
523
			type = "ir_mode*",
			name = "resmode"
524
		),
525
526
527
528
529
	]
	attr_struct = "divmod_attr"
	pinned      = "exception"
	op_index    = 1
	arity_override = "oparity_binary"
Matthias Braun's avatar
Matthias Braun committed
530

531
532
533
534
535
536
537
538
539
540
541
542
class Mul(Binop):
	flags = [ "commutative" ]

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

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

class NoMem(Op):
543
544
545
546
	mode          = "mode_M"
	flags         = [ "dump_noblock", "dump_noinput" ]
	pinned        = "yes"
	knownBlock    = True
547
	block         = "get_irg_start_block(irg)"
548
	singleton     = True
549
550
551
552
553
554
555
556

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"
Matthias Braun's avatar
Matthias Braun committed
561
562
563
564
565
566
	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);
	'''
567
568
569
570
571
572
573
574

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

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

class Quot(Op):
	ins   = [ "mem", "left", "right" ]
594
595
596
597
598
599
	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"),
	]
600
601
	flags = [ "fragile", "uses_memory" ]
	attrs_name = "divmod"
602
	attrs = [
603
		dict(
604
605
606
			type = "ir_mode*",
			name = "resmode"
		),
607
608
609
610
611
612
613
614
	]
	attr_struct = "divmod_attr"
	pinned      = "exception"
	op_index    = 1
	arity_override = "oparity_binary"

class Raise(Op):
	ins    = [ "mem", "exo_ptr" ]
615
616
617
618
	outs  = [
		("M", "memory result",                     "pn_Generic_M"),
		("X", "control flow to exception handler", "pn_Generic_X_regular"),
	]
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
	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"
638
	attrs  = [
639
		dict(
640
641
642
			type = "ir_entity*",
			name = "entity"
		)
643
644
645
646
647
648
649
650
651
652
653
654
655
	]
	attr_struct = "sel_attr"

class Shl(Binop):
	flags = []

class Shr(Binop):
	flags = []

class Shrs(Binop):
	flags = []

class Start(Op):
656
657
658
659
660
661
662
	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")
	]
663
664
665
666
	mode       = "mode_T"
	pinned     = "yes"
	flags      = [ "cfopcode" ]
	singleton  = True
667
668
	knownBlock = True
	block      = "get_irg_start_block(irg)"
669
670
671

class Store(Op):
	ins      = [ "mem", "ptr", "value" ]
672
673
674
675
676
	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"),
	]
677
678
679
680
	flags    = [ "fragile", "uses_memory" ]
	pinned   = "exception"
	attr_struct = "store_attr"
	pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
681
	constructor_args = [
682
		dict(
683
684
			type = "ir_cons_flags",
			name = "flags",
685
		),
686
687
688
689
690
691
692
693
694
695
	]

class Sub(Binop):
	flags = []

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

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

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

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

# 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))