ir_spec.py 28 KB
Newer Older
Matthias Braun's avatar
Matthias Braun committed
1
2
3
# Firm node specifications
# The comments are in (standard python) restructured text format and are used
# to generate documentation.
Matthias Braun's avatar
Matthias Braun committed
4
from spec_util import abstract, op
5

Matthias Braun's avatar
Matthias Braun committed
6
name = "ir"
7

Matthias Braun's avatar
Matthias Braun committed
8
9
10
@abstract
@op
class Unop(object):
11
	"""Unary nodes have exactly 1 input"""
12
	name     = "unop"
13
14
15
	ins      = [
		("op",  "operand"),
	]
16
17
18
	op_index = 0
	pinned   = "no"

Matthias Braun's avatar
Matthias Braun committed
19
20
21
@abstract
@op
class Binop(object):
22
	"""Binary nodes have exactly 2 inputs"""
23
	name     = "binop"
24
25
26
27
	ins      = [
		( "left",   "first operand" ),
		( "right", "second operand" ),
	]
28
29
30
	op_index = 0
	pinned   = "no"

Matthias Braun's avatar
Matthias Braun committed
31
@op
32
class Add(Binop):
33
	"""returns the sum of its operands"""
34
	flags = [ "commutative" ]
35

Matthias Braun's avatar
Matthias Braun committed
36
37
@op
class Alloc:
38
	"""allocates a block of memory.
Matthias Braun's avatar
Matthias Braun committed
39
40
41
42
	It can be specified whether the memory should be allocated to the stack
	or to the heap.
	Allocates memory for one or more objects (depending on value on count input).
	"""
43
44
45
46
	ins   = [
		("mem",   "memory dependency" ),
		("count", "number of objects to allocate" ),
	]
47
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
48
		("M",         "memory result"),
49
		("res",       "pointer to newly allocated memory"),
Matthias Braun's avatar
Matthias Braun committed
50
51
		("X_regular", "control flow when no exception occurs"),
		("X_except",  "control flow when exception occured"),
52
	]
53
54
	attrs = [
		dict(
55
56
			name    = "type",
			type    = "ir_type*",
Matthias Braun's avatar
Matthias Braun committed
57
			comment = "type of the objects to allocate",
58
59
		),
		dict(
60
61
62
			name    = "where",
			type    = "ir_where_alloc",
			comment = "whether to allocate the variable on the stack or heap",
63
		)
64
	]
65
	flags       = [ "fragile", "uses_memory" ]
66
	pinned      = "exception"
67
	throws_init = "false"
68
	pinned_init = "op_pin_state_pinned"
69
70
	attr_struct = "alloc_attr"

Matthias Braun's avatar
Matthias Braun committed
71
72
@op
class Anchor:
73
74
75
76
77
78
	"""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."""
79
80
81
82
83
84
85
86
87
	mode             = "mode_ANY"
	arity            = "variable"
	flags            = [ "dump_noblock" ]
	pinned           = "yes"
	attr_struct      = "irg_attr"
	knownBlock       = True
	singleton        = True
	noconstructor    = True
	customSerializer = True
88

Matthias Braun's avatar
Matthias Braun committed
89
@op
90
class And(Binop):
91
	"""returns the result of a bitwise and operation of its operands"""
92
93
	flags    = [ "commutative" ]

Matthias Braun's avatar
Matthias Braun committed
94
95
@op
class ASM:
Matthias Braun's avatar
Matthias Braun committed
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
	"""executes assembler fragments of the target machine.

	The node contains a template for an assembler snippet. The compiler will
	replace occurences of %0 to %9 with input/output registers,
	%% with a single % char. Some backends allow additional specifiers (for
	example %w3, %l3, %h3 on x86 to get a 16bit, 8hit low, 8bit high part
	of a register).
	After the replacements the text is emitted into the final assembly.

	The clobber list contains names of registers which have an undefined value
	after the assembler instruction is executed; it may also contain 'memory'
	or 'cc' if global state/memory changes or the condition code registers
	(some backends implicitely set cc, memory clobbers on all ASM statements).

	Example (an i386 instruction)::

		ASM(text="btsl %1, %0",
			input_constraints = ["=m", "r"],
			clobbers = ["cc"])

	As there are no output, the %0 references the first input which is just an
	address which the asm operation writes to. %1 references to an input which
	is passed as a register. The condition code register has an unknown value
	after the instruction.

	(This format is inspired by the gcc extended asm syntax)
	"""
123
124
125
126
127
128
129
130
	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
131
132
133
	ins   = [
		("mem",    "memory dependency"),
	]
134
135
	attrs = [
		dict(
136
137
138
			name    = "input_constraints",
			type    = "ir_asm_constraint*",
			comment = "input constraints",
139
140
		),
		dict(
141
			name    = "n_output_constraints",
142
			type    = "size_t",
143
144
			noprop  = True,
			comment = "number of output constraints",
145
146
		),
		dict(
147
148
149
			name    = "output_constraints",
			type    = "ir_asm_constraint*",
			comment = "output constraints",
150
151
		),
		dict(
152
			name    = "n_clobbers",
153
			type    = "size_t",
154
155
			noprop  = True,
			comment = "number of clobbered registers/memory",
156
157
		),
		dict(
158
159
160
			name    = "clobbers",
			type    = "ident**",
			comment = "list of clobbered registers/memory",
161
162
		),
		dict(
163
164
165
			name    = "text",
			type    = "ident*",
			comment = "assembler text",
166
167
168
169
170
		),
	]
	# constructor is written manually at the moment, because of the clobbers+
	# constraints arrays needing special handling (2 arguments for 1 attribute)
	noconstructor = True
171

Matthias Braun's avatar
Matthias Braun committed
172
173
@op
class Bad:
174
175
176
177
178
179
180
181
182
183
	"""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
Christoph Mallon's avatar
Christoph Mallon committed
184
	replaced by Bad themselves. Nodes with at least 1 Bad input get exchanged
185
186
187
188
189
190
	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
191
	flags         = [ "start_block", "dump_noblock" ]
192
193
	pinned        = "yes"
	knownBlock    = True
194
	block         = "get_irg_start_block(irg)"
195
	attr_struct   = "bad_attr"
196
	init = '''
197
	res->attr.bad.irg.irg = irg;
198
199
	'''

Matthias Braun's avatar
Matthias Braun committed
200
201
@op
class Deleted:
202
203
	"""Internal node which is temporary set to nodes which are already removed
	from the graph."""
204
205
206
207
	mode             = "mode_Bad"
	flags            = [ ]
	pinned           = "yes"
	noconstructor    = True
Matthias Braun's avatar
Matthias Braun committed
208
	customSerializer = True # this has no serializer
209

Matthias Braun's avatar
Matthias Braun committed
210
211
@op
class Block:
212
	"""A basic block"""
213
214
215
216
217
	mode             = "mode_BB"
	knownBlock       = True
	block            = "NULL"
	pinned           = "yes"
	arity            = "variable"
218
	flags            = []
219
	attr_struct      = "block_attr"
220
221
222
223
224
225
226
227
	attrs            = [
		dict(
			name    = "entity",
			type    = "ir_entity*",
			comment = "entity representing this block",
			init    = "NULL",
		),
	]
228
	customSerializer = True
Moritz Kroll's avatar
Moritz Kroll committed
229
230

	init = '''
231
	res->attr.block.irg.irg     = irg;
232
	res->attr.block.backedge    = new_backedge_arr(get_irg_obstack(irg), arity);
Moritz Kroll's avatar
Moritz Kroll committed
233
	set_Block_matured(res, 1);
234
235

	/* Create and initialize array for Phi-node construction. */
236
	if (irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_CONSTRUCTION)) {
237
		res->attr.block.graph_arr = NEW_ARR_DZ(ir_node*, get_irg_obstack(irg), irg->n_loc);
238
	}
239
	'''
240

Matthias Braun's avatar
Matthias Braun committed
241
@op
242
class Borrow(Binop):
243
	"""Returns the borrow bit from and implied subtractions of its 2 operands"""
244
245
	flags = []

Matthias Braun's avatar
Matthias Braun committed
246
247
@op
class Bound:
248
249
	"""Performs a bounds-check: if lower <= index < upper then return index,
	otherwise throw an exception."""
250
251
252
253
254
255
	ins    = [
		("mem",    "memory dependency"),
		("index",  "value to test"),
		("lower",  "lower bound (inclusive)"),
		("upper",  "upper bound (exclusive)"),
	]
256
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
257
		("M",         "memory result"),
258
		("res",       "the checked index"),
Matthias Braun's avatar
Matthias Braun committed
259
260
		("X_regular", "control flow when no exception occurs"),
		("X_except",  "control flow when exception occured"),
261
	]
262
263
264
 	flags  = [ "fragile", "highlevel" ]
	pinned = "exception"
	pinned_init = "op_pin_state_pinned"
265
	throws_init = "false"
266
267
	attr_struct = "bound_attr"

Matthias Braun's avatar
Matthias Braun committed
268
269
@op
class Builtin:
270
	"""performs a backend-specific builtin."""
271
272
273
	ins      = [
		("mem", "memory dependency"),
	]
274
	arity    = "variable"
275
	outs     = [
276
277
		("M", "memory result"),
		# results follow here
278
	]
279
	flags    = [ "uses_memory" ]
280
	attrs    = [
281
		dict(
282
283
284
			type    = "ir_builtin_kind",
			name    = "kind",
			comment = "kind of builtin",
285
		),
286
		dict(
287
288
289
			type    = "ir_type*",
			name    = "type",
			comment = "method type for the builtin call",
290
		)
291
292
293
294
	]
	pinned      = "memory"
	pinned_init = "op_pin_state_pinned"
	attr_struct = "builtin_attr"
295
	init   = '''
296
297
298
	assert((get_unknown_type() == type) || is_Method_type(type));
	'''

Matthias Braun's avatar
Matthias Braun committed
299
300
@op
class Call:
301
302
303
304
	"""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."""
305
306
307
308
	ins      = [
		("mem",   "memory dependency"),
		("ptr",   "pointer to called code"),
	]
309
	arity    = "variable"
310
	outs     = [
Matthias Braun's avatar
Matthias Braun committed
311
		("M",                "memory result"),
312
		("T_result",         "tuple containing all results"),
Matthias Braun's avatar
Matthias Braun committed
313
314
		("X_regular",        "control flow when no exception occurs"),
		("X_except",         "control flow when exception occured"),
315
	]
316
	flags    = [ "fragile", "uses_memory" ]
317
	attrs    = [
318
		dict(
319
320
321
			type    = "ir_type*",
			name    = "type",
			comment = "type of the call (usually type of the called procedure)",
322
		),
323
324
325
326
	]
	attr_struct = "call_attr"
	pinned      = "memory"
	pinned_init = "op_pin_state_pinned"
327
	throws_init = "false"
328
329
	init = '''
	assert((get_unknown_type() == type) || is_Method_type(type));
330
	'''
331

Matthias Braun's avatar
Matthias Braun committed
332
@op
333
class Carry(Binop):
334
335
	"""Computes the value of the carry-bit that would result when adding the 2
	operands"""
336
337
	flags = [ "commutative" ]

Matthias Braun's avatar
Matthias Braun committed
338
@op
Michael Beck's avatar
Michael Beck committed
339
class Cast(Unop):
340
	"""perform a high-level type cast"""
341
342
	mode     = "get_irn_mode(irn_op)"
	flags    = [ "highlevel" ]
343
344
	attrs    = [
		dict(
345
346
347
			type    = "ir_type*",
			name    = "type",
			comment = "target type of the case",
348
		)
349
350
	]
	attr_struct = "cast_attr"
351
	init     = "assert(is_atomic_type(type));"
352

Matthias Braun's avatar
Matthias Braun committed
353
@op
354
class Cmp(Binop):
355
	"""Compares its two operands and checks whether a specified
356
	   relation (like less or equal) is fulfilled."""
357
	flags = []
358
359
360
361
362
363
364
365
366
	mode  = "mode_b"
	attrs = [
		dict(
			type    = "ir_relation",
			name    = "relation",
			comment = "Comparison relation"
		)
	]
	attr_struct = "cmp_attr"
367

Matthias Braun's avatar
Matthias Braun committed
368
369
@op
class Cond:
370
	"""Conditionally change control flow."""
371
372
373
	ins      = [
		("selector",  "condition parameter"),
	]
374
375
376
377
	outs     = [
		("false", "control flow if operand is \"false\""),
		("true",  "control flow if operand is \"true\""),
	]
378
379
	flags    = [ "cfopcode", "forking" ]
	pinned   = "yes"
380
381
	attrs    = [
		dict(
382
383
384
385
			name    = "jmp_pred",
			type    = "cond_jmp_predicate",
			init    = "COND_JMP_PRED_NONE",
			comment = "can indicate the most likely jump",
Matthias Braun's avatar
Matthias Braun committed
386
		),
387
	]
388
	attr_struct = "cond_attr"
389

Matthias Braun's avatar
Matthias Braun committed
390
391
@op
class Switch:
Matthias Braun's avatar
Matthias Braun committed
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
	"""Change control flow. The destination is choosen based on an integer input value which is looked up in a table.

	Backends can implement this efficiently using a jump table."""
	ins    = [
		("selector", "input selector"),
	]
	outs   = [
		("default", "control flow if no other case matches"),
	]
	flags  = [ "cfopcode", "forking" ]
	pinned = "yes"
	attrs  = [
		dict(
			name    = "n_outs",
			type    = "unsigned",
			comment = "number of outputs (including pn_Switch_default)",
		),
		dict(
			name    = "table",
			type    = "ir_switch_table*",
			comment = "table describing mapping from input values to Proj numbers",
		),
	]
	attr_struct = "switch_attr"
	attrs_name  = "switcha"

Matthias Braun's avatar
Matthias Braun committed
418
419
@op
class Confirm:
420
421
422
423
424
425
426
427
428
	"""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."""
429
430
431
432
	ins      = [
		("value",  "value to express a constraint for"),
		("bound",  "value to compare against"),
	]
433
434
435
	mode     = "get_irn_mode(irn_value)"
	flags    = [ "highlevel" ]
	pinned   = "yes"
436
437
	attrs    = [
		dict(
438
439
440
			name    = "relation",
			type    = "ir_relation",
			comment = "relation of value to bound",
441
		),
442
443
444
	]
	attr_struct = "confirm_attr"

Matthias Braun's avatar
Matthias Braun committed
445
446
@op
class Const:
447
	"""Returns a constant value."""
448
	flags      = [ "constlike", "start_block" ]
449
450
	block      = "get_irg_start_block(irg)"
	mode       = "get_tarval_mode(tarval)"
451
452
	knownBlock = True
	pinned     = "no"
453
454
	attrs      = [
		dict(
455
456
457
			type    = "ir_tarval*",
			name    = "tarval",
			comment = "constant value (a tarval object)",
458
		)
459
460
	]
	attr_struct = "const_attr"
461
	attrs_name  = "con"
462

Matthias Braun's avatar
Matthias Braun committed
463
@op
464
class Conv(Unop):
465
	"""Converts values between modes"""
466
467
	flags = []

Matthias Braun's avatar
Matthias Braun committed
468
469
@op
class CopyB:
Matthias Braun's avatar
Matthias Braun committed
470
	"""Copies a block of memory with statically known size/type."""
471
472
473
474
475
	ins   = [
		("mem",  "memory dependency"),
		("dst",  "destination address"),
		("src",  "source address"),
	]
476
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
477
478
479
		("M",         "memory result"),
		("X_regular", "control flow when no exception occurs"),
		("X_except",  "control flow when exception occured"),
480
	]
481
	flags = [ "fragile", "uses_memory" ]
482
483
	attrs = [
		dict(
484
485
486
			name    = "type",
			type    = "ir_type*",
			comment = "type of copied data",
487
		)
488
489
490
491
	]
	attr_struct = "copyb_attr"
	pinned      = "memory"
	pinned_init = "op_pin_state_pinned"
492
	throws_init = "false"
493

Matthias Braun's avatar
Matthias Braun committed
494
495
@op
class Div:
496
	"""returns the quotient of its 2 operands"""
497
498
499
500
501
	ins   = [
		("mem",   "memory dependency"),
		("left",  "first operand"),
		("right", "second operand"),
	]
502
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
503
		("M",         "memory result"),
504
		("res",       "result of computation"),
Matthias Braun's avatar
Matthias Braun committed
505
506
		("X_regular", "control flow when no exception occurs"),
		("X_except",  "control flow when exception occured"),
507
	]
508
	flags = [ "fragile", "uses_memory" ]
509
510
	attrs = [
		dict(
511
512
513
			type    = "ir_mode*",
			name    = "resmode",
			comment = "mode of the result value",
514
		),
Moritz Kroll's avatar
Moritz Kroll committed
515
516
517
518
		dict(
			name = "no_remainder",
			type = "int",
			init = "0",
519
		)
520
	]
521
	attr_struct = "div_attr"
522
	pinned      = "exception"
523
	throws_init = "false"
524
525
	op_index    = 1
	arity_override = "oparity_binary"
526

Matthias Braun's avatar
Matthias Braun committed
527
528
@op
class Dummy:
529
530
531
	"""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."""
532
533
	ins        = []
	flags      = [ "cfopcode", "start_block", "constlike", "dump_noblock" ]
534
535
536
537
	knownBlock = True
	pinned     = "yes"
	block      = "get_irg_start_block(irg)"

Matthias Braun's avatar
Matthias Braun committed
538
539
@op
class End:
540
541
	"""Last node of a graph. It references nodes in endless loops (so called
	keepalive edges)"""
542
543
544
545
546
547
548
	mode             = "mode_X"
	pinned           = "yes"
	arity            = "dynamic"
	flags            = [ "cfopcode" ]
	knownBlock       = True
	block            = "get_irg_end_block(irg)"
	singleton        = True
549

Matthias Braun's avatar
Matthias Braun committed
550
@op
551
class Eor(Binop):
Matthias Braun's avatar
Matthias Braun committed
552
553
554
	"""returns the result of a bitwise exclusive or operation of its operands.

	This is also known as the Xor operation."""
555
	flags    = [ "commutative" ]
556

Matthias Braun's avatar
Matthias Braun committed
557
558
@op
class Free:
559
	"""Frees a block of memory previously allocated by an Alloc node"""
560
561
562
	ins    = [
		("mem",   "memory dependency" ),
		("ptr",   "pointer to the object to free"),
563
		("count", "number of objects to allocate" ),
564
	]
565
566
567
	mode   = "mode_M"
	flags  = [ "uses_memory" ]
	pinned = "yes"
568
	attrs  = [
569
		dict(
570
571
572
			name    = "type",
			type    = "ir_type*",
			comment = "type of the allocated variable",
573
574
		),
		dict(
575
576
577
			name    = "where",
			type    = "ir_where_alloc",
			comment = "whether allocation was on the stack or heap",
578
		)
579
580
581
	]
	attr_struct = "free_attr"

Matthias Braun's avatar
Matthias Braun committed
582
583
@op
class Id:
Matthias Braun's avatar
Matthias Braun committed
584
585
586
587
	"""Returns its operand unchanged.

	This is mainly used when exchanging nodes. Usually you shouldn't see Id
	nodes since the getters/setters for node inputs skip them automatically."""
588
589
590
	ins    = [
	   ("pred", "the value which is returned unchanged")
	]
591
592
593
	pinned = "no"
	flags  = []

Matthias Braun's avatar
Matthias Braun committed
594
595
@op
class IJmp:
596
597
598
	"""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"""
599
600
	mode     = "mode_X"
	pinned   = "yes"
601
602
603
	ins      = [
	   ("target", "target address of the jump"),
	]
604
	flags    = [ "cfopcode", "forking", "keep", "unknown_jump" ]
605

Matthias Braun's avatar
Matthias Braun committed
606
607
@op
class InstOf:
608
	"""Tests whether an object is an instance of a class-type"""
609
610
611
612
	ins   = [
	   ("store", "memory dependency"),
	   ("obj",   "pointer to object being queried")
	]
613
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
614
		("M",         "memory result"),
615
		("res",       "checked object pointer"),
Matthias Braun's avatar
Matthias Braun committed
616
617
		("X_regular", "control flow when no exception occurs"),
		("X_except",  "control flow when exception occured"),
618
	]
619
	flags = [ "highlevel" ]
620
621
	attrs = [
		dict(
622
623
624
			name    = "type",
			type    = "ir_type*",
			comment = "type to check ptr for",
625
		)
626
627
628
629
630
	]
	attr_struct = "io_attr"
	pinned      = "memory"
	pinned_init = "op_pin_state_floats"

Matthias Braun's avatar
Matthias Braun committed
631
632
@op
class Jmp:
633
	"""Jumps to the block connected through the out-value"""
634
635
636
637
638
	mode     = "mode_X"
	pinned   = "yes"
	ins      = []
	flags    = [ "cfopcode" ]

Matthias Braun's avatar
Matthias Braun committed
639
640
@op
class Load:
641
	"""Loads a value from memory (heap or stack)."""
642
643
644
645
	ins   = [
		("mem", "memory dependency"),
		("ptr",  "address to load from"),
	]
646
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
647
		("M",         "memory result"),
648
		("res",       "result of load operation"),
Matthias Braun's avatar
Matthias Braun committed
649
650
		("X_regular", "control flow when no exception occurs"),
		("X_except",  "control flow when exception occured"),
651
	]
652
653
	flags    = [ "fragile", "uses_memory" ]
	pinned   = "exception"
654
655
	attrs    = [
		dict(
656
657
658
			type      = "ir_mode*",
			name      = "mode",
			comment   = "mode of the value to be loaded",
659
		),
660
661
662
663
664
		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",
665
			to_flags  = "%s == volatility_is_volatile ? cons_volatile : cons_none"
666
667
668
669
670
671
		),
		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",
672
			to_flags  = "%s == align_non_aligned ? cons_unaligned : cons_none"
673
		),
674
675
	]
	attr_struct = "load_attr"
676
677
	constructor_args = [
		dict(
678
679
680
			type    = "ir_cons_flags",
			name    = "flags",
			comment = "specifies alignment, volatility and pin state",
681
		),
682
	]
683
	pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
684
	throws_init = "(flags & cons_throws_exception) != 0"
685

Matthias Braun's avatar
Matthias Braun committed
686
@op
687
class Minus(Unop):
Andreas Seltenreich's avatar
Andreas Seltenreich committed
688
	"""returns the additive inverse of its operand"""
689
690
	flags = []

Matthias Braun's avatar
Matthias Braun committed
691
692
@op
class Mod:
693
694
695
	"""returns the remainder of its operands from an implied division.

	Examples:
696

697
698
699
700
701
	* mod(5,3)   produces 2
	* mod(5,-3)  produces 2
	* mod(-5,3)  produces -2
	* mod(-5,-3) produces -2
	"""
702
703
704
705
706
	ins   = [
		("mem",   "memory dependency"),
		("left",  "first operand"),
		("right", "second operand"),
	]
707
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
708
		("M",         "memory result"),
709
		("res",       "result of computation"),
Matthias Braun's avatar
Matthias Braun committed
710
711
		("X_regular", "control flow when no exception occurs"),
		("X_except",  "control flow when exception occured"),
712
	]
713
	flags = [ "fragile", "uses_memory" ]
714
	attrs = [
715
		dict(
716
717
718
			type    = "ir_mode*",
			name    = "resmode",
			comment = "mode of the result",
719
		),
720
	]
721
	attr_struct = "mod_attr"
722
	pinned      = "exception"
723
	throws_init = "false"
724
725
	op_index    = 1
	arity_override = "oparity_binary"
Matthias Braun's avatar
Matthias Braun committed
726

727
class Mul(Binop):
728
	"""returns the product of its operands"""
729
730
731
	flags = [ "commutative" ]

class Mulh(Binop):
732
733
	"""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)"""
734
735
	flags = [ "commutative" ]

Matthias Braun's avatar
Matthias Braun committed
736
737
@op
class Mux:
738
739
	"""returns the false or true operand depending on the value of the sel
	operand"""
740
741
742
743
744
	ins    = [
	   ("sel",   "value making the output selection"),
	   ("false", "selected if sel input is false"),
	   ("true",  "selected if sel input is true"),
	]
745
746
747
	flags  = []
	pinned = "no"

Matthias Braun's avatar
Matthias Braun committed
748
749
@op
class NoMem:
750
	"""Placeholder node for cases where you don't need any memory input"""
751
	mode          = "mode_M"
752
	flags         = [ "dump_noblock" ]
753
754
	pinned        = "yes"
	knownBlock    = True
755
	block         = "get_irg_start_block(irg)"
756
	singleton     = True
757

Matthias Braun's avatar
Matthias Braun committed
758
@op
759
class Not(Unop):
760
	"""returns the bitwise complement of a value. Works for boolean values, too."""
761
762
	flags = []

Matthias Braun's avatar
Matthias Braun committed
763
@op
764
class Or(Binop):
765
	"""returns the result of a bitwise or operation of its operands"""
766
767
	flags = [ "commutative" ]

Matthias Braun's avatar
Matthias Braun committed
768
769
@op
class Phi:
770
771
772
	"""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."""
773
774
775
776
	pinned        = "yes"
	arity         = "variable"
	flags         = []
	attr_struct   = "phi_attr"
777
	init          = '''
778
	res->attr.phi.u.backedge = new_backedge_arr(get_irg_obstack(irg), arity);'''
Matthias Braun's avatar
Matthias Braun committed
779
	customSerializer = True
780

Matthias Braun's avatar
Matthias Braun committed
781
782
@op
class Pin:
783
784
785
	"""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."""
786
787
788
	ins      = [
		("op", "value which is pinned"),
	]
789
790
791
792
	mode     = "get_irn_mode(irn_op)"
	flags    = [ "highlevel" ]
	pinned   = "yes"

Matthias Braun's avatar
Matthias Braun committed
793
794
@op
class Proj:
795
	"""returns an entry of a tuple value"""
796
797
798
	ins              = [
		("pred", "the tuple value from which a part is extracted"),
	]
799
800
801
802
803
804
	flags            = []
	pinned           = "no"
	knownBlock       = True
	knownGraph       = True
	block            = "get_nodes_block(irn_pred)"
	graph            = "get_irn_irg(irn_pred)"
805
	attrs      = [
806
		dict(
807
808
809
			type    = "long",
			name    = "proj",
			comment = "number of tuple component to be extracted",
810
		),
811
	]
812
	attr_struct = "proj_attr"
813

Matthias Braun's avatar
Matthias Braun committed
814
815
@op
class Raise:
816
817
818
	"""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."""
819
820
821
822
	ins    = [
		("mem",     "memory dependency"),
		("exo_ptr", "pointer to exception object to be thrown"),
	]
823
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
824
825
		("M", "memory result"),
		("X", "control flow to exception handler"),
826
	]
827
828
829
	flags  = [ "highlevel", "cfopcode" ]
	pinned = "yes"

Matthias Braun's avatar
Matthias Braun committed
830
831
@op
class Return:
832
833
	"""Returns from the current function. Takes memory and return values as
	operands."""
834
835
836
	ins      = [
		("mem", "memory dependency"),
	]
837
838
839
840
841
842
	arity    = "variable"
	mode     = "mode_X"
	flags    = [ "cfopcode" ]
	pinned   = "yes"

class Rotl(Binop):
843
844
	"""Returns its first operand bits rotated left by the amount in the 2nd
	operand"""
845
846
	flags    = []

Matthias Braun's avatar
Matthias Braun committed
847
848
@op
class Sel:
849
	"""Computes the address of a entity of a compound type given the base
850
851
852
853
	address of an instance of the compound type.

	Optimisations assume that a Sel node can only produce a NULL pointer if the
	ptr input was NULL."""
854
855
856
857
	ins    = [
		("mem", "memory dependency"),
		("ptr", "pointer to object to select from"),
	]
858
859
860
861
	arity  = "variable"
	flags  = []
	mode   = "is_Method_type(get_entity_type(entity)) ? mode_P_code : mode_P_data"
	pinned = "no"
862
	attrs  = [
863
		dict(
864
865
866
			type    = "ir_entity*",
			name    = "entity",
			comment = "entity which is selected",
867
		)
868
869
870
	]
	attr_struct = "sel_attr"

Matthias Braun's avatar
Matthias Braun committed
871
@op
872
class Shl(Binop):
873
	"""Returns its first operands bits shifted left by the amount of the 2nd
874
875
876
877
	operand.
	The right input (shift amount) must be an unsigned integer value.
	If the result mode has modulo_shift!=0, then the effective shift amount is
	the right input modulo this modulo_shift amount."""
878
879
	flags = []

Matthias Braun's avatar
Matthias Braun committed
880
@op
881
class Shr(Binop):
882
	"""Returns its first operands bits shifted right by the amount of the 2nd
883
884
885
886
	operand. No special handling for the sign bit is performed (zero extension).
	The right input (shift amount) must be an unsigned integer value.
	If the result mode has modulo_shift!=0, then the effective shift amount is
	the right input modulo this modulo_shift amount."""
887
888
	flags = []

Matthias Braun's avatar
Matthias Braun committed
889
@op
890
class Shrs(Binop):
891
892
	"""Returns its first operands bits shifted right by the amount of the 2nd
	operand. The leftmost bit (usually the sign bit) stays the same
893
894
895
896
	(sign extension).
	The right input (shift amount) must be an unsigned integer value.
	If the result mode has modulo_shift!=0, then the effective shift amount is
	the right input modulo this modulo_shift amount."""
897
898
	flags = []

Matthias Braun's avatar
Matthias Braun committed
899
900
@op
class Start:
901
	"""The first node of a graph. Execution starts with this node."""
902
903
904
905
906
907
	outs       = [
		("X_initial_exec", "control flow"),
		("M",              "initial memory"),
		("P_frame_base",   "frame base pointer"),
		("T_args",         "function arguments")
	]
908
909
910
911
912
913
	mode             = "mode_T"
	pinned           = "yes"
	flags            = [ "cfopcode" ]
	singleton        = True
	knownBlock       = True
	block            = "get_irg_start_block(irg)"
914

Matthias Braun's avatar
Matthias Braun committed
915
916
@op
class Store:
917
	"""Stores a value into memory (heap or stack)."""
918
919
920
921
922
	ins   = [
	   ("mem",   "memory dependency"),
	   ("ptr",   "address to store to"),
	   ("value", "value to store"),
	]
923
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
924
925
926
		("M",         "memory result"),
		("X_regular", "control flow when no exception occurs"),
		("X_except",  "control flow when exception occured"),
927
	]
928
929
930
931
	flags    = [ "fragile", "uses_memory" ]
	pinned   = "exception"
	attr_struct = "store_attr"
	pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
932
	throws_init = "(flags & cons_throws_exception) != 0"
933
934
935
936
937
938
	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",
939
			to_flags  = "%s == volatility_is_volatile ? cons_volatile : cons_none"
940
941
942
943
944
945
		),
		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",
946
			to_flags  = "%s == align_non_aligned ? cons_unaligned : cons_none"
947
948
		),
	]
949
	constructor_args = [
950
		dict(
951
952
953
			type    = "ir_cons_flags",
			name    = "flags",
			comment = "specifies alignment, volatility and pin state",
954
		),
955
956
	]

Matthias Braun's avatar
Matthias Braun committed
957
@op
958
class Sub(Binop):
959
	"""returns the difference of its operands"""
960
961
	flags = []

Matthias Braun's avatar
Matthias Braun committed
962
963
@op
class SymConst:
964
965
	"""A symbolic constant.

966
967
968
969
970
971
972
973
974
975
976
977
978
	 - *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."""
979
980
981
982
	mode       = "mode_P"
	flags      = [ "constlike", "start_block" ]
	knownBlock = True
	pinned     = "no"
983
	attrs      = [
984
		dict(
985
986
987
988
			type    = "ir_entity*",
			name    = "entity",
			noprop  = True,
			comment = "entity whose address is returned",
989
		)
990
991
	]
	attr_struct = "symconst_attr"
992
	customSerializer = True
993
994
995
	# constructor is written manually at the moment, because of the strange
	# union argument
	noconstructor = True
996

Matthias Braun's avatar
Matthias Braun committed
997
998
@op
class Sync:
999
1000
1001
1002
1003
	"""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."""