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
107
108
109
110
111
	flags            = [ "keep", "uses_memory" ]
	pinned           = "memory"
	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
180
	'''

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

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

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

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

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

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

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

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

Matthias Braun's avatar
Matthias Braun committed
326
327
@op
class Switch:
Matthias Braun's avatar
Matthias Braun committed
328
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
	"""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
354
355
@op
class Confirm:
356
357
358
359
360
361
362
363
364
	"""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."""
365
366
367
368
	ins      = [
		("value",  "value to express a constraint for"),
		("bound",  "value to compare against"),
	]
369
370
371
	mode     = "get_irn_mode(irn_value)"
	flags    = [ "highlevel" ]
	pinned   = "yes"
372
373
	attrs    = [
		dict(
374
375
376
			name    = "relation",
			type    = "ir_relation",
			comment = "relation of value to bound",
377
		),
378
379
380
	]
	attr_struct = "confirm_attr"

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

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

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

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

Matthias Braun's avatar
Matthias Braun committed
467
468
@op
class Dummy:
469
470
471
	"""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."""
472
473
	ins        = []
	flags      = [ "cfopcode", "start_block", "constlike", "dump_noblock" ]
474
475
476
477
	knownBlock = True
	pinned     = "yes"
	block      = "get_irg_start_block(irg)"

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

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

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

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

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

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

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

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

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

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

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

	Examples:
627

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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