ir_spec.py 26.4 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

Matthias Braun's avatar
Matthias Braun committed
24
@op
25
class Add(Binop):
26
	"""returns the sum of its operands"""
27
	flags = [ "commutative" ]
28

Matthias Braun's avatar
Matthias Braun committed
29
30
@op
class Alloc:
31
32
33
34
	"""Allocates a block of memory on the stack."""
	ins = [
		("mem",  "memory dependency" ),
		("size", "size of the block in bytes" ),
35
	]
36
37
38
	outs = [
		("M",   "memory result"),
		("res", "pointer to newly allocated memory"),
39
	]
40
41
	attrs = [
		dict(
42
43
44
			name    = "alignment",
			type    = "unsigned",
			comment = "alignment of the memory block (must be a power of 2)",
45
		),
46
	]
47
48
	flags       = [ "uses_memory" ]
	pinned      = "yes"
49
50
	attr_struct = "alloc_attr"

Matthias Braun's avatar
Matthias Braun committed
51
52
@op
class Anchor:
53
54
55
56
57
58
	"""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."""
59
60
61
62
63
64
65
66
67
	mode             = "mode_ANY"
	arity            = "variable"
	flags            = [ "dump_noblock" ]
	pinned           = "yes"
	attr_struct      = "irg_attr"
	knownBlock       = True
	singleton        = True
	noconstructor    = True
	customSerializer = True
68

Matthias Braun's avatar
Matthias Braun committed
69
@op
70
class And(Binop):
71
	"""returns the result of a bitwise and operation of its operands"""
72
73
	flags    = [ "commutative" ]

Matthias Braun's avatar
Matthias Braun committed
74
75
@op
class ASM:
Matthias Braun's avatar
Matthias Braun committed
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
	"""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)
	"""
103
104
	mode             = "mode_T"
	arity            = "variable"
105
	input_name       = "input"
106
	flags            = [ "keep", "uses_memory" ]
107
	pinned           = "exception"
108
109
110
111
	pinned_init      = "op_pin_state_pinned"
	attr_struct      = "asm_attr"
	attrs_name       = "assem"
	customSerializer = True
112
113
114
	ins   = [
		("mem",    "memory dependency"),
	]
115
116
	attrs = [
		dict(
117
118
119
			name    = "input_constraints",
			type    = "ir_asm_constraint*",
			comment = "input constraints",
120
121
		),
		dict(
122
			name    = "n_output_constraints",
123
			type    = "size_t",
124
125
			noprop  = True,
			comment = "number of output constraints",
126
127
		),
		dict(
128
129
130
			name    = "output_constraints",
			type    = "ir_asm_constraint*",
			comment = "output constraints",
131
132
		),
		dict(
133
			name    = "n_clobbers",
134
			type    = "size_t",
135
136
			noprop  = True,
			comment = "number of clobbered registers/memory",
137
138
		),
		dict(
139
140
141
			name    = "clobbers",
			type    = "ident**",
			comment = "list of clobbered registers/memory",
142
143
		),
		dict(
144
145
146
			name    = "text",
			type    = "ident*",
			comment = "assembler text",
147
148
149
150
151
		),
	]
	# constructor is written manually at the moment, because of the clobbers+
	# constraints arrays needing special handling (2 arguments for 1 attribute)
	noconstructor = True
152

Matthias Braun's avatar
Matthias Braun committed
153
154
@op
class Bad:
155
156
157
158
159
160
161
162
163
164
	"""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
165
	replaced by Bad themselves. Nodes with at least 1 Bad input get exchanged
166
167
168
169
170
171
	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
172
	flags         = [ "start_block", "dump_noblock" ]
173
174
	pinned        = "yes"
	knownBlock    = True
175
	block         = "get_irg_start_block(irg)"
176
	attr_struct   = "bad_attr"
177
	init = '''
178
	res->attr.bad.irg.irg = irg;
179
	clear_irg_properties(irg, IR_GRAPH_PROPERTY_NO_BADS);
180
181
	'''

Matthias Braun's avatar
Matthias Braun committed
182
183
@op
class Deleted:
184
185
	"""Internal node which is temporary set to nodes which are already removed
	from the graph."""
186
187
188
189
	mode             = "mode_Bad"
	flags            = [ ]
	pinned           = "yes"
	noconstructor    = True
Matthias Braun's avatar
Matthias Braun committed
190
	customSerializer = True # this has no serializer
191

Matthias Braun's avatar
Matthias Braun committed
192
193
@op
class Block:
194
	"""A basic block"""
195
196
197
198
199
	mode             = "mode_BB"
	knownBlock       = True
	block            = "NULL"
	pinned           = "yes"
	arity            = "variable"
200
	input_name       = "cfgpred"
201
	flags            = []
202
	attr_struct      = "block_attr"
203
204
205
206
207
208
209
210
	attrs            = [
		dict(
			name    = "entity",
			type    = "ir_entity*",
			comment = "entity representing this block",
			init    = "NULL",
		),
	]
211
	customSerializer = True
Moritz Kroll's avatar
Moritz Kroll committed
212
213

	init = '''
214
	res->attr.block.irg.irg     = irg;
215
	res->attr.block.backedge    = new_backedge_arr(get_irg_obstack(irg), arity);
Moritz Kroll's avatar
Moritz Kroll committed
216
	set_Block_matured(res, 1);
217
218

	/* Create and initialize array for Phi-node construction. */
219
	if (irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_CONSTRUCTION)) {
220
		res->attr.block.graph_arr = NEW_ARR_DZ(ir_node*, get_irg_obstack(irg), irg->n_loc);
221
	}
222
	'''
223

Matthias Braun's avatar
Matthias Braun committed
224
225
@op
class Builtin:
226
	"""performs a backend-specific builtin."""
227
	ins         = [
228
229
		("mem", "memory dependency"),
	]
230
231
232
	arity       = "variable"
	input_name  = "param"
	outs        = [
233
234
		("M", "memory result"),
		# results follow here
235
	]
236
237
	flags       = [ "uses_memory" ]
	attrs       = [
238
		dict(
239
240
241
			type    = "ir_builtin_kind",
			name    = "kind",
			comment = "kind of builtin",
242
		),
243
		dict(
244
245
246
			type    = "ir_type*",
			name    = "type",
			comment = "method type for the builtin call",
247
		)
248
	]
249
	pinned      = "exception"
250
251
	pinned_init = "op_pin_state_pinned"
	attr_struct = "builtin_attr"
252
	init        = '''
253
254
255
	assert((get_unknown_type() == type) || is_Method_type(type));
	'''

Matthias Braun's avatar
Matthias Braun committed
256
257
@op
class Call:
258
259
260
261
	"""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."""
262
	ins         = [
263
264
265
		("mem",   "memory dependency"),
		("ptr",   "pointer to called code"),
	]
266
267
268
	arity       = "variable"
	input_name  = "param"
	outs        = [
Matthias Braun's avatar
Matthias Braun committed
269
		("M",                "memory result"),
270
		("T_result",         "tuple containing all results"),
Matthias Braun's avatar
Matthias Braun committed
271
272
		("X_regular",        "control flow when no exception occurs"),
		("X_except",         "control flow when exception occured"),
273
	]
274
275
	flags       = [ "fragile", "uses_memory" ]
	attrs       = [
276
		dict(
277
278
279
			type    = "ir_type*",
			name    = "type",
			comment = "type of the call (usually type of the called procedure)",
280
		),
281
282
	]
	attr_struct = "call_attr"
283
	pinned      = "exception"
284
	pinned_init = "op_pin_state_pinned"
285
	throws_init = "false"
286
287
	init = '''
	assert((get_unknown_type() == type) || is_Method_type(type));
288
	'''
289

Matthias Braun's avatar
Matthias Braun committed
290
@op
291
class Cmp(Binop):
292
	"""Compares its two operands and checks whether a specified
293
	   relation (like less or equal) is fulfilled."""
294
	flags = []
295
296
297
298
299
300
301
302
303
	mode  = "mode_b"
	attrs = [
		dict(
			type    = "ir_relation",
			name    = "relation",
			comment = "Comparison relation"
		)
	]
	attr_struct = "cmp_attr"
304

Matthias Braun's avatar
Matthias Braun committed
305
306
@op
class Cond:
307
	"""Conditionally change control flow."""
308
309
310
	ins      = [
		("selector",  "condition parameter"),
	]
311
312
313
314
	outs     = [
		("false", "control flow if operand is \"false\""),
		("true",  "control flow if operand is \"true\""),
	]
315
316
	flags    = [ "cfopcode", "forking" ]
	pinned   = "yes"
317
318
	attrs    = [
		dict(
319
320
321
322
			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
323
		),
324
	]
325
	attr_struct = "cond_attr"
326

Matthias Braun's avatar
Matthias Braun committed
327
328
@op
class Switch:
Matthias Braun's avatar
Matthias Braun committed
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
	"""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
355
356
@op
class Confirm:
357
358
359
360
361
362
363
364
365
	"""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."""
366
367
368
369
	ins      = [
		("value",  "value to express a constraint for"),
		("bound",  "value to compare against"),
	]
370
371
372
	mode     = "get_irn_mode(irn_value)"
	flags    = [ "highlevel" ]
	pinned   = "yes"
373
374
	attrs    = [
		dict(
375
376
377
			name    = "relation",
			type    = "ir_relation",
			comment = "relation of value to bound",
378
		),
379
380
381
	]
	attr_struct = "confirm_attr"

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

Matthias Braun's avatar
Matthias Braun committed
400
@op
401
class Conv:
402
	"""Converts values between modes"""
403
404
405
406
407
	flags  = []
	pinned = "no"
	ins    = [
		("op", "operand")
	]
408

Matthias Braun's avatar
Matthias Braun committed
409
410
@op
class CopyB:
Matthias Braun's avatar
Matthias Braun committed
411
	"""Copies a block of memory with statically known size/type."""
412
413
414
415
416
	ins   = [
		("mem",  "memory dependency"),
		("dst",  "destination address"),
		("src",  "source address"),
	]
417
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
418
419
420
		("M",         "memory result"),
		("X_regular", "control flow when no exception occurs"),
		("X_except",  "control flow when exception occured"),
421
	]
422
	flags = [ "fragile", "uses_memory" ]
423
424
	attrs = [
		dict(
425
426
427
			name    = "type",
			type    = "ir_type*",
			comment = "type of copied data",
428
		)
429
430
	]
	attr_struct = "copyb_attr"
431
	pinned      = "exception"
432
	pinned_init = "op_pin_state_pinned"
433
	throws_init = "false"
434

Matthias Braun's avatar
Matthias Braun committed
435
436
@op
class Div:
437
	"""returns the quotient of its 2 operands"""
438
439
440
441
442
	ins   = [
		("mem",   "memory dependency"),
		("left",  "first operand"),
		("right", "second operand"),
	]
443
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
444
		("M",         "memory result"),
445
		("res",       "result of computation"),
Matthias Braun's avatar
Matthias Braun committed
446
447
		("X_regular", "control flow when no exception occurs"),
		("X_except",  "control flow when exception occured"),
448
	]
449
	flags = [ "fragile", "uses_memory" ]
450
451
	attrs = [
		dict(
452
453
454
			type    = "ir_mode*",
			name    = "resmode",
			comment = "mode of the result value",
455
		),
Moritz Kroll's avatar
Moritz Kroll committed
456
457
458
459
		dict(
			name = "no_remainder",
			type = "int",
			init = "0",
460
		)
461
	]
462
	attr_struct = "div_attr"
463
	pinned      = "exception"
464
	throws_init = "false"
465
466
	op_index    = 1
	arity_override = "oparity_binary"
467

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

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

Matthias Braun's avatar
Matthias Braun committed
492
@op
493
class Eor(Binop):
Matthias Braun's avatar
Matthias Braun committed
494
495
496
	"""returns the result of a bitwise exclusive or operation of its operands.

	This is also known as the Xor operation."""
497
	flags    = [ "commutative" ]
498

Matthias Braun's avatar
Matthias Braun committed
499
500
@op
class Free:
501
	"""Frees a block of memory previously allocated by an Alloc node"""
502
503
504
	ins = [
		("mem", "memory dependency" ),
		("ptr", "pointer to the object to free"),
505
	]
506
507
508
509
	mode   = "mode_M"
	flags  = [ "uses_memory" ]
	pinned = "yes"

Matthias Braun's avatar
Matthias Braun committed
510
511
@op
class Id:
Matthias Braun's avatar
Matthias Braun committed
512
513
514
515
	"""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."""
516
517
518
	ins    = [
	   ("pred", "the value which is returned unchanged")
	]
519
520
521
	pinned = "no"
	flags  = []

Matthias Braun's avatar
Matthias Braun committed
522
523
@op
class IJmp:
524
525
526
	"""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"""
527
528
	mode     = "mode_X"
	pinned   = "yes"
529
530
531
	ins      = [
	   ("target", "target address of the jump"),
	]
532
	flags    = [ "cfopcode", "forking", "keep", "unknown_jump" ]
533

Matthias Braun's avatar
Matthias Braun committed
534
535
@op
class InstOf:
536
	"""Tests whether an object is an instance of a class-type"""
537
538
539
540
	ins   = [
	   ("store", "memory dependency"),
	   ("obj",   "pointer to object being queried")
	]
541
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
542
		("M",         "memory result"),
543
		("res",       "checked object pointer"),
Matthias Braun's avatar
Matthias Braun committed
544
545
		("X_regular", "control flow when no exception occurs"),
		("X_except",  "control flow when exception occured"),
546
	]
547
	flags = [ "highlevel" ]
548
549
	attrs = [
		dict(
550
551
552
			name    = "type",
			type    = "ir_type*",
			comment = "type to check ptr for",
553
		)
554
555
	]
	attr_struct = "io_attr"
556
	pinned      = "exception"
557
558
	pinned_init = "op_pin_state_floats"

Matthias Braun's avatar
Matthias Braun committed
559
560
@op
class Jmp:
561
	"""Jumps to the block connected through the out-value"""
562
563
564
565
566
	mode     = "mode_X"
	pinned   = "yes"
	ins      = []
	flags    = [ "cfopcode" ]

Matthias Braun's avatar
Matthias Braun committed
567
568
@op
class Load:
569
	"""Loads a value from memory (heap or stack)."""
570
571
572
573
	ins   = [
		("mem", "memory dependency"),
		("ptr",  "address to load from"),
	]
574
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
575
		("M",         "memory result"),
576
		("res",       "result of load operation"),
Matthias Braun's avatar
Matthias Braun committed
577
578
		("X_regular", "control flow when no exception occurs"),
		("X_except",  "control flow when exception occured"),
579
	]
580
581
	flags    = [ "fragile", "uses_memory" ]
	pinned   = "exception"
582
583
	attrs    = [
		dict(
584
585
586
			type      = "ir_mode*",
			name      = "mode",
			comment   = "mode of the value to be loaded",
587
		),
588
589
590
591
592
		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",
593
			to_flags  = "%s == volatility_is_volatile ? cons_volatile : cons_none"
594
595
596
597
598
599
		),
		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",
600
			to_flags  = "%s == align_non_aligned ? cons_unaligned : cons_none"
601
		),
602
603
	]
	attr_struct = "load_attr"
604
605
	constructor_args = [
		dict(
606
607
608
			type    = "ir_cons_flags",
			name    = "flags",
			comment = "specifies alignment, volatility and pin state",
609
		),
610
	]
611
	pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
612
	throws_init = "(flags & cons_throws_exception) != 0"
613

Matthias Braun's avatar
Matthias Braun committed
614
@op
615
class Minus:
Andreas Seltenreich's avatar
Andreas Seltenreich committed
616
	"""returns the additive inverse of its operand"""
617
618
619
620
621
	flags  = []
	pinned = "no"
	ins    = [
		("op", "operand")
	]
622

Matthias Braun's avatar
Matthias Braun committed
623
624
@op
class Mod:
625
626
627
	"""returns the remainder of its operands from an implied division.

	Examples:
628

629
630
631
632
633
	* mod(5,3)   produces 2
	* mod(5,-3)  produces 2
	* mod(-5,3)  produces -2
	* mod(-5,-3) produces -2
	"""
634
635
636
637
638
	ins   = [
		("mem",   "memory dependency"),
		("left",  "first operand"),
		("right", "second operand"),
	]
639
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
640
		("M",         "memory result"),
641
		("res",       "result of computation"),
Matthias Braun's avatar
Matthias Braun committed
642
643
		("X_regular", "control flow when no exception occurs"),
		("X_except",  "control flow when exception occured"),
644
	]
645
	flags = [ "fragile", "uses_memory" ]
646
	attrs = [
647
		dict(
648
649
650
			type    = "ir_mode*",
			name    = "resmode",
			comment = "mode of the result",
651
		),
652
	]
653
	attr_struct = "mod_attr"
654
	pinned      = "exception"
655
	throws_init = "false"
656
657
	op_index    = 1
	arity_override = "oparity_binary"
Matthias Braun's avatar
Matthias Braun committed
658

659
class Mul(Binop):
660
	"""returns the product of its operands"""
661
662
663
	flags = [ "commutative" ]

class Mulh(Binop):
664
665
	"""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)"""
666
667
	flags = [ "commutative" ]

Matthias Braun's avatar
Matthias Braun committed
668
669
@op
class Mux:
670
671
	"""returns the false or true operand depending on the value of the sel
	operand"""
672
673
674
675
676
	ins    = [
	   ("sel",   "value making the output selection"),
	   ("false", "selected if sel input is false"),
	   ("true",  "selected if sel input is true"),
	]
677
678
679
	flags  = []
	pinned = "no"

Matthias Braun's avatar
Matthias Braun committed
680
681
@op
class NoMem:
682
	"""Placeholder node for cases where you don't need any memory input"""
683
	mode          = "mode_M"
684
	flags         = [ "dump_noblock" ]
685
686
	pinned        = "yes"
	knownBlock    = True
687
	block         = "get_irg_start_block(irg)"
688
	singleton     = True
689

Matthias Braun's avatar
Matthias Braun committed
690
@op
691
class Not:
692
	"""returns the bitwise complement of a value. Works for boolean values, too."""
693
694
695
696
697
	flags  = []
	pinned = "no"
	ins    = [
		("op", "operand")
	]
698

Matthias Braun's avatar
Matthias Braun committed
699
@op
700
class Or(Binop):
701
	"""returns the result of a bitwise or operation of its operands"""
702
703
	flags = [ "commutative" ]

Matthias Braun's avatar
Matthias Braun committed
704
705
@op
class Phi:
706
707
708
	"""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."""
709
710
	pinned        = "yes"
	arity         = "variable"
711
	input_name    = "pred"
712
713
	flags         = []
	attr_struct   = "phi_attr"
714
	init          = '''
715
	res->attr.phi.u.backedge = new_backedge_arr(get_irg_obstack(irg), arity);'''
Matthias Braun's avatar
Matthias Braun committed
716
	customSerializer = True
717

Matthias Braun's avatar
Matthias Braun committed
718
719
@op
class Pin:
720
721
722
	"""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."""
723
724
725
	ins      = [
		("op", "value which is pinned"),
	]
726
727
728
729
	mode     = "get_irn_mode(irn_op)"
	flags    = [ "highlevel" ]
	pinned   = "yes"

Matthias Braun's avatar
Matthias Braun committed
730
731
@op
class Proj:
732
	"""returns an entry of a tuple value"""
733
734
735
	ins              = [
		("pred", "the tuple value from which a part is extracted"),
	]
736
737
738
739
740
741
	flags            = []
	pinned           = "no"
	knownBlock       = True
	knownGraph       = True
	block            = "get_nodes_block(irn_pred)"
	graph            = "get_irn_irg(irn_pred)"
742
	attrs      = [
743
		dict(
744
745
746
			type    = "long",
			name    = "proj",
			comment = "number of tuple component to be extracted",
747
		),
748
	]
749
	attr_struct = "proj_attr"
750

Matthias Braun's avatar
Matthias Braun committed
751
752
@op
class Raise:
753
754
755
	"""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."""
756
757
758
759
	ins    = [
		("mem",     "memory dependency"),
		("exo_ptr", "pointer to exception object to be thrown"),
	]
760
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
761
762
		("M", "memory result"),
		("X", "control flow to exception handler"),
763
	]
764
765
766
	flags  = [ "highlevel", "cfopcode" ]
	pinned = "yes"

Matthias Braun's avatar
Matthias Braun committed
767
768
@op
class Return:
769
770
	"""Returns from the current function. Takes memory and return values as
	operands."""
771
	ins        = [
772
773
		("mem", "memory dependency"),
	]
774
775
776
777
778
	arity      = "variable"
	input_name = "res"
	mode       = "mode_X"
	flags      = [ "cfopcode" ]
	pinned     = "yes"
779

Matthias Braun's avatar
Matthias Braun committed
780
781
@op
class Sel:
782
	"""Computes the address of a entity of a compound type given the base
783
784
785
786
	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."""
787
	ins         = [
788
789
790
		("mem", "memory dependency"),
		("ptr", "pointer to object to select from"),
	]
791
792
793
794
795
796
	arity       = "variable"
	input_name  = "index"
	flags       = []
	mode        = "is_Method_type(get_entity_type(entity)) ? mode_P_code : mode_P_data"
	pinned      = "no"
	attrs       = [
797
		dict(
798
799
800
			type    = "ir_entity*",
			name    = "entity",
			comment = "entity which is selected",
801
		)
802
803
804
	]
	attr_struct = "sel_attr"

Matthias Braun's avatar
Matthias Braun committed
805
@op
806
class Shl(Binop):
807
	"""Returns its first operands bits shifted left by the amount of the 2nd
808
809
810
811
	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."""
812
813
	flags = []

Matthias Braun's avatar
Matthias Braun committed
814
@op
815
class Shr(Binop):
816
	"""Returns its first operands bits shifted right by the amount of the 2nd
817
818
819
820
	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."""
821
822
	flags = []

Matthias Braun's avatar
Matthias Braun committed
823
@op
824
class Shrs(Binop):
825
826
	"""Returns its first operands bits shifted right by the amount of the 2nd
	operand. The leftmost bit (usually the sign bit) stays the same
827
828
829
830
	(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."""
831
832
	flags = []

Matthias Braun's avatar
Matthias Braun committed
833
834
@op
class Start:
835
	"""The first node of a graph. Execution starts with this node."""
836
837
838
839
840
841
	outs       = [
		("X_initial_exec", "control flow"),
		("M",              "initial memory"),
		("P_frame_base",   "frame base pointer"),
		("T_args",         "function arguments")
	]
842
843
844
845
846
847
	mode             = "mode_T"
	pinned           = "yes"
	flags            = [ "cfopcode" ]
	singleton        = True
	knownBlock       = True
	block            = "get_irg_start_block(irg)"
848

Matthias Braun's avatar
Matthias Braun committed
849
850
@op
class Store:
851
	"""Stores a value into memory (heap or stack)."""
852
853
854
855
856
	ins   = [
	   ("mem",   "memory dependency"),
	   ("ptr",   "address to store to"),
	   ("value", "value to store"),
	]
857
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
858
859
860
		("M",         "memory result"),
		("X_regular", "control flow when no exception occurs"),
		("X_except",  "control flow when exception occured"),
861
	]
862
863
864
865
	flags    = [ "fragile", "uses_memory" ]
	pinned   = "exception"
	attr_struct = "store_attr"
	pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
866
	throws_init = "(flags & cons_throws_exception) != 0"
867
868
869
870
871
872
	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",
873
			to_flags  = "%s == volatility_is_volatile ? cons_volatile : cons_none"
874
875
876
877
878
879
		),
		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",
880
			to_flags  = "%s == align_non_aligned ? cons_unaligned : cons_none"
881
882
		),
	]
883
	constructor_args = [
884
		dict(
885
886
887
			type    = "ir_cons_flags",
			name    = "flags",
			comment = "specifies alignment, volatility and pin state",
888
		),
889
890
	]

Matthias Braun's avatar
Matthias Braun committed
891
@op
892
class Sub(Binop):
893
	"""returns the difference of its operands"""
894
895
	flags = []

Matthias Braun's avatar
Matthias Braun committed
896
897
@op
class SymConst:
898
899
	"""A symbolic constant.

900
901
902
903
904
905
906
907
908
909
910
911
912
	 - *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."""
913
914
915
916
	mode       = "mode_P"
	flags      = [ "constlike", "start_block" ]
	knownBlock = True
	pinned     = "no"
917
	attrs      = [
918
		dict(
919
920
921
922
			type    = "ir_entity*",
			name    = "entity",
			noprop  = True,
			comment = "entity whose address is returned",
923
		)
924
925
	]
	attr_struct = "symconst_attr"
926
	customSerializer = True
927
928
929
	# constructor is written manually at the moment, because of the strange
	# union argument
	noconstructor = True
930

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

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

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