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"

Matthias Braun's avatar
Matthias Braun committed
43
@op
44
class Add(Binop):
45
	"""returns the sum of its operands"""
46
	flags = [ "commutative" ]
47

48
49
50
51
@op
class Address(EntConst):
	"""Symbolic constant that represents the address of an entity (variable or method)"""

Matthias Braun's avatar
Matthias Braun committed
52
53
@op
class Alloc:
54
55
56
57
	"""Allocates a block of memory on the stack."""
	ins = [
		("mem",  "memory dependency" ),
		("size", "size of the block in bytes" ),
58
	]
59
60
61
	outs = [
		("M",   "memory result"),
		("res", "pointer to newly allocated memory"),
62
	]
63
64
	attrs = [
		dict(
65
66
67
			name    = "alignment",
			type    = "unsigned",
			comment = "alignment of the memory block (must be a power of 2)",
68
		),
69
	]
70
71
	flags       = [ "uses_memory" ]
	pinned      = "yes"
72
73
	attr_struct = "alloc_attr"

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Matthias Braun's avatar
Matthias Braun committed
422
@op
423
class Conv:
424
	"""Converts values between modes"""
425
426
427
428
429
	flags  = []
	pinned = "no"
	ins    = [
		("op", "operand")
	]
430

Matthias Braun's avatar
Matthias Braun committed
431
432
@op
class CopyB:
Matthias Braun's avatar
Matthias Braun committed
433
	"""Copies a block of memory with statically known size/type."""
434
435
436
437
438
	ins   = [
		("mem",  "memory dependency"),
		("dst",  "destination address"),
		("src",  "source address"),
	]
439
440
	mode  = "mode_M"
	flags = [ "uses_memory" ]
441
442
	attrs = [
		dict(
443
444
445
			name    = "type",
			type    = "ir_type*",
			comment = "type of copied data",
446
447
448
449
450
451
452
		),
		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"
453
		)
454
455
	]
	attr_struct = "copyb_attr"
456
457
458
459
460
461
462
	constructor_args = [
		dict(
			type    = "ir_cons_flags",
			name    = "flags",
			comment = "specifies volatility",
		),
	]
463
	pinned      = "no"
464

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

Matthias Braun's avatar
Matthias Braun committed
498
499
@op
class Dummy:
500
501
502
	"""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."""
503
504
	ins        = []
	flags      = [ "cfopcode", "start_block", "constlike", "dump_noblock" ]
505
506
507
508
	knownBlock = True
	pinned     = "yes"
	block      = "get_irg_start_block(irg)"

Matthias Braun's avatar
Matthias Braun committed
509
510
@op
class End:
511
512
	"""Last node of a graph. It references nodes in endless loops (so called
	keepalive edges)"""
513
514
515
	mode             = "mode_X"
	pinned           = "yes"
	arity            = "dynamic"
516
	input_name       = "keepalive"
517
518
519
520
	flags            = [ "cfopcode" ]
	knownBlock       = True
	block            = "get_irg_end_block(irg)"
	singleton        = True
521

Matthias Braun's avatar
Matthias Braun committed
522
@op
523
class Eor(Binop):
Matthias Braun's avatar
Matthias Braun committed
524
525
526
	"""returns the result of a bitwise exclusive or operation of its operands.

	This is also known as the Xor operation."""
527
	flags    = [ "commutative" ]
528

Matthias Braun's avatar
Matthias Braun committed
529
530
@op
class Free:
531
	"""Frees a block of memory previously allocated by an Alloc node"""
532
533
534
	ins = [
		("mem", "memory dependency" ),
		("ptr", "pointer to the object to free"),
535
	]
536
537
538
539
	mode   = "mode_M"
	flags  = [ "uses_memory" ]
	pinned = "yes"

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

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

Matthias Braun's avatar
Matthias Braun committed
564
565
@op
class Jmp:
566
	"""Jumps to the block connected through the out-value"""
567
568
569
570
571
	mode     = "mode_X"
	pinned   = "yes"
	ins      = []
	flags    = [ "cfopcode" ]

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

Matthias Braun's avatar
Matthias Braun committed
619
@op
620
class Minus:
Andreas Seltenreich's avatar
Andreas Seltenreich committed
621
	"""returns the additive inverse of its operand"""
622
623
624
625
626
	flags  = []
	pinned = "no"
	ins    = [
		("op", "operand")
	]
627

Matthias Braun's avatar
Matthias Braun committed
628
629
@op
class Mod:
630
631
632
	"""returns the remainder of its operands from an implied division.

	Examples:
633

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

664
class Mul(Binop):
665
	"""returns the product of its operands"""
666
667
668
	flags = [ "commutative" ]

class Mulh(Binop):
669
670
	"""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)"""
671
672
	flags = [ "commutative" ]

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

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

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

704
705
706
707
@op
class Offset(EntConst):
	"""Symbolic constant that represents the offset of an entity in its owner type."""

Matthias Braun's avatar
Matthias Braun committed
708
@op
709
class Or(Binop):
710
	"""returns the result of a bitwise or operation of its operands"""
711
712
	flags = [ "commutative" ]

Matthias Braun's avatar
Matthias Braun committed
713
714
@op
class Phi:
715
716
717
	"""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."""
718
719
	pinned        = "yes"
	arity         = "variable"
720
	input_name    = "pred"
721
722
	flags         = []
	attr_struct   = "phi_attr"
723
	init          = '''
724
	res->attr.phi.u.backedge = new_backedge_arr(get_irg_obstack(irg), arity);'''
Matthias Braun's avatar
Matthias Braun committed
725
	customSerializer = True
726

Matthias Braun's avatar
Matthias Braun committed
727
728
@op
class Pin:
729
730
731
	"""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."""
732
733
734
	ins      = [
		("op", "value which is pinned"),
	]
735
736
737
738
	mode     = "get_irn_mode(irn_op)"
	flags    = [ "highlevel" ]
	pinned   = "yes"

Matthias Braun's avatar
Matthias Braun committed
739
740
@op
class Proj:
741
	"""returns an entry of a tuple value"""
742
743
744
	ins              = [
		("pred", "the tuple value from which a part is extracted"),
	]
745
746
747
748
749
750
	flags            = []
	pinned           = "no"
	knownBlock       = True
	knownGraph       = True
	block            = "get_nodes_block(irn_pred)"
	graph            = "get_irn_irg(irn_pred)"
751
	attrs      = [
752
		dict(
753
754
755
			type    = "long",
			name    = "proj",
			comment = "number of tuple component to be extracted",
756
		),
757
	]
758
	attr_struct = "proj_attr"
759

Matthias Braun's avatar
Matthias Braun committed
760
761
@op
class Raise:
762
763
764
	"""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."""
765
766
767
768
	ins    = [
		("mem",     "memory dependency"),
		("exo_ptr", "pointer to exception object to be thrown"),
	]
769
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
770
771
		("M", "memory result"),
		("X", "control flow to exception handler"),
772
	]
773
774
775
	flags  = [ "highlevel", "cfopcode" ]
	pinned = "yes"

Matthias Braun's avatar
Matthias Braun committed
776
777
@op
class Return:
778
779
	"""Returns from the current function. Takes memory and return values as
	operands."""
780
	ins        = [
781
782
		("mem", "memory dependency"),
	]
783
784
785
786
787
	arity      = "variable"
	input_name = "res"
	mode       = "mode_X"
	flags      = [ "cfopcode" ]
	pinned     = "yes"
788

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

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

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

Matthias Braun's avatar
Matthias Braun committed
832
@op
833
class Shrs(Binop):
834
835
	"""Returns its first operands bits shifted right by the amount of the 2nd
	operand. The leftmost bit (usually the sign bit) stays the same
836
837
838
839
	(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."""
840
841
	flags = []

Matthias Braun's avatar
Matthias Braun committed
842
843
@op
class Start:
844
	"""The first node of a graph. Execution starts with this node."""
845
846
847
848
849
850
	outs       = [
		("X_initial_exec", "control flow"),
		("M",              "initial memory"),
		("P_frame_base",   "frame base pointer"),
		("T_args",         "function arguments")
	]
851
852
853
854
855
856
	mode             = "mode_T"
	pinned           = "yes"
	flags            = [ "cfopcode" ]
	singleton        = True
	knownBlock       = True
	block            = "get_irg_start_block(irg)"
857

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

Matthias Braun's avatar
Matthias Braun committed
900
@op
901
class Sub(Binop):
902
	"""returns the difference of its operands"""
903
904
	flags = []

905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
@op
class TypeConst:
	"""A symbolic constant.

	 - *typeconst_size* The symbolic constant represents the size of a type.
	 - *typeconst_align* The symbolic constant represents the alignment of a type."""
	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",
		),
		dict(
			type    = "typeconst_kind",
			name    = "kind",
			comment = "aspect of the type",
		)
	]
	attr_struct = "typeconst_attr"
	attrs_name  = "typec"
929
	customSerializer = 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" ]