ir_spec.py 26 KB
Newer Older
1
2
3
# This file is part of libFirm.
# Copyright (C) 2012 Karlsruhe Institute of Technology.
#
Matthias Braun's avatar
Matthias Braun committed
4
5
6
# 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
7
from spec_util import abstract, op
8

Matthias Braun's avatar
Matthias Braun committed
9
name = "ir"
10

Matthias Braun's avatar
Matthias Braun committed
11
12
13
@abstract
@op
class Binop(object):
14
	"""Binary nodes have exactly 2 inputs"""
15
	name     = "binop"
16
	ins      = [
17
18
		("left",   "first operand"),
		("right", "second operand"),
19
	]
20
21
22
	op_index       = 0
	pinned         = "no"
	arity_override = "oparity_binary"
23

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
@abstract
@op
class EntConst(object):
	"""Symbolic constant that represents an aspect of an entity"""
	name       = "entconst"
	flags      = [ "constlike", "start_block" ]
	block      = "get_irg_start_block(irg)"
	knownBlock = True
	pinned     = "no"
	attrs      = [
		dict(
			type    = "ir_entity*",
			name    = "entity",
			comment = "entity to operate on",
		),
	]
	attr_struct = "entconst_attr"
	attrs_name  = "entc"

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
@abstract
@op
class TypeConst:
	"""A symbolic constant that represents an aspect of a type"""
	name       = "typeconst"
	flags      = [ "constlike", "start_block" ]
	block      = "get_irg_start_block(irg)"
	knownBlock = True
	pinned     = "no"
	attrs      = [
		dict(
			type    = "ir_type*",
			name    = "type",
			comment = "type to operate on",
		),
	]
	attr_struct = "typeconst_attr"
	attrs_name  = "typec"

Matthias Braun's avatar
Matthias Braun committed
62
@op
63
class Add(Binop):
64
	"""returns the sum of its operands"""
65
	flags = [ "commutative" ]
66

67
68
69
@op
class Address(EntConst):
	"""Symbolic constant that represents the address of an entity (variable or method)"""
70
	mode = "get_type_pointer_mode(get_entity_type(entity))"
71

72
73
74
75
@op
class Align(TypeConst):
	"""A symbolic constant that represents the alignment of a type"""

Matthias Braun's avatar
Matthias Braun committed
76
77
@op
class Alloc:
78
79
80
81
	"""Allocates a block of memory on the stack."""
	ins = [
		("mem",  "memory dependency" ),
		("size", "size of the block in bytes" ),
82
	]
83
84
85
	outs = [
		("M",   "memory result"),
		("res", "pointer to newly allocated memory"),
86
	]
87
88
	attrs = [
		dict(
89
90
91
			name    = "alignment",
			type    = "unsigned",
			comment = "alignment of the memory block (must be a power of 2)",
92
		),
93
	]
94
95
	flags       = [ "uses_memory" ]
	pinned      = "yes"
96
97
	attr_struct = "alloc_attr"

Matthias Braun's avatar
Matthias Braun committed
98
99
@op
class Anchor:
100
101
102
103
104
105
	"""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."""
106
107
108
109
110
111
112
113
114
	mode             = "mode_ANY"
	arity            = "variable"
	flags            = [ "dump_noblock" ]
	pinned           = "yes"
	attr_struct      = "irg_attr"
	knownBlock       = True
	singleton        = True
	noconstructor    = True
	customSerializer = True
115

Matthias Braun's avatar
Matthias Braun committed
116
@op
117
class And(Binop):
118
	"""returns the result of a bitwise and operation of its operands"""
119
120
	flags    = [ "commutative" ]

Matthias Braun's avatar
Matthias Braun committed
121
122
@op
class ASM:
Matthias Braun's avatar
Matthias Braun committed
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
	"""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)
	"""
150
151
	mode             = "mode_T"
	arity            = "variable"
152
	input_name       = "input"
153
	flags            = [ "keep", "uses_memory" ]
154
	pinned           = "exception"
155
156
157
158
	pinned_init      = "op_pin_state_pinned"
	attr_struct      = "asm_attr"
	attrs_name       = "assem"
	customSerializer = True
159
160
161
	ins   = [
		("mem",    "memory dependency"),
	]
162
163
	attrs = [
		dict(
164
165
166
			name    = "input_constraints",
			type    = "ir_asm_constraint*",
			comment = "input constraints",
167
168
		),
		dict(
169
			name    = "n_output_constraints",
170
			type    = "size_t",
171
172
			noprop  = True,
			comment = "number of output constraints",
173
174
		),
		dict(
175
176
177
			name    = "output_constraints",
			type    = "ir_asm_constraint*",
			comment = "output constraints",
178
179
		),
		dict(
180
			name    = "n_clobbers",
181
			type    = "size_t",
182
183
			noprop  = True,
			comment = "number of clobbered registers/memory",
184
185
		),
		dict(
186
187
188
			name    = "clobbers",
			type    = "ident**",
			comment = "list of clobbered registers/memory",
189
190
		),
		dict(
191
192
193
			name    = "text",
			type    = "ident*",
			comment = "assembler text",
194
195
196
197
198
		),
	]
	# constructor is written manually at the moment, because of the clobbers+
	# constraints arrays needing special handling (2 arguments for 1 attribute)
	noconstructor = True
199

Matthias Braun's avatar
Matthias Braun committed
200
201
@op
class Bad:
202
203
204
205
206
207
208
209
210
211
	"""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
212
	replaced by Bad themselves. Nodes with at least 1 Bad input get exchanged
213
214
215
216
217
218
	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
219
	flags         = [ "start_block", "dump_noblock" ]
220
221
	pinned        = "yes"
	knownBlock    = True
222
	block         = "get_irg_start_block(irg)"
223
	attr_struct   = "bad_attr"
224
	init = '''
225
	res->attr.bad.irg.irg = irg;
226
227
	'''

Matthias Braun's avatar
Matthias Braun committed
228
229
@op
class Deleted:
230
231
	"""Internal node which is temporary set to nodes which are already removed
	from the graph."""
232
233
234
235
	mode             = "mode_Bad"
	flags            = [ ]
	pinned           = "yes"
	noconstructor    = True
Matthias Braun's avatar
Matthias Braun committed
236
	customSerializer = True # this has no serializer
237

Matthias Braun's avatar
Matthias Braun committed
238
239
@op
class Block:
240
	"""A basic block"""
241
242
243
244
245
	mode             = "mode_BB"
	knownBlock       = True
	block            = "NULL"
	pinned           = "yes"
	arity            = "variable"
246
	input_name       = "cfgpred"
247
	flags            = []
248
	attr_struct      = "block_attr"
249
250
251
252
253
254
255
256
	attrs            = [
		dict(
			name    = "entity",
			type    = "ir_entity*",
			comment = "entity representing this block",
			init    = "NULL",
		),
	]
257
	customSerializer = True
Moritz Kroll's avatar
Moritz Kroll committed
258
259

	init = '''
260
	res->attr.block.irg.irg     = irg;
261
	res->attr.block.backedge    = new_backedge_arr(get_irg_obstack(irg), arity);
Moritz Kroll's avatar
Moritz Kroll committed
262
	set_Block_matured(res, 1);
263
264

	/* Create and initialize array for Phi-node construction. */
265
	if (irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_CONSTRUCTION)) {
266
		res->attr.block.graph_arr = NEW_ARR_DZ(ir_node*, get_irg_obstack(irg), irg->n_loc);
267
	}
268
	'''
269

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

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

Matthias Braun's avatar
Matthias Braun committed
336
@op
337
class Cmp(Binop):
338
	"""Compares its two operands and checks whether a specified
339
	   relation (like less or equal) is fulfilled."""
340
	flags = []
341
342
343
344
345
346
347
348
349
	mode  = "mode_b"
	attrs = [
		dict(
			type    = "ir_relation",
			name    = "relation",
			comment = "Comparison relation"
		)
	]
	attr_struct = "cmp_attr"
350

Matthias Braun's avatar
Matthias Braun committed
351
352
@op
class Cond:
353
	"""Conditionally change control flow."""
354
355
356
	ins      = [
		("selector",  "condition parameter"),
	]
357
358
359
360
	outs     = [
		("false", "control flow if operand is \"false\""),
		("true",  "control flow if operand is \"true\""),
	]
361
362
	flags    = [ "cfopcode", "forking" ]
	pinned   = "yes"
363
364
	attrs    = [
		dict(
365
366
367
368
			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
369
		),
370
	]
371
	attr_struct = "cond_attr"
372

Matthias Braun's avatar
Matthias Braun committed
373
374
@op
class Switch:
Matthias Braun's avatar
Matthias Braun committed
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
	"""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
401
402
@op
class Confirm:
403
404
405
406
407
408
409
410
411
	"""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."""
412
413
414
415
	ins      = [
		("value",  "value to express a constraint for"),
		("bound",  "value to compare against"),
	]
416
417
418
	mode     = "get_irn_mode(irn_value)"
	flags    = [ "highlevel" ]
	pinned   = "yes"
419
420
	attrs    = [
		dict(
421
422
423
			name    = "relation",
			type    = "ir_relation",
			comment = "relation of value to bound",
424
		),
425
426
427
	]
	attr_struct = "confirm_attr"

Matthias Braun's avatar
Matthias Braun committed
428
429
@op
class Const:
430
	"""Returns a constant value."""
431
	flags      = [ "constlike", "start_block" ]
432
433
	block      = "get_irg_start_block(irg)"
	mode       = "get_tarval_mode(tarval)"
434
435
	knownBlock = True
	pinned     = "no"
436
437
	attrs      = [
		dict(
438
439
440
			type    = "ir_tarval*",
			name    = "tarval",
			comment = "constant value (a tarval object)",
441
		)
442
443
	]
	attr_struct = "const_attr"
444
	attrs_name  = "con"
445

Matthias Braun's avatar
Matthias Braun committed
446
@op
447
class Conv:
448
	"""Converts values between modes"""
449
450
451
452
453
	flags  = []
	pinned = "no"
	ins    = [
		("op", "operand")
	]
454

Matthias Braun's avatar
Matthias Braun committed
455
456
@op
class CopyB:
Matthias Braun's avatar
Matthias Braun committed
457
	"""Copies a block of memory with statically known size/type."""
458
459
460
461
462
	ins   = [
		("mem",  "memory dependency"),
		("dst",  "destination address"),
		("src",  "source address"),
	]
463
464
	mode  = "mode_M"
	flags = [ "uses_memory" ]
465
466
	attrs = [
		dict(
467
468
469
			name    = "type",
			type    = "ir_type*",
			comment = "type of copied data",
470
471
472
473
474
475
476
		),
		dict(
			type      = "ir_volatility",
			name      = "volatility",
			comment   = "volatile CopyB nodes have a visible side-effect and may not be optimized",
			init      = "flags & cons_volatile ? volatility_is_volatile : volatility_non_volatile",
			to_flags  = "%s == volatility_is_volatile ? cons_volatile : cons_none"
477
		)
478
479
	]
	attr_struct = "copyb_attr"
480
481
482
483
484
485
486
	constructor_args = [
		dict(
			type    = "ir_cons_flags",
			name    = "flags",
			comment = "specifies volatility",
		),
	]
487
	pinned      = "no"
488

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

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

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

Matthias Braun's avatar
Matthias Braun committed
546
@op
547
class Eor(Binop):
Matthias Braun's avatar
Matthias Braun committed
548
549
550
	"""returns the result of a bitwise exclusive or operation of its operands.

	This is also known as the Xor operation."""
551
	flags    = [ "commutative" ]
552

Matthias Braun's avatar
Matthias Braun committed
553
554
@op
class Free:
555
	"""Frees a block of memory previously allocated by an Alloc node"""
556
557
558
	ins = [
		("mem", "memory dependency" ),
		("ptr", "pointer to the object to free"),
559
	]
560
561
562
563
	mode   = "mode_M"
	flags  = [ "uses_memory" ]
	pinned = "yes"

Matthias Braun's avatar
Matthias Braun committed
564
565
@op
class Id:
Matthias Braun's avatar
Matthias Braun committed
566
567
568
569
	"""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."""
570
571
572
	ins    = [
	   ("pred", "the value which is returned unchanged")
	]
573
574
575
	pinned = "no"
	flags  = []

Matthias Braun's avatar
Matthias Braun committed
576
577
@op
class IJmp:
578
579
580
	"""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"""
581
582
	mode     = "mode_X"
	pinned   = "yes"
583
584
585
	ins      = [
	   ("target", "target address of the jump"),
	]
586
	flags    = [ "cfopcode", "forking", "keep", "unknown_jump" ]
587

Matthias Braun's avatar
Matthias Braun committed
588
589
@op
class Jmp:
590
	"""Jumps to the block connected through the out-value"""
591
592
593
594
595
	mode     = "mode_X"
	pinned   = "yes"
	ins      = []
	flags    = [ "cfopcode" ]

Matthias Braun's avatar
Matthias Braun committed
596
597
@op
class Load:
598
	"""Loads a value from memory (heap or stack)."""
599
600
601
602
	ins   = [
		("mem", "memory dependency"),
		("ptr",  "address to load from"),
	]
603
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
604
		("M",         "memory result"),
605
		("res",       "result of load operation"),
Matthias Braun's avatar
Matthias Braun committed
606
607
		("X_regular", "control flow when no exception occurs"),
		("X_except",  "control flow when exception occured"),
608
	]
609
610
	flags    = [ "fragile", "uses_memory" ]
	pinned   = "exception"
611
612
	attrs    = [
		dict(
613
614
615
			type      = "ir_mode*",
			name      = "mode",
			comment   = "mode of the value to be loaded",
616
		),
617
618
619
620
621
		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",
622
			to_flags  = "%s == volatility_is_volatile ? cons_volatile : cons_none"
623
624
625
626
627
628
		),
		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",
629
			to_flags  = "%s == align_non_aligned ? cons_unaligned : cons_none"
630
		),
631
632
	]
	attr_struct = "load_attr"
633
634
	constructor_args = [
		dict(
635
636
637
			type    = "ir_cons_flags",
			name    = "flags",
			comment = "specifies alignment, volatility and pin state",
638
		),
639
	]
640
	pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
641
	throws_init = "(flags & cons_throws_exception) != 0"
642

Matthias Braun's avatar
Matthias Braun committed
643
@op
644
class Minus:
Andreas Seltenreich's avatar
Andreas Seltenreich committed
645
	"""returns the additive inverse of its operand"""
646
647
648
649
650
	flags  = []
	pinned = "no"
	ins    = [
		("op", "operand")
	]
651

Matthias Braun's avatar
Matthias Braun committed
652
653
@op
class Mod:
654
655
656
	"""returns the remainder of its operands from an implied division.

	Examples:
657

658
659
660
661
662
	* mod(5,3)   produces 2
	* mod(5,-3)  produces 2
	* mod(-5,3)  produces -2
	* mod(-5,-3) produces -2
	"""
663
664
665
666
667
	ins   = [
		("mem",   "memory dependency"),
		("left",  "first operand"),
		("right", "second operand"),
	]
668
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
669
		("M",         "memory result"),
670
		("res",       "result of computation"),
Matthias Braun's avatar
Matthias Braun committed
671
672
		("X_regular", "control flow when no exception occurs"),
		("X_except",  "control flow when exception occured"),
673
	]
674
	flags = [ "fragile", "uses_memory" ]
675
	attrs = [
676
		dict(
677
678
679
			type    = "ir_mode*",
			name    = "resmode",
			comment = "mode of the result",
680
		),
681
	]
682
	attr_struct = "mod_attr"
683
	pinned      = "exception"
684
	throws_init = "false"
685
686
	op_index    = 1
	arity_override = "oparity_binary"
Matthias Braun's avatar
Matthias Braun committed
687

688
class Mul(Binop):
689
	"""returns the product of its operands"""
690
691
692
	flags = [ "commutative" ]

class Mulh(Binop):
693
694
	"""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)"""
695
696
	flags = [ "commutative" ]

Matthias Braun's avatar
Matthias Braun committed
697
698
@op
class Mux:
699
700
	"""returns the false or true operand depending on the value of the sel
	operand"""
701
702
703
704
705
	ins    = [
	   ("sel",   "value making the output selection"),
	   ("false", "selected if sel input is false"),
	   ("true",  "selected if sel input is true"),
	]
706
707
708
	flags  = []
	pinned = "no"

Matthias Braun's avatar
Matthias Braun committed
709
710
@op
class NoMem:
711
	"""Placeholder node for cases where you don't need any memory input"""
712
	mode          = "mode_M"
713
	flags         = [ "dump_noblock" ]
714
715
	pinned        = "yes"
	knownBlock    = True
716
	block         = "get_irg_start_block(irg)"
717
	singleton     = True
718

Matthias Braun's avatar
Matthias Braun committed
719
@op
720
class Not:
721
	"""returns the bitwise complement of a value. Works for boolean values, too."""
722
723
724
725
726
	flags  = []
	pinned = "no"
	ins    = [
		("op", "operand")
	]
727

728
729
730
731
@op
class Offset(EntConst):
	"""Symbolic constant that represents the offset of an entity in its owner type."""

Matthias Braun's avatar
Matthias Braun committed
732
@op
733
class Or(Binop):
734
	"""returns the result of a bitwise or operation of its operands"""
735
736
	flags = [ "commutative" ]

Matthias Braun's avatar
Matthias Braun committed
737
738
@op
class Phi:
739
740
741
	"""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."""
742
743
	pinned        = "yes"
	arity         = "variable"
744
	input_name    = "pred"
745
746
	flags         = []
	attr_struct   = "phi_attr"
747
	init          = '''
748
	res->attr.phi.u.backedge = new_backedge_arr(get_irg_obstack(irg), arity);'''
Matthias Braun's avatar
Matthias Braun committed
749
	customSerializer = True
750

Matthias Braun's avatar
Matthias Braun committed
751
752
@op
class Pin:
753
754
755
	"""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."""
756
757
758
	ins      = [
		("op", "value which is pinned"),
	]
759
760
761
762
	mode     = "get_irn_mode(irn_op)"
	flags    = [ "highlevel" ]
	pinned   = "yes"

Matthias Braun's avatar
Matthias Braun committed
763
764
@op
class Proj:
765
	"""returns an entry of a tuple value"""
766
767
768
	ins              = [
		("pred", "the tuple value from which a part is extracted"),
	]
769
770
771
772
773
774
	flags            = []
	pinned           = "no"
	knownBlock       = True
	knownGraph       = True
	block            = "get_nodes_block(irn_pred)"
	graph            = "get_irn_irg(irn_pred)"
775
	attrs      = [
776
		dict(
777
778
779
			type    = "long",
			name    = "proj",
			comment = "number of tuple component to be extracted",
780
		),
781
	]
782
	attr_struct = "proj_attr"
783

Matthias Braun's avatar
Matthias Braun committed
784
785
@op
class Raise:
786
787
788
	"""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."""
789
790
791
792
	ins    = [
		("mem",     "memory dependency"),
		("exo_ptr", "pointer to exception object to be thrown"),
	]
793
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
794
795
		("M", "memory result"),
		("X", "control flow to exception handler"),
796
	]
797
798
799
	flags  = [ "highlevel", "cfopcode" ]
	pinned = "yes"

Matthias Braun's avatar
Matthias Braun committed
800
801
@op
class Return:
802
803
	"""Returns from the current function. Takes memory and return values as
	operands."""
804
	ins        = [
805
806
		("mem", "memory dependency"),
	]
807
808
809
810
811
	arity      = "variable"
	input_name = "res"
	mode       = "mode_X"
	flags      = [ "cfopcode" ]
	pinned     = "yes"
812

Matthias Braun's avatar
Matthias Braun committed
813
814
@op
class Sel:
815
	"""Computes the address of a entity of a compound type given the base
816
817
818
819
	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."""
820
	ins         = [
821
822
823
		("mem", "memory dependency"),
		("ptr", "pointer to object to select from"),
	]
824
825
826
827
828
829
	arity       = "variable"
	input_name  = "index"
	flags       = []
	mode        = "is_Method_type(get_entity_type(entity)) ? mode_P_code : mode_P_data"
	pinned      = "no"
	attrs       = [
830
		dict(
831
832
833
			type    = "ir_entity*",
			name    = "entity",
			comment = "entity which is selected",
834
		)
835
836
837
	]
	attr_struct = "sel_attr"

Matthias Braun's avatar
Matthias Braun committed
838
@op
839
class Shl(Binop):
840
	"""Returns its first operands bits shifted left by the amount of the 2nd
841
842
843
844
	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."""
845
846
	flags = []

Matthias Braun's avatar
Matthias Braun committed
847
@op
848
class Shr(Binop):
849
	"""Returns its first operands bits shifted right by the amount of the 2nd
850
851
852
853
	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."""
854
855
	flags = []

Matthias Braun's avatar
Matthias Braun committed
856
@op
857
class Shrs(Binop):
858
859
	"""Returns its first operands bits shifted right by the amount of the 2nd
	operand. The leftmost bit (usually the sign bit) stays the same
860
861
862
863
	(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."""
864
865
	flags = []

Matthias Braun's avatar
Matthias Braun committed
866
867
@op
class Start:
868
	"""The first node of a graph. Execution starts with this node."""
869
870
871
872
873
874
	outs       = [
		("X_initial_exec", "control flow"),
		("M",              "initial memory"),
		("P_frame_base",   "frame base pointer"),
		("T_args",         "function arguments")
	]
875
876
877
878
879
880
	mode             = "mode_T"
	pinned           = "yes"
	flags            = [ "cfopcode" ]
	singleton        = True
	knownBlock       = True
	block            = "get_irg_start_block(irg)"
881

Matthias Braun's avatar
Matthias Braun committed
882
883
@op
class Store:
884
	"""Stores a value into memory (heap or stack)."""
885
886
887
888
889
	ins   = [
	   ("mem",   "memory dependency"),
	   ("ptr",   "address to store to"),
	   ("value", "value to store"),
	]
890
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
891
892
893
		("M",         "memory result"),
		("X_regular", "control flow when no exception occurs"),
		("X_except",  "control flow when exception occured"),
894
	]
895
896
897
898
	flags    = [ "fragile", "uses_memory" ]
	pinned   = "exception"
	attr_struct = "store_attr"
	pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
899
	throws_init = "(flags & cons_throws_exception) != 0"
900
901
902
903
904
905
	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",
906
			to_flags  = "%s == volatility_is_volatile ? cons_volatile : cons_none"
907
908
909
910
911
912
		),
		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",
913
			to_flags  = "%s == align_non_aligned ? cons_unaligned : cons_none"
914
915
		),
	]
916
	constructor_args = [
917
		dict(
918
919
920
			type    = "ir_cons_flags",
			name    = "flags",
			comment = "specifies alignment, volatility and pin state",
921
		),
922
923
	]

Matthias Braun's avatar
Matthias Braun committed
924
@op
925
class Sub(Binop):
926
	"""returns the difference of its operands"""
927
928
	flags = []

929
@op
930
931
class Size(TypeConst):
	"""A symbolic constant that represents the size of a type"""
932

Matthias Braun's avatar
Matthias Braun committed
933
934
@op
class Sync:
935
936
937
938
939
	"""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."""
940
941
942
943
944
	mode       = "mode_M"
	flags      = []
	pinned     = "no"
	arity      = "dynamic"
	input_name = "pred"
945

Matthias Braun's avatar
Matthias Braun committed
946
947
@op
class Tuple:
948
949
950
951
952
953
954
	"""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
955
	just changing its opcode and giving it a new in array."""
956
957
958
959
960
	arity      = "variable"
	input_name = "pred"
	mode       = "mode_T"
	pinned     = "no"
	flags      = []
961

Matthias Braun's avatar
Matthias Braun committed
962
963
@op
class Unknown:
964
965
	"""Returns an unknown (at compile- and runtime) value. It is a valid
	optimisation to replace an Unknown by any other constant value."""
966
967
968
	knownBlock = True
	pinned     = "yes"
	block      = "get_irg_start_block(irg)"
Matthias Braun's avatar
Matthias Braun committed
969
	flags      = [ "start_block", "constlike", "dump_noblock" ]