ir_spec.py 27.3 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 Unop(object):
14
	"""Unary nodes have exactly 1 input"""
15
	name     = "unop"
16
	ins      = [
17
		("op", "operand"),
18
	]
19
20
21
	op_index       = 0
	pinned         = "no"
	arity_override = "oparity_unary"
22

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

Matthias Braun's avatar
Matthias Braun committed
36
@op
37
class Add(Binop):
38
	"""returns the sum of its operands"""
39
	flags = [ "commutative" ]
40

Matthias Braun's avatar
Matthias Braun committed
41
42
@op
class Alloc:
43
	"""allocates a block of memory.
Matthias Braun's avatar
Matthias Braun committed
44
45
46
47
	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).
	"""
48
49
50
51
	ins   = [
		("mem",   "memory dependency" ),
		("count", "number of objects to allocate" ),
	]
52
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
53
		("M",         "memory result"),
54
		("res",       "pointer to newly allocated memory"),
Matthias Braun's avatar
Matthias Braun committed
55
56
		("X_regular", "control flow when no exception occurs"),
		("X_except",  "control flow when exception occured"),
57
	]
58
59
	attrs = [
		dict(
60
61
			name    = "type",
			type    = "ir_type*",
Matthias Braun's avatar
Matthias Braun committed
62
			comment = "type of the objects to allocate",
63
64
		),
		dict(
65
66
67
			name    = "where",
			type    = "ir_where_alloc",
			comment = "whether to allocate the variable on the stack or heap",
68
		)
69
	]
70
	flags       = [ "fragile", "uses_memory" ]
71
	pinned      = "exception"
72
	throws_init = "false"
73
	pinned_init = "op_pin_state_pinned"
74
75
	attr_struct = "alloc_attr"

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

Matthias Braun's avatar
Matthias Braun committed
94
@op
95
class And(Binop):
96
	"""returns the result of a bitwise and operation of its operands"""
97
98
	flags    = [ "commutative" ]

Matthias Braun's avatar
Matthias Braun committed
99
100
@op
class ASM:
Matthias Braun's avatar
Matthias Braun committed
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
	"""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)
	"""
128
129
	mode             = "mode_T"
	arity            = "variable"
130
	input_name       = "input"
131
132
133
134
135
136
	flags            = [ "keep", "uses_memory" ]
	pinned           = "memory"
	pinned_init      = "op_pin_state_pinned"
	attr_struct      = "asm_attr"
	attrs_name       = "assem"
	customSerializer = True
137
138
139
	ins   = [
		("mem",    "memory dependency"),
	]
140
141
	attrs = [
		dict(
142
143
144
			name    = "input_constraints",
			type    = "ir_asm_constraint*",
			comment = "input constraints",
145
146
		),
		dict(
147
			name    = "n_output_constraints",
148
			type    = "size_t",
149
150
			noprop  = True,
			comment = "number of output constraints",
151
152
		),
		dict(
153
154
155
			name    = "output_constraints",
			type    = "ir_asm_constraint*",
			comment = "output constraints",
156
157
		),
		dict(
158
			name    = "n_clobbers",
159
			type    = "size_t",
160
161
			noprop  = True,
			comment = "number of clobbered registers/memory",
162
163
		),
		dict(
164
165
166
			name    = "clobbers",
			type    = "ident**",
			comment = "list of clobbered registers/memory",
167
168
		),
		dict(
169
170
171
			name    = "text",
			type    = "ident*",
			comment = "assembler text",
172
173
174
175
176
		),
	]
	# constructor is written manually at the moment, because of the clobbers+
	# constraints arrays needing special handling (2 arguments for 1 attribute)
	noconstructor = True
177

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

Matthias Braun's avatar
Matthias Braun committed
206
207
@op
class Deleted:
208
209
	"""Internal node which is temporary set to nodes which are already removed
	from the graph."""
210
211
212
213
	mode             = "mode_Bad"
	flags            = [ ]
	pinned           = "yes"
	noconstructor    = True
Matthias Braun's avatar
Matthias Braun committed
214
	customSerializer = True # this has no serializer
215

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

	init = '''
238
	res->attr.block.irg.irg     = irg;
239
	res->attr.block.backedge    = new_backedge_arr(get_irg_obstack(irg), arity);
Moritz Kroll's avatar
Moritz Kroll committed
240
	set_Block_matured(res, 1);
241
242

	/* Create and initialize array for Phi-node construction. */
243
	if (irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_CONSTRUCTION)) {
244
		res->attr.block.graph_arr = NEW_ARR_DZ(ir_node*, get_irg_obstack(irg), irg->n_loc);
245
	}
246
	'''
247

Matthias Braun's avatar
Matthias Braun committed
248
249
@op
class Builtin:
250
	"""performs a backend-specific builtin."""
251
	ins         = [
252
253
		("mem", "memory dependency"),
	]
254
255
256
	arity       = "variable"
	input_name  = "param"
	outs        = [
257
258
		("M", "memory result"),
		# results follow here
259
	]
260
261
	flags       = [ "uses_memory" ]
	attrs       = [
262
		dict(
263
264
265
			type    = "ir_builtin_kind",
			name    = "kind",
			comment = "kind of builtin",
266
		),
267
		dict(
268
269
270
			type    = "ir_type*",
			name    = "type",
			comment = "method type for the builtin call",
271
		)
272
273
274
275
	]
	pinned      = "memory"
	pinned_init = "op_pin_state_pinned"
	attr_struct = "builtin_attr"
276
	init        = '''
277
278
279
	assert((get_unknown_type() == type) || is_Method_type(type));
	'''

Matthias Braun's avatar
Matthias Braun committed
280
281
@op
class Call:
282
283
284
285
	"""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."""
286
	ins         = [
287
288
289
		("mem",   "memory dependency"),
		("ptr",   "pointer to called code"),
	]
290
291
292
	arity       = "variable"
	input_name  = "param"
	outs        = [
Matthias Braun's avatar
Matthias Braun committed
293
		("M",                "memory result"),
294
		("T_result",         "tuple containing all results"),
Matthias Braun's avatar
Matthias Braun committed
295
296
		("X_regular",        "control flow when no exception occurs"),
		("X_except",         "control flow when exception occured"),
297
	]
298
299
	flags       = [ "fragile", "uses_memory" ]
	attrs       = [
300
		dict(
301
302
303
			type    = "ir_type*",
			name    = "type",
			comment = "type of the call (usually type of the called procedure)",
304
		),
305
306
307
308
	]
	attr_struct = "call_attr"
	pinned      = "memory"
	pinned_init = "op_pin_state_pinned"
309
	throws_init = "false"
310
311
	init = '''
	assert((get_unknown_type() == type) || is_Method_type(type));
312
	'''
313

Matthias Braun's avatar
Matthias Braun committed
314
@op
315
class Cmp(Binop):
316
	"""Compares its two operands and checks whether a specified
317
	   relation (like less or equal) is fulfilled."""
318
	flags = []
319
320
321
322
323
324
325
326
327
	mode  = "mode_b"
	attrs = [
		dict(
			type    = "ir_relation",
			name    = "relation",
			comment = "Comparison relation"
		)
	]
	attr_struct = "cmp_attr"
328

Matthias Braun's avatar
Matthias Braun committed
329
330
@op
class Cond:
331
	"""Conditionally change control flow."""
332
333
334
	ins      = [
		("selector",  "condition parameter"),
	]
335
336
337
338
	outs     = [
		("false", "control flow if operand is \"false\""),
		("true",  "control flow if operand is \"true\""),
	]
339
340
	flags    = [ "cfopcode", "forking" ]
	pinned   = "yes"
341
342
	attrs    = [
		dict(
343
344
345
346
			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
347
		),
348
	]
349
	attr_struct = "cond_attr"
350

Matthias Braun's avatar
Matthias Braun committed
351
352
@op
class Switch:
Matthias Braun's avatar
Matthias Braun committed
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
	"""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
379
380
@op
class Confirm:
381
382
383
384
385
386
387
388
389
	"""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."""
390
391
392
393
	ins      = [
		("value",  "value to express a constraint for"),
		("bound",  "value to compare against"),
	]
394
395
396
	mode     = "get_irn_mode(irn_value)"
	flags    = [ "highlevel" ]
	pinned   = "yes"
397
398
	attrs    = [
		dict(
399
400
401
			name    = "relation",
			type    = "ir_relation",
			comment = "relation of value to bound",
402
		),
403
404
405
	]
	attr_struct = "confirm_attr"

Matthias Braun's avatar
Matthias Braun committed
406
407
@op
class Const:
408
	"""Returns a constant value."""
409
	flags      = [ "constlike", "start_block" ]
410
411
	block      = "get_irg_start_block(irg)"
	mode       = "get_tarval_mode(tarval)"
412
413
	knownBlock = True
	pinned     = "no"
414
415
	attrs      = [
		dict(
416
417
418
			type    = "ir_tarval*",
			name    = "tarval",
			comment = "constant value (a tarval object)",
419
		)
420
421
	]
	attr_struct = "const_attr"
422
	attrs_name  = "con"
423

Matthias Braun's avatar
Matthias Braun committed
424
@op
425
class Conv(Unop):
426
	"""Converts values between modes"""
427
428
	flags = []

Matthias Braun's avatar
Matthias Braun committed
429
430
@op
class CopyB:
Matthias Braun's avatar
Matthias Braun committed
431
	"""Copies a block of memory with statically known size/type."""
432
433
434
435
436
	ins   = [
		("mem",  "memory dependency"),
		("dst",  "destination address"),
		("src",  "source address"),
	]
437
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
438
439
440
		("M",         "memory result"),
		("X_regular", "control flow when no exception occurs"),
		("X_except",  "control flow when exception occured"),
441
	]
442
	flags = [ "fragile", "uses_memory" ]
443
444
	attrs = [
		dict(
445
446
447
			name    = "type",
			type    = "ir_type*",
			comment = "type of copied data",
448
		)
449
450
451
452
	]
	attr_struct = "copyb_attr"
	pinned      = "memory"
	pinned_init = "op_pin_state_pinned"
453
	throws_init = "false"
454

Matthias Braun's avatar
Matthias Braun committed
455
456
@op
class Div:
457
	"""returns the quotient of its 2 operands"""
458
459
460
461
462
	ins   = [
		("mem",   "memory dependency"),
		("left",  "first operand"),
		("right", "second operand"),
	]
463
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
464
		("M",         "memory result"),
465
		("res",       "result of computation"),
Matthias Braun's avatar
Matthias Braun committed
466
467
		("X_regular", "control flow when no exception occurs"),
		("X_except",  "control flow when exception occured"),
468
	]
469
	flags = [ "fragile", "uses_memory" ]
470
471
	attrs = [
		dict(
472
473
474
			type    = "ir_mode*",
			name    = "resmode",
			comment = "mode of the result value",
475
		),
Moritz Kroll's avatar
Moritz Kroll committed
476
477
478
479
		dict(
			name = "no_remainder",
			type = "int",
			init = "0",
480
		)
481
	]
482
	attr_struct = "div_attr"
483
	pinned      = "exception"
484
	throws_init = "false"
485
486
	op_index    = 1
	arity_override = "oparity_binary"
487

Matthias Braun's avatar
Matthias Braun committed
488
489
@op
class Dummy:
490
491
492
	"""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."""
493
494
	ins        = []
	flags      = [ "cfopcode", "start_block", "constlike", "dump_noblock" ]
495
496
497
498
	knownBlock = True
	pinned     = "yes"
	block      = "get_irg_start_block(irg)"

Matthias Braun's avatar
Matthias Braun committed
499
500
@op
class End:
501
502
	"""Last node of a graph. It references nodes in endless loops (so called
	keepalive edges)"""
503
504
505
	mode             = "mode_X"
	pinned           = "yes"
	arity            = "dynamic"
506
	input_name       = "keepalive"
507
508
509
510
	flags            = [ "cfopcode" ]
	knownBlock       = True
	block            = "get_irg_end_block(irg)"
	singleton        = True
511

Matthias Braun's avatar
Matthias Braun committed
512
@op
513
class Eor(Binop):
Matthias Braun's avatar
Matthias Braun committed
514
515
516
	"""returns the result of a bitwise exclusive or operation of its operands.

	This is also known as the Xor operation."""
517
	flags    = [ "commutative" ]
518

Matthias Braun's avatar
Matthias Braun committed
519
520
@op
class Free:
521
	"""Frees a block of memory previously allocated by an Alloc node"""
522
523
524
	ins    = [
		("mem",   "memory dependency" ),
		("ptr",   "pointer to the object to free"),
525
		("count", "number of objects to allocate" ),
526
	]
527
528
529
	mode   = "mode_M"
	flags  = [ "uses_memory" ]
	pinned = "yes"
530
	attrs  = [
531
		dict(
532
533
534
			name    = "type",
			type    = "ir_type*",
			comment = "type of the allocated variable",
535
536
		),
		dict(
537
538
539
			name    = "where",
			type    = "ir_where_alloc",
			comment = "whether allocation was on the stack or heap",
540
		)
541
542
543
	]
	attr_struct = "free_attr"

Matthias Braun's avatar
Matthias Braun committed
544
545
@op
class Id:
Matthias Braun's avatar
Matthias Braun committed
546
547
548
549
	"""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."""
550
551
552
	ins    = [
	   ("pred", "the value which is returned unchanged")
	]
553
554
555
	pinned = "no"
	flags  = []

Matthias Braun's avatar
Matthias Braun committed
556
557
@op
class IJmp:
558
559
560
	"""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"""
561
562
	mode     = "mode_X"
	pinned   = "yes"
563
564
565
	ins      = [
	   ("target", "target address of the jump"),
	]
566
	flags    = [ "cfopcode", "forking", "keep", "unknown_jump" ]
567

Matthias Braun's avatar
Matthias Braun committed
568
569
@op
class InstOf:
570
	"""Tests whether an object is an instance of a class-type"""
571
572
573
574
	ins   = [
	   ("store", "memory dependency"),
	   ("obj",   "pointer to object being queried")
	]
575
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
576
		("M",         "memory result"),
577
		("res",       "checked object pointer"),
Matthias Braun's avatar
Matthias Braun committed
578
579
		("X_regular", "control flow when no exception occurs"),
		("X_except",  "control flow when exception occured"),
580
	]
581
	flags = [ "highlevel" ]
582
583
	attrs = [
		dict(
584
585
586
			name    = "type",
			type    = "ir_type*",
			comment = "type to check ptr for",
587
		)
588
589
590
591
592
	]
	attr_struct = "io_attr"
	pinned      = "memory"
	pinned_init = "op_pin_state_floats"

Matthias Braun's avatar
Matthias Braun committed
593
594
@op
class Jmp:
595
	"""Jumps to the block connected through the out-value"""
596
597
598
599
600
	mode     = "mode_X"
	pinned   = "yes"
	ins      = []
	flags    = [ "cfopcode" ]

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

Matthias Braun's avatar
Matthias Braun committed
648
@op
649
class Minus(Unop):
Andreas Seltenreich's avatar
Andreas Seltenreich committed
650
	"""returns the additive inverse of its operand"""
651
652
	flags = []

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

	Examples:
658

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

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

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

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

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

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

Matthias Braun's avatar
Matthias Braun committed
725
@op
726
class Or(Binop):
727
	"""returns the result of a bitwise or operation of its operands"""
728
729
	flags = [ "commutative" ]

Matthias Braun's avatar
Matthias Braun committed
730
731
@op
class Phi:
732
733
734
	"""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."""
735
736
	pinned        = "yes"
	arity         = "variable"
737
	input_name    = "pred"
738
739
	flags         = []
	attr_struct   = "phi_attr"
740
	init          = '''
741
	res->attr.phi.u.backedge = new_backedge_arr(get_irg_obstack(irg), arity);'''
Matthias Braun's avatar
Matthias Braun committed
742
	customSerializer = True
743

Matthias Braun's avatar
Matthias Braun committed
744
745
@op
class Pin:
746
747
748
	"""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."""
749
750
751
	ins      = [
		("op", "value which is pinned"),
	]
752
753
754
755
	mode     = "get_irn_mode(irn_op)"
	flags    = [ "highlevel" ]
	pinned   = "yes"

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

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

Matthias Braun's avatar
Matthias Braun committed
793
794
@op
class Return:
795
796
	"""Returns from the current function. Takes memory and return values as
	operands."""
797
	ins        = [
798
799
		("mem", "memory dependency"),
	]
800
801
802
803
804
	arity      = "variable"
	input_name = "res"
	mode       = "mode_X"
	flags      = [ "cfopcode" ]
	pinned     = "yes"
805
806

class Rotl(Binop):
807
808
	"""Returns its first operand bits rotated left by the amount in the 2nd
	operand"""
809
810
	flags    = []

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

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

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

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

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

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

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

Matthias Braun's avatar
Matthias Braun committed
927
928
@op
class SymConst:
929
930
	"""A symbolic constant.

931
932
933
934
935
936
937
938
939
940
941
942
943
	 - *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."""
944
945
946
947
	mode       = "mode_P"
	flags      = [ "constlike", "start_block" ]
	knownBlock = True
	pinned     = "no"
948
	attrs      = [
949
		dict(
950
951
952
953
			type    = "ir_entity*",
			name    = "entity",
			noprop  = True,
			comment = "entity whose address is returned",
954
		)
955
956
	]
	attr_struct = "symconst_attr"
957
	customSerializer = True
958
959
960
	# constructor is written manually at the moment, because of the strange
	# union argument
	noconstructor = True
961

Matthias Braun's avatar
Matthias Braun committed
962
963
@op
class Sync:
964
965
966
967
968
	"""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."""
969
970
971
972
973
	mode       = "mode_M"
	flags      = []
	pinned     = "no"
	arity      = "dynamic"
	input_name = "pred"