ir_spec.py 17.1 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
	]
	pinned      = "yes"
	attr_struct = "alloc_attr"

class Anchor(Op):
49
50
51
52
53
54
55
56
57
	mode             = "mode_ANY"
	arity            = "variable"
	flags            = [ "dump_noblock" ]
	pinned           = "yes"
	attr_struct      = "irg_attr"
	knownBlock       = True
	singleton        = True
	noconstructor    = True
	customSerializer = True
58
59
60
61
62

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

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

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

112
class Deleted(Op):
113
114
115
116
117
	mode             = "mode_Bad"
	flags            = [ ]
	pinned           = "yes"
	noconstructor    = True
	customSerializer = True
118

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

	init = '''
130
	res->attr.block.irg.irg     = irg;
Moritz Kroll's avatar
Moritz Kroll committed
131
132
	res->attr.block.backedge    = new_backedge_arr(irg->obst, arity);
	set_Block_matured(res, 1);
133
134

	/* Create and initialize array for Phi-node construction. */
135
136
137
	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*));
138
	}
139
	'''
140

141
142
143
class Borrow(Binop):
	flags = []

144
145
class Bound(Op):
	ins    = [ "mem", "index", "lower", "upper" ]
146
147
148
149
150
151
	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"),
	]
152
153
154
155
 	flags  = [ "fragile", "highlevel" ]
	pinned = "exception"
	pinned_init = "op_pin_state_pinned"
	attr_struct = "bound_attr"
156
	attrs_name  = "bound"
157
158
159
160

class Builtin(Op):
	ins      = [ "mem" ]
	arity    = "variable"
161
162
163
164
	outs     = [
		("M",        "memory result", "pn_Generic_M"),
		("1_result", "first result",  "pn_Generic_other"),
	]
165
	flags    = [ "uses_memory" ]
166
	attrs    = [
167
168
169
170
		dict(
			type = "ir_builtin_kind",
			name = "kind"
		),
171
		dict(
172
173
174
			type = "ir_type*",
			name = "type"
		)
175
176
177
178
	]
	pinned      = "memory"
	pinned_init = "op_pin_state_pinned"
	attr_struct = "builtin_attr"
179
	init   = '''
180
181
182
	assert((get_unknown_type() == type) || is_Method_type(type));
	'''

183
184
185
class Call(Op):
	ins      = [ "mem", "ptr" ]
	arity    = "variable"
186
187
188
189
190
191
192
	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"),
	]
193
	flags    = [ "fragile", "uses_memory" ]
194
	attrs    = [
195
196
197
		dict(
			type = "ir_type*",
			name = "type"
198
199
200
201
202
203
		),
		dict(
			type = "unsigned",
			name = "tail_call",
			# the tail call attribute can only be set by analysis
			init = "0"
204
		)
205
206
207
208
	]
	attr_struct = "call_attr"
	pinned      = "memory"
	pinned_init = "op_pin_state_pinned"
209
210
	init = '''
	assert((get_unknown_type() == type) || is_Method_type(type));
211
	'''
212

213
214
215
class Carry(Binop):
	flags = [ "commutative" ]

Michael Beck's avatar
Michael Beck committed
216
class Cast(Unop):
217
218
	mode     = "get_irn_mode(irn_op)"
	flags    = [ "highlevel" ]
219
220
221
222
223
	attrs    = [
		dict(
			type = "ir_type*",
			name = "type"
		)
224
225
	]
	attr_struct = "cast_attr"
226
	init     = "assert(is_atomic_type(type));"
227
228

class Cmp(Binop):
229
	outs  = [
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
		("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"),
246
	]
247
248
249
250
	flags = []

class Cond(Op):
	ins      = [ "selector" ]
251
252
253
254
	outs     = [
		("false", "control flow if operand is \"false\""),
		("true",  "control flow if operand is \"true\""),
	]
255
256
	flags    = [ "cfopcode", "forking" ]
	pinned   = "yes"
257
258
259
260
261
262
263
264
265
266
267
	attrs    = [
		dict(
			name = "default_proj",
			type = "long",
			init = "0"
		),
		dict(
			name = "jmp_pred",
			type = "cond_jmp_predicate",
			init = "COND_JMP_PRED_NONE"
		)
268
	]
269
	attr_struct = "cond_attr"
270

271
272
273
274
275
class Confirm(Op):
	ins      = [ "value", "bound" ]
	mode     = "get_irn_mode(irn_value)"
	flags    = [ "highlevel" ]
	pinned   = "yes"
276
277
278
279
280
	attrs    = [
		dict(
			name = "cmp",
			type = "pn_Cmp"
		),
281
282
	]
	attr_struct = "confirm_attr"
283
	attrs_name  = "confirm"
284
285
286
287
288
289
290

class Const(Op):
	mode       = ""
	flags      = [ "constlike", "start_block" ]
	knownBlock = True
	pinned     = "no"
	attrs_name = "con"
291
292
	attrs      = [
		dict(
Matthias Braun's avatar
Matthias Braun committed
293
			type = "ir_tarval*",
294
295
			name = "tarval",
		)
296
297
	]
	attr_struct = "const_attr"
298

299
300
class Conv(Unop):
	flags = []
301
302
303
304
305
306
307
308
309
310
	attrs = [
		dict(
			name = "strict",
			type = "int",
			init = "0",
			special = dict(
				prefix = "strict",
				init = "1"
			)
		)
311
312
	]
	attr_struct = "conv_attr"
313
	attrs_name  = "conv"
314
315
316

class CopyB(Op):
	ins   = [ "mem", "dst", "src" ]
317
318
319
320
321
	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"),
	]
322
	flags = [ "fragile", "highlevel", "uses_memory" ]
323
324
	attrs = [
		dict(
325
326
			name = "type",
			type = "ir_type*"
327
		)
328
329
	]
	attr_struct = "copyb_attr"
330
	attrs_name  = "copyb"
331
332
	pinned      = "memory"
	pinned_init = "op_pin_state_pinned"
333

334
335
class Div(Op):
	ins   = [ "mem", "left", "right" ]
336
337
338
339
340
341
	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"),
	]
342
343
	flags = [ "fragile", "uses_memory" ]
	attrs_name = "divmod"
344
345
346
347
348
	attrs = [
		dict(
			type = "ir_mode*",
			name = "resmode"
		),
Moritz Kroll's avatar
Moritz Kroll committed
349
350
351
352
353
354
355
356
		dict(
			name = "no_remainder",
			type = "int",
			init = "0",
			special = dict(
				suffix = "RL",
				init = "1"
			)
357
		)
358
359
360
361
362
	]
	attr_struct = "divmod_attr"
	pinned      = "exception"
	op_index    = 1
	arity_override = "oparity_binary"
363

364
365
class DivMod(Op):
	ins   = [ "mem", "left", "right" ]
366
367
368
369
370
371
372
	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"),
	]
373
374
	flags = [ "fragile", "uses_memory" ]
	attrs_name = "divmod"
375
376
377
378
379
	attrs = [
		dict(
			type = "ir_mode*",
			name = "resmode"
		),
380
381
382
383
384
385
386
	]
	attr_struct = "divmod_attr"
	pinned      = "exception"
	op_index    = 1
	arity_override = "oparity_binary"

class Dummy(Op):
387
388
	ins        = []
	flags      = [ "cfopcode", "start_block", "constlike", "dump_noblock" ]
389
390
391
392
393
	knownBlock = True
	pinned     = "yes"
	block      = "get_irg_start_block(irg)"

class End(Op):
394
395
396
397
398
399
400
401
	mode             = "mode_X"
	pinned           = "yes"
	arity            = "dynamic"
	flags            = [ "cfopcode" ]
	knownBlock       = True
	block            = "get_irg_end_block(irg)"
	singleton        = True
	customSerializer = True
402
403
404

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

406
407
408
409
410
class Free(Op):
	ins    = [ "mem", "ptr", "size" ]
	mode   = "mode_M"
	flags  = [ "uses_memory" ]
	pinned = "yes"
411
	attrs  = [
412
		dict(
413
414
			name = "type",
			type = "ir_type*"
415
416
		),
		dict(
417
418
			name = "where",
			type = "ir_where_alloc"
419
		)
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
	]
	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" ]
436
437
438
439
440
441
	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"),
	]
442
	flags = [ "highlevel" ]
443
444
445
446
447
	attrs = [
		dict(
			name = "type",
			type = "ir_type*"
		)
448
449
450
451
452
453
454
455
456
457
458
459
460
	]
	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" ]
461
462
463
464
465
466
	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"),
	]
467
468
469
	flags    = [ "fragile", "uses_memory" ]
	pinned   = "exception"
	pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
470
471
472
473
474
475
	attrs    = [
		dict(
			type = "ir_mode*",
			name = "mode",
			java_name = "load_mode"
		),
476
477
	]
	attr_struct = "load_attr"
478
479
	constructor_args = [
		dict(
Moritz Kroll's avatar
Moritz Kroll committed
480
			type = "ir_cons_flags",
481
482
			name = "flags",
		),
483
484
485
486
487
488
489
	]

class Minus(Unop):
	flags = []

class Mod(Op):
	ins   = [ "mem", "left", "right" ]
490
491
492
493
494
495
	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"),
	]
496
497
	flags = [ "fragile", "uses_memory" ]
	attrs_name = "divmod"
498
	attrs = [
499
		dict(
500
501
			type = "ir_mode*",
			name = "resmode"
502
		),
503
504
505
506
507
	]
	attr_struct = "divmod_attr"
	pinned      = "exception"
	op_index    = 1
	arity_override = "oparity_binary"
Matthias Braun's avatar
Matthias Braun committed
508

509
510
511
512
513
514
515
516
517
518
519
520
class Mul(Binop):
	flags = [ "commutative" ]

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

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

class NoMem(Op):
521
522
523
524
	mode          = "mode_M"
	flags         = [ "dump_noblock", "dump_noinput" ]
	pinned        = "yes"
	knownBlock    = True
525
	block         = "get_irg_start_block(irg)"
526
	singleton     = True
527
528
529
530
531
532
533
534

class Not(Unop):
	flags = []

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

class Phi(Op):
535
536
537
538
	pinned        = "yes"
	arity         = "variable"
	flags         = []
	attr_struct   = "phi_attr"
Matthias Braun's avatar
Matthias Braun committed
539
540
541
542
543
544
	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);
	'''
545
546
547
548
549
550
551
552

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

class Proj(Op):
553
554
555
556
557
558
559
560
	ins              = [ "pred" ]
	flags            = []
	pinned           = "no"
	knownBlock       = True
	knownGraph       = True
	block            = "get_nodes_block(irn_pred)"
	graph            = "get_irn_irg(irn_pred)"
	customSerializer = True
561
	attrs      = [
562
563
		dict(
			type = "long",
564
			name = "proj",
565
566
			initname = "",
			noprop = False,
567
		)
568
569
570
571
572
	]
	attr_struct = "long"

class Quot(Op):
	ins   = [ "mem", "left", "right" ]
573
574
575
576
577
578
	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"),
	]
579
580
	flags = [ "fragile", "uses_memory" ]
	attrs_name = "divmod"
581
	attrs = [
582
		dict(
583
584
585
			type = "ir_mode*",
			name = "resmode"
		),
586
587
588
589
590
591
592
593
	]
	attr_struct = "divmod_attr"
	pinned      = "exception"
	op_index    = 1
	arity_override = "oparity_binary"

class Raise(Op):
	ins    = [ "mem", "exo_ptr" ]
594
595
596
597
	outs  = [
		("M", "memory result",                     "pn_Generic_M"),
		("X", "control flow to exception handler", "pn_Generic_X_regular"),
	]
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
	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"
617
	attrs  = [
618
		dict(
619
620
621
			type = "ir_entity*",
			name = "entity"
		)
622
623
624
625
626
627
628
629
630
631
632
633
634
	]
	attr_struct = "sel_attr"

class Shl(Binop):
	flags = []

class Shr(Binop):
	flags = []

class Shrs(Binop):
	flags = []

class Start(Op):
635
636
637
638
639
640
641
	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")
	]
642
643
644
645
646
647
648
	mode             = "mode_T"
	pinned           = "yes"
	flags            = [ "cfopcode" ]
	singleton        = True
	knownBlock       = True
	customSerializer = True
	block            = "get_irg_start_block(irg)"
649
650
651

class Store(Op):
	ins      = [ "mem", "ptr", "value" ]
652
653
654
655
656
	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"),
	]
657
658
659
660
	flags    = [ "fragile", "uses_memory" ]
	pinned   = "exception"
	attr_struct = "store_attr"
	pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
661
	constructor_args = [
662
		dict(
663
664
			type = "ir_cons_flags",
			name = "flags",
665
		),
666
667
668
669
670
671
672
673
674
675
	]

class Sub(Binop):
	flags = []

class SymConst(Op):
	mode       = "mode_P"
	flags      = [ "constlike", "start_block" ]
	knownBlock = True
	pinned     = "no"
676
	attrs      = [
677
		dict(
678
			type = "ir_entity*",
679
680
			name = "entity",
			noprop = True
681
		)
682
683
	]
	attr_struct = "symconst_attr"
684
	customSerializer = True
685
686
687
688
689

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

692
693
694
695
696
697
698
699
700
701
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)"
702
	flags      = [ "cfopcode", "start_block", "constlike", "dump_noblock" ]
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718

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