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
@op
class Address(EntConst):
	"""Symbolic constant that represents the address of an entity (variable or method)"""
51
	mode = "get_type_pointer_mode(get_entity_type(entity))"
52

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

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

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

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

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

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

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

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

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

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

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

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

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

Matthias Braun's avatar
Matthias Braun committed
350
351
@op
class Switch:
Matthias Braun's avatar
Matthias Braun committed
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
377
	"""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
378
379
@op
class Confirm:
380
381
382
383
384
385
386
387
388
	"""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."""
389
390
391
392
	ins      = [
		("value",  "value to express a constraint for"),
		("bound",  "value to compare against"),
	]
393
394
395
	mode     = "get_irn_mode(irn_value)"
	flags    = [ "highlevel" ]
	pinned   = "yes"
396
397
	attrs    = [
		dict(
398
399
400
			name    = "relation",
			type    = "ir_relation",
			comment = "relation of value to bound",
401
		),
402
403
404
	]
	attr_struct = "confirm_attr"

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	Examples:
634

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
@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"
930
	customSerializer = True
931

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

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

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