ir_spec.py 27.3 KB
Newer Older
1
2
3
from spec_util import abstract, setnodedefaults

class Op(object):
4
	"""Base class for firm nodes"""
5
6
7
abstract(Op)

class Unop(Op):
8
	"""Unary nodes have exactly 1 input"""
9
	name     = "unop"
10
11
12
	ins      = [
		("op",  "operand"),
	]
13
14
15
16
17
	op_index = 0
	pinned   = "no"
abstract(Unop)

class Binop(Op):
18
	"""Binary nodes have exactly 2 inputs"""
19
	name     = "binop"
20
21
22
23
	ins      = [
		( "left",   "first operand" ),
		( "right", "second operand" ),
	]
24
25
26
27
28
	op_index = 0
	pinned   = "no"
abstract(Binop)

class Add(Binop):
29
	"""returns the sum of its operands"""
30
	flags = [ "commutative" ]
31
32

class Alloc(Op):
33
34
35
	"""allocates a block of memory.
	It can be specified whether the variable should be allocated to the stack
	or to the heap."""
36
37
38
39
	ins   = [
		("mem",   "memory dependency" ),
		("count", "number of objects to allocate" ),
	]
40
41
42
43
44
45
	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"),
	]
46
47
	attrs = [
		dict(
48
49
50
			name    = "type",
			type    = "ir_type*",
			comment = "type of the allocated variable",
51
52
		),
		dict(
53
54
55
			name    = "where",
			type    = "ir_where_alloc",
			comment = "whether to allocate the variable on the stack or heap",
56
		)
57
	]
58
	flags       = [ "fragile", "uses_memory" ]
59
60
61
62
	pinned      = "yes"
	attr_struct = "alloc_attr"

class Anchor(Op):
63
64
65
66
67
68
	"""utiliy node used to "hold" nodes in a graph that might possibly not be
	reachable by other means or which should be reachable immediately without
	searching through the graph.
	Each firm-graph contains exactly one anchor node whose address is always
	known. All other well-known graph-nodes like Start, End, NoMem, Bad, ...
	are found by looking at the respective Anchor operand."""
69
70
71
72
73
74
75
76
77
	mode             = "mode_ANY"
	arity            = "variable"
	flags            = [ "dump_noblock" ]
	pinned           = "yes"
	attr_struct      = "irg_attr"
	knownBlock       = True
	singleton        = True
	noconstructor    = True
	customSerializer = True
78
79

class And(Binop):
80
	"""returns the result of a bitwise and operation of its operands"""
81
82
83
	flags    = [ "commutative" ]

class ASM(Op):
84
	"""executes assembler fragments of the target machine"""
85
86
87
88
89
90
91
92
	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
93
94
	attrs = [
		dict(
95
96
97
			name    = "input_constraints",
			type    = "ir_asm_constraint*",
			comment = "input constraints",
98
99
		),
		dict(
100
101
102
103
			name    = "n_output_constraints",
			type    = "int",
			noprop  = True,
			comment = "number of output constraints",
104
105
		),
		dict(
106
107
108
			name    = "output_constraints",
			type    = "ir_asm_constraint*",
			comment = "output constraints",
109
110
		),
		dict(
111
112
113
114
			name    = "n_clobbers",
			type    = "int",
			noprop  = True,
			comment = "number of clobbered registers/memory",
115
116
		),
		dict(
117
118
119
			name    = "clobbers",
			type    = "ident**",
			comment = "list of clobbered registers/memory",
120
121
		),
		dict(
122
123
124
			name    = "text",
			type    = "ident*",
			comment = "assembler text",
125
126
127
128
129
		),
	]
	# constructor is written manually at the moment, because of the clobbers+
	# constraints arrays needing special handling (2 arguments for 1 attribute)
	noconstructor = True
130
131

class Bad(Op):
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
	"""Bad nodes indicate invalid input, which is values which should never be
	computed.

	The typical use case for the Bad node is removing unreachable code.
	Frontends should set the current_block to Bad when it is clear that
	following code must be unreachable (ie. after a goto or return statement).
	Optimisations also set block predecessors to Bad when it becomes clear,
	that a control flow edge can never be executed.

	The gigo optimisations ensures that nodes with Bad as their block, get
	replaced by Bad themselfes. Nodes with at least 1 Bad input get exchanged
	with Bad too. Exception to this rule are Block, Phi, Tuple and End node;
	This is because removing inputs from a Block is hairy operation (requiring,
	Phis to be shortened too for example). So instead of removing block inputs
	they are set to Bad, and the actual removal is left to the control flow
	optimisation phase. Block, Phi, Tuple with only Bad inputs however are
	replaced by Bad right away."""
Matthias Braun's avatar
Matthias Braun committed
149
	flags         = [ "start_block", "dump_noblock" ]
150
151
	pinned        = "yes"
	knownBlock    = True
152
	block         = "get_irg_start_block(irg)"
153
	attr_struct   = "bad_attr"
154
	init = '''
155
	res->attr.bad.irg.irg = irg;
156
157
	'''

158
class Deleted(Op):
159
160
	"""Internal node which is temporary set to nodes which are already removed
	from the graph."""
161
162
163
164
165
	mode             = "mode_Bad"
	flags            = [ ]
	pinned           = "yes"
	noconstructor    = True
	customSerializer = True
166

167
class Block(Op):
168
	"""A basic block"""
169
170
171
172
173
174
175
176
	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
177
178

	init = '''
179
	res->attr.block.irg.irg     = irg;
Moritz Kroll's avatar
Moritz Kroll committed
180
181
	res->attr.block.backedge    = new_backedge_arr(irg->obst, arity);
	set_Block_matured(res, 1);
182
183

	/* Create and initialize array for Phi-node construction. */
184
185
186
	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*));
187
	}
188
	'''
189

190
class Borrow(Binop):
191
	"""Returns the borrow bit from and implied subtractions of its 2 operands"""
192
193
	flags = []

194
class Bound(Op):
195
196
	"""Performs a bounds-check: if lower <= index < upper then return index,
	otherwise throw an exception."""
197
198
199
200
201
202
	ins    = [
		("mem",    "memory dependency"),
		("index",  "value to test"),
		("lower",  "lower bound (inclusive)"),
		("upper",  "upper bound (exclusive)"),
	]
203
204
205
206
207
208
	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"),
	]
209
210
211
212
 	flags  = [ "fragile", "highlevel" ]
	pinned = "exception"
	pinned_init = "op_pin_state_pinned"
	attr_struct = "bound_attr"
213
	attrs_name  = "bound"
214
215

class Builtin(Op):
216
	"""performs a backend-specific builtin."""
217
218
219
	ins      = [
		("mem", "memory dependency"),
	]
220
	arity    = "variable"
221
222
223
224
	outs     = [
		("M",        "memory result", "pn_Generic_M"),
		("1_result", "first result",  "pn_Generic_other"),
	]
225
	flags    = [ "uses_memory" ]
226
	attrs    = [
227
		dict(
228
229
230
			type    = "ir_builtin_kind",
			name    = "kind",
			comment = "kind of builtin",
231
		),
232
		dict(
233
234
235
			type    = "ir_type*",
			name    = "type",
			comment = "method type for the builtin call",
236
		)
237
238
239
240
	]
	pinned      = "memory"
	pinned_init = "op_pin_state_pinned"
	attr_struct = "builtin_attr"
241
	init   = '''
242
243
244
	assert((get_unknown_type() == type) || is_Method_type(type));
	'''

245
class Call(Op):
246
247
248
249
	"""Calls other code. Control flow is transfered to ptr, additional
	operands are passed to the called code. Called code usually performs a
	return operation. The operands of this return operation are the result
	of the Call node."""
250
251
252
253
	ins      = [
		("mem",   "memory dependency"),
		("ptr",   "pointer to called code"),
	]
254
	arity    = "variable"
255
256
257
258
259
260
	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"),
	]
261
	flags    = [ "fragile", "uses_memory" ]
262
	attrs    = [
263
		dict(
264
265
266
			type    = "ir_type*",
			name    = "type",
			comment = "type of the call (usually type of the called procedure)",
267
268
269
270
271
		),
		dict(
			type = "unsigned",
			name = "tail_call",
			# the tail call attribute can only be set by analysis
272
			init = "0",
273
		)
274
275
276
277
	]
	attr_struct = "call_attr"
	pinned      = "memory"
	pinned_init = "op_pin_state_pinned"
278
279
	init = '''
	assert((get_unknown_type() == type) || is_Method_type(type));
280
	'''
281

282
class Carry(Binop):
283
284
	"""Computes the value of the carry-bit that would result when adding the 2
	operands"""
285
286
	flags = [ "commutative" ]

Michael Beck's avatar
Michael Beck committed
287
class Cast(Unop):
288
	"""perform a high-level type cast"""
289
290
	mode     = "get_irn_mode(irn_op)"
	flags    = [ "highlevel" ]
291
292
	attrs    = [
		dict(
293
294
295
			type    = "ir_type*",
			name    = "type",
			comment = "target type of the case",
296
		)
297
298
	]
	attr_struct = "cast_attr"
299
	init     = "assert(is_atomic_type(type));"
300
301

class Cmp(Binop):
302
	"""Compares its two operands and checks whether a specified
303
	   relation (like less or equal) is fulfilled."""
304
	flags = []
305
306
307
308
309
310
311
312
313
	mode  = "mode_b"
	attrs = [
		dict(
			type    = "ir_relation",
			name    = "relation",
			comment = "Comparison relation"
		)
	]
	attr_struct = "cmp_attr"
314
315

class Cond(Op):
316
317
318
319
320
321
322
323
324
325
326
327
328
	"""Conditionally change control flow. There are two versions of this node:

	Boolean Cond:
	Input:  A value of mode_b
	Output: A tuple of two control flows. The first is taken if the input is
	        false, the second if it is true.

	Switch Cond:
	Input:  A value of mode_Iu
	Output: A tuple of n control flows. If the Cond's input is i, control flow
	will proceed along output i. If the input is >= n control flow proceeds
	along output def_proj.
	"""
329
330
331
	ins      = [
		("selector",  "condition parameter"),
	]
332
333
334
335
	outs     = [
		("false", "control flow if operand is \"false\""),
		("true",  "control flow if operand is \"true\""),
	]
336
337
	flags    = [ "cfopcode", "forking" ]
	pinned   = "yes"
338
339
	attrs    = [
		dict(
340
341
342
343
			name    = "default_proj",
			type    = "long",
			init    = "0",
			comment = "Proj-number of default case for switch-Cond",
344
345
		),
		dict(
346
347
348
349
			name    = "jmp_pred",
			type    = "cond_jmp_predicate",
			init    = "COND_JMP_PRED_NONE",
			comment = "can indicate the most likely jump",
350
		)
351
	]
352
	attr_struct = "cond_attr"
353

354
class Confirm(Op):
355
356
357
358
359
360
361
362
363
	"""Specifies constraints for a value. This allows explicit representation
	of path-sensitive properties. (Example: This value is always >= 0 on 1
	if-branch then all users within that branch are rerouted to a confirm-node
	specifying this property).

	A constraint is specified for the relation between value and bound.
	value is always returned.
	Note that this node does NOT check or assert the constraint, it merely
	specifies it."""
364
365
366
367
	ins      = [
		("value",  "value to express a constraint for"),
		("bound",  "value to compare against"),
	]
368
369
370
	mode     = "get_irn_mode(irn_value)"
	flags    = [ "highlevel" ]
	pinned   = "yes"
371
372
	attrs    = [
		dict(
373
374
375
			name    = "relation",
			type    = "ir_relation",
			comment = "relation of value to bound",
376
		),
377
378
	]
	attr_struct = "confirm_attr"
379
	attrs_name  = "confirm"
380
381

class Const(Op):
382
	"""Returns a constant value."""
383
	flags      = [ "constlike", "start_block" ]
384
385
	block      = "get_irg_start_block(irg)"
	mode       = "get_tarval_mode(tarval)"
386
387
	knownBlock = True
	pinned     = "no"
388
389
	attrs      = [
		dict(
390
391
392
			type    = "ir_tarval*",
			name    = "tarval",
			comment = "constant value (a tarval object)",
393
		)
394
395
	]
	attr_struct = "const_attr"
396
	attrs_name  = "con"
397

398
class Conv(Unop):
399
	"""Converts values between modes"""
400
	flags = []
401
402
	attrs = [
		dict(
403
404
405
406
			name    = "strict",
			type    = "int",
			init    = "0",
			comment = "force floating point to restrict precision even if backend computes in higher precision (deprecated)",
407
		)
408
409
	]
	attr_struct = "conv_attr"
410
	attrs_name  = "conv"
411
412

class CopyB(Op):
413
	"""Copies a block of memory"""
414
415
416
417
418
	ins   = [
		("mem",  "memory dependency"),
		("dst",  "destination address"),
		("src",  "source address"),
	]
419
420
421
422
423
	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"),
	]
424
	flags = [ "fragile", "uses_memory" ]
425
426
	attrs = [
		dict(
427
428
429
			name    = "type",
			type    = "ir_type*",
			comment = "type of copied data",
430
		)
431
432
	]
	attr_struct = "copyb_attr"
433
	attrs_name  = "copyb"
434
435
	pinned      = "memory"
	pinned_init = "op_pin_state_pinned"
436

437
class Div(Op):
438
	"""returns the quotient of its 2 operands"""
439
440
441
442
443
	ins   = [
		("mem",   "memory dependency"),
		("left",  "first operand"),
		("right", "second operand"),
	]
444
445
446
447
448
449
	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"),
	]
450
	flags = [ "fragile", "uses_memory" ]
451
	attrs_name = "div"
452
453
	attrs = [
		dict(
454
455
456
			type    = "ir_mode*",
			name    = "resmode",
			comment = "mode of the result value",
457
		),
Moritz Kroll's avatar
Moritz Kroll committed
458
459
460
461
		dict(
			name = "no_remainder",
			type = "int",
			init = "0",
462
		)
463
	]
464
	attr_struct = "div_attr"
465
466
467
	pinned      = "exception"
	op_index    = 1
	arity_override = "oparity_binary"
468

469
class Dummy(Op):
470
471
472
	"""A placeholder value. This is used when constructing cyclic graphs where
	you have cases where not all predecessors of a phi-node are known. Dummy
	nodes are used for the unknown predecessors and replaced later."""
473
474
	ins        = []
	flags      = [ "cfopcode", "start_block", "constlike", "dump_noblock" ]
475
476
477
478
479
	knownBlock = True
	pinned     = "yes"
	block      = "get_irg_start_block(irg)"

class End(Op):
480
481
	"""Last node of a graph. It references nodes in endless loops (so called
	keepalive edges)"""
482
483
484
485
486
487
488
489
	mode             = "mode_X"
	pinned           = "yes"
	arity            = "dynamic"
	flags            = [ "cfopcode" ]
	knownBlock       = True
	block            = "get_irg_end_block(irg)"
	singleton        = True
	customSerializer = True
490
491

class Eor(Binop):
492
	"""returns the result of a bitwise exclusive or operation of its operands"""
493
	flags    = [ "commutative" ]
494

495
class Free(Op):
496
	"""Frees a block of memory previously allocated by an Alloc node"""
497
498
499
500
501
	ins    = [
		("mem",   "memory dependency" ),
		("ptr",   "pointer to the object to free"),
		("size",  "number of objects to allocate" ),
	]
502
503
504
	mode   = "mode_M"
	flags  = [ "uses_memory" ]
	pinned = "yes"
505
	attrs  = [
506
		dict(
507
508
509
			name    = "type",
			type    = "ir_type*",
			comment = "type of the allocated variable",
510
511
		),
		dict(
512
513
514
			name    = "where",
			type    = "ir_where_alloc",
			comment = "whether allocation was on the stack or heap",
515
		)
516
517
518
519
	]
	attr_struct = "free_attr"

class Id(Op):
520
	"""Returns its operand unchanged."""
521
522
523
	ins    = [
	   ("pred", "the value which is returned unchanged")
	]
524
525
526
527
	pinned = "no"
	flags  = []

class IJmp(Op):
528
529
530
	"""Jumps to the code in its argument. The code has to be in the same
	function and the the destination must be one of the blocks reachable
	by the tuple results"""
531
532
	mode     = "mode_X"
	pinned   = "yes"
533
534
535
	ins      = [
	   ("target", "target address of the jump"),
	]
536
	flags    = [ "cfopcode", "forking", "keep", "unknown_jump" ]
537
538

class InstOf(Op):
539
	"""Tests whether an object is an instance of a class-type"""
540
541
542
543
	ins   = [
	   ("store", "memory dependency"),
	   ("obj",   "pointer to object being queried")
	]
544
545
546
547
548
549
	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"),
	]
550
	flags = [ "highlevel" ]
551
552
	attrs = [
		dict(
553
554
555
			name    = "type",
			type    = "ir_type*",
			comment = "type to check ptr for",
556
		)
557
558
559
560
561
562
	]
	attr_struct = "io_attr"
	pinned      = "memory"
	pinned_init = "op_pin_state_floats"

class Jmp(Op):
563
	"""Jumps to the block connected through the out-value"""
564
565
566
567
568
569
	mode     = "mode_X"
	pinned   = "yes"
	ins      = []
	flags    = [ "cfopcode" ]

class Load(Op):
570
	"""Loads a value from memory (heap or stack)."""
571
572
573
574
	ins   = [
		("mem", "memory dependency"),
		("ptr",  "address to load from"),
	]
575
576
577
578
579
580
	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"),
	]
581
582
	flags    = [ "fragile", "uses_memory" ]
	pinned   = "exception"
583
584
	attrs    = [
		dict(
585
586
587
			type      = "ir_mode*",
			name      = "mode",
			comment   = "mode of the value to be loaded",
588
		),
589
590
591
592
593
594
595
596
597
598
599
600
		dict(
			type      = "ir_volatility",
			name      = "volatility",
			comment   = "volatile loads are a visible side-effect and may not be optimized",
			init      = "flags & cons_volatile ? volatility_is_volatile : volatility_non_volatile",
		),
		dict(
			type      = "ir_align",
			name      = "unaligned",
			comment   = "pointers to unaligned loads don't need to respect the load-mode/type alignments",
			init      = "flags & cons_unaligned ? align_non_aligned : align_is_aligned",
		),
601
602
	]
	attr_struct = "load_attr"
603
604
	constructor_args = [
		dict(
605
606
607
			type    = "ir_cons_flags",
			name    = "flags",
			comment = "specifies alignment, volatility and pin state",
608
		),
609
	]
610
	pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
611
612

class Minus(Unop):
613
	"""returns the difference between its operands"""
614
615
616
	flags = []

class Mod(Op):
617
618
619
620
621
622
623
624
	"""returns the remainder of its operands from an implied division.

	Examples:
	* mod(5,3)   produces 2
	* mod(5,-3)  produces 2
	* mod(-5,3)  produces -2
	* mod(-5,-3) produces -2
	"""
625
626
627
628
629
	ins   = [
		("mem",   "memory dependency"),
		("left",  "first operand"),
		("right", "second operand"),
	]
630
631
632
633
634
635
	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"),
	]
636
	flags = [ "fragile", "uses_memory" ]
637
	attrs_name = "mod"
638
	attrs = [
639
		dict(
640
641
642
			type    = "ir_mode*",
			name    = "resmode",
			comment = "mode of the result",
643
		),
644
	]
645
	attr_struct = "mod_attr"
646
647
648
	pinned      = "exception"
	op_index    = 1
	arity_override = "oparity_binary"
Matthias Braun's avatar
Matthias Braun committed
649

650
class Mul(Binop):
651
	"""returns the product of its operands"""
652
653
654
	flags = [ "commutative" ]

class Mulh(Binop):
655
656
	"""returns the upper word of the product of its operands (the part which
	would not fit into the result mode of a normal Mul anymore)"""
657
658
659
	flags = [ "commutative" ]

class Mux(Op):
660
661
	"""returns the false or true operand depending on the value of the sel
	operand"""
662
663
664
665
666
	ins    = [
	   ("sel",   "value making the output selection"),
	   ("false", "selected if sel input is false"),
	   ("true",  "selected if sel input is true"),
	]
667
668
669
670
	flags  = []
	pinned = "no"

class NoMem(Op):
671
	"""Placeholder node for cases where you don't need any memory input"""
672
673
674
675
	mode          = "mode_M"
	flags         = [ "dump_noblock", "dump_noinput" ]
	pinned        = "yes"
	knownBlock    = True
676
	block         = "get_irg_start_block(irg)"
677
	singleton     = True
678
679

class Not(Unop):
680
681
682
	"""returns the logical complement of a value. Works for integer values too.
	If the input is false/zero then true/one is returned, otherwise false/zero
	is returned."""
683
684
685
	flags = []

class Or(Binop):
686
	"""returns the result of a bitwise or operation of its operands"""
687
688
689
	flags = [ "commutative" ]

class Phi(Op):
690
691
692
	"""Choose a value based on control flow. A phi node has 1 input for each
	predecessor of its block. If a block is entered from its nth predecessor
	all phi nodes produce their nth input as result."""
693
694
695
696
	pinned        = "yes"
	arity         = "variable"
	flags         = []
	attr_struct   = "phi_attr"
697
698
699
	init          = '''
	res->attr.phi.u.backedge = new_backedge_arr(irg->obst, arity);'''
	init_after_opt = '''
Matthias Braun's avatar
Matthias Braun committed
700
701
	/* Memory Phis in endless loops must be kept alive.
	   As we can't distinguish these easily we keep all of them alive. */
702
703
	if (is_Phi(res) && mode == mode_M)
		add_End_keepalive(get_irg_end(irg), res);'''
704
705

class Pin(Op):
706
707
708
	"""Pin the value of the node node in the current block. No users of the Pin
	node can float above the Block of the Pin. The node cannot float behind
	this block. Often used to Pin the NoMem node."""
709
710
711
	ins      = [
		("op", "value which is pinned"),
	]
712
713
714
715
716
	mode     = "get_irn_mode(irn_op)"
	flags    = [ "highlevel" ]
	pinned   = "yes"

class Proj(Op):
717
	"""returns an entry of a tuple value"""
718
719
720
	ins              = [
		("pred", "the tuple value from which a part is extracted"),
	]
721
722
723
724
725
726
727
	flags            = []
	pinned           = "no"
	knownBlock       = True
	knownGraph       = True
	block            = "get_nodes_block(irn_pred)"
	graph            = "get_irn_irg(irn_pred)"
	customSerializer = True
728
	attrs      = [
729
		dict(
730
731
732
			type    = "long",
			name    = "proj",
			comment = "number of tuple component to be extracted",
733
		),
734
	]
735
	attr_struct = "proj_attr"
736
737

class Raise(Op):
738
739
740
	"""Raises an exception. Unconditional change of control flow. Writes an
	explicit Except variable to memory to pass it to the exception handler.
	Must be lowered to a Call to a runtime check function."""
741
742
743
744
	ins    = [
		("mem",     "memory dependency"),
		("exo_ptr", "pointer to exception object to be thrown"),
	]
745
746
747
748
	outs  = [
		("M", "memory result",                     "pn_Generic_M"),
		("X", "control flow to exception handler", "pn_Generic_X_regular"),
	]
749
750
751
752
	flags  = [ "highlevel", "cfopcode" ]
	pinned = "yes"

class Return(Op):
753
754
	"""Returns from the current function. Takes memory and return values as
	operands."""
755
756
757
	ins      = [
		("mem", "memory dependency"),
	]
758
759
760
761
762
763
	arity    = "variable"
	mode     = "mode_X"
	flags    = [ "cfopcode" ]
	pinned   = "yes"

class Rotl(Binop):
764
765
	"""Returns its first operand bits rotated left by the amount in the 2nd
	operand"""
766
767
768
	flags    = []

class Sel(Op):
769
770
	"""Computes the address of a entity of a compound type given the base
	address of an instance of the compound type."""
771
772
773
774
	ins    = [
		("mem", "memory dependency"),
		("ptr", "pointer to object to select from"),
	]
775
776
777
778
	arity  = "variable"
	flags  = []
	mode   = "is_Method_type(get_entity_type(entity)) ? mode_P_code : mode_P_data"
	pinned = "no"
779
	attrs  = [
780
		dict(
781
782
783
			type    = "ir_entity*",
			name    = "entity",
			comment = "entity which is selected",
784
		)
785
786
787
788
	]
	attr_struct = "sel_attr"

class Shl(Binop):
789
790
	"""Returns its first operands bits shifted left by the amount of the 2nd
	operand"""
791
792
793
	flags = []

class Shr(Binop):
794
795
	"""Returns its first operands bits shifted right by the amount of the 2nd
	operand. No special handling for the sign bit (zero extension)"""
796
797
798
	flags = []

class Shrs(Binop):
799
800
801
	"""Returns its first operands bits shifted right by the amount of the 2nd
	operand. The leftmost bit (usually the sign bit) stays the same
	(sign extension)"""
802
803
804
	flags = []

class Start(Op):
805
	"""The first node of a graph. Execution starts with this node."""
806
807
808
809
810
811
	outs       = [
		("X_initial_exec", "control flow"),
		("M",              "initial memory"),
		("P_frame_base",   "frame base pointer"),
		("T_args",         "function arguments")
	]
812
813
814
815
816
817
818
	mode             = "mode_T"
	pinned           = "yes"
	flags            = [ "cfopcode" ]
	singleton        = True
	knownBlock       = True
	customSerializer = True
	block            = "get_irg_start_block(irg)"
819
820

class Store(Op):
821
	"""Stores a value into memory (heap or stack)."""
822
823
824
825
826
	ins   = [
	   ("mem",   "memory dependency"),
	   ("ptr",   "address to store to"),
	   ("value", "value to store"),
	]
827
828
829
830
831
	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"),
	]
832
833
834
835
	flags    = [ "fragile", "uses_memory" ]
	pinned   = "exception"
	attr_struct = "store_attr"
	pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
836
837
838
839
840
841
842
843
844
845
846
847
848
849
	attrs = [
		dict(
			type      = "ir_volatility",
			name      = "volatility",
			comment   = "volatile stores are a visible side-effect and may not be optimized",
			init      = "flags & cons_volatile ? volatility_is_volatile : volatility_non_volatile",
		),
		dict(
			type      = "ir_align",
			name      = "unaligned",
			comment   = "pointers to unaligned stores don't need to respect the load-mode/type alignments",
			init      = "flags & cons_unaligned ? align_non_aligned : align_is_aligned",
		),
	]
850
	constructor_args = [
851
		dict(
852
853
854
			type    = "ir_cons_flags",
			name    = "flags",
			comment = "specifies alignment, volatility and pin state",
855
		),
856
857
858
	]

class Sub(Binop):
859
	"""returns the difference of its operands"""
860
861
862
	flags = []

class SymConst(Op):
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
	"""A symbolic constant.

	 - symconst_type_tag   The symbolic constant represents a type tag.  The
	                       type the tag stands for is given explicitly.
	 - symconst_type_size  The symbolic constant represents the size of a type.
	                       The type of which the constant represents the size
	                       is given explicitly.
	 - symconst_type_align The symbolic constant represents the alignment of a
	                       type.  The type of which the constant represents the
	                       size is given explicitly.
	 - symconst_addr_ent   The symbolic constant represents the address of an
	                       entity (variable or method).  The variable is given
	                       explicitly by a firm entity.
	 - symconst_ofs_ent    The symbolic constant represents the offset of an
	                       entity in its owner type.
	 - symconst_enum_const The symbolic constant is a enumeration constant of
	                       an enumeration type."""
880
881
882
883
	mode       = "mode_P"
	flags      = [ "constlike", "start_block" ]
	knownBlock = True
	pinned     = "no"
884
	attrs      = [
885
		dict(
886
887
888
889
			type    = "ir_entity*",
			name    = "entity",
			noprop  = True,
			comment = "entity whose address is returned",
890
		)
891
892
	]
	attr_struct = "symconst_attr"
893
	customSerializer = True
894
895
896
	# constructor is written manually at the moment, because of the strange
	# union argument
	noconstructor = True
897
898

class Sync(Op):
899
900
901
902
903
	"""The Sync operation unifies several partial memory blocks. These blocks
	have to be pairwise disjunct or the values in common locations have to
	be identical.  This operation allows to specify all operations that
	eventually need several partial memory blocks as input with a single
	entrance by unifying the memories with a preceding Sync operation."""
904
905
906
	mode     = "mode_M"
	flags    = []
	pinned   = "no"
907
	arity    = "dynamic"
908

909
class Tuple(Op):
910
911
912
913
914
915
916
	"""Builds a Tuple from single values.

	This is needed to implement optimizations that remove a node that produced
	a tuple.  The node can be replaced by the Tuple operation so that the
	following Proj nodes have not to be changed. (They are hard to find due to
	the implementation with pointers in only one direction.) The Tuple node is
	smaller than any other node, so that a node can be changed into a Tuple by
917
	just changing its opcode and giving it a new in array."""
918
919
920
921
922
923
	arity  = "variable"
	mode   = "mode_T"
	pinned = "no"
	flags  = [ "labeled" ]

class Unknown(Op):
924
925
	"""Returns an unknown (at compile- and runtime) value. It is a valid
	optimisation to replace an Unknown by any other constant value."""
926
927
928
	knownBlock = True
	pinned     = "yes"
	block      = "get_irg_start_block(irg)"
Matthias Braun's avatar
Matthias Braun committed
929
	flags      = [ "start_block", "constlike", "dump_noblock" ]
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945

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