ir_spec.py 26.1 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.
7
from spec_util import abstract, op, Attribute
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
@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)"
	pinned     = "no"
	attrs      = [
33
		Attribute("entity", type="ir_entity*", comment="entity to operate on"),
34
35
36
37
	]
	attr_struct = "entconst_attr"
	attrs_name  = "entc"

38
39
@abstract
@op
40
class TypeConst(object):
41
42
43
44
45
46
	"""A symbolic constant that represents an aspect of a type"""
	name       = "typeconst"
	flags      = [ "constlike", "start_block" ]
	block      = "get_irg_start_block(irg)"
	pinned     = "no"
	attrs      = [
47
		Attribute("type", type="ir_type*", comment="type to operate on"),
48
49
50
51
	]
	attr_struct = "typeconst_attr"
	attrs_name  = "typec"

Matthias Braun's avatar
Matthias Braun committed
52
@op
53
class Add(Binop):
54
	"""returns the sum of its operands"""
55
	flags = [ "commutative" ]
56

57
58
59
@op
class Address(EntConst):
	"""Symbolic constant that represents the address of an entity (variable or method)"""
60
	mode = "mode_P"
61

62
63
64
65
@op
class Align(TypeConst):
	"""A symbolic constant that represents the alignment of a type"""

Matthias Braun's avatar
Matthias Braun committed
66
67
@op
class Alloc:
68
69
70
71
	"""Allocates a block of memory on the stack."""
	ins = [
		("mem",  "memory dependency" ),
		("size", "size of the block in bytes" ),
72
	]
73
74
75
	outs = [
		("M",   "memory result"),
		("res", "pointer to newly allocated memory"),
76
	]
77
	attrs = [
78
79
		Attribute("alignment", type="unsigned",
		          comment="alignment of the memory block (must be a power of 2)"),
80
	]
81
	flags       = [ "uses_memory", "const_memory" ]
82
	pinned      = "yes"
83
84
	attr_struct = "alloc_attr"

Matthias Braun's avatar
Matthias Braun committed
85
86
@op
class Anchor:
87
88
89
90
91
92
	"""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."""
93
94
95
96
97
98
99
100
	mode             = "mode_ANY"
	arity            = "variable"
	flags            = [ "dump_noblock" ]
	pinned           = "yes"
	attr_struct      = "irg_attr"
	singleton        = True
	noconstructor    = True
	customSerializer = True
101

Matthias Braun's avatar
Matthias Braun committed
102
@op
103
class And(Binop):
104
	"""returns the result of a bitwise and operation of its operands"""
105
106
	flags    = [ "commutative" ]

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

Matthias Braun's avatar
Matthias Braun committed
165
166
@op
class Bad:
167
168
169
170
171
172
	"""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).
yb9976's avatar
yb9976 committed
173
	Optimizations also set block predecessors to Bad when it becomes clear,
174
175
	that a control flow edge can never be executed.

yb9976's avatar
yb9976 committed
176
	The gigo optimizations ensures that nodes with Bad as their block, get
Christoph Mallon's avatar
Christoph Mallon committed
177
	replaced by Bad themselves. Nodes with at least 1 Bad input get exchanged
178
179
180
181
	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
yb9976's avatar
yb9976 committed
182
	optimization phase. Block, Phi, Tuple with only Bad inputs however are
183
184
185
186
	replaced by Bad right away.

	In the future we may use the Bad node to model poison values that arise
	from undefined behaviour like reading uninitialized local variables in C."""
Matthias Braun's avatar
Matthias Braun committed
187
	flags         = [ "start_block", "dump_noblock" ]
188
	pinned        = "yes"
189
	block         = "get_irg_start_block(irg)"
190
	attr_struct   = "bad_attr"
191
	init = '''
192
	res->attr.bad.irg.irg = irg;
193
194
	'''

Matthias Braun's avatar
Matthias Braun committed
195
196
@op
class Deleted:
197
198
	"""Internal node which is temporary set to nodes which are already removed
	from the graph."""
199
200
201
202
	mode             = "mode_Bad"
	flags            = [ ]
	pinned           = "yes"
	noconstructor    = True
Matthias Braun's avatar
Matthias Braun committed
203
	customSerializer = True # this has no serializer
204

Matthias Braun's avatar
Matthias Braun committed
205
206
@op
class Block:
207
	"""A basic block"""
208
209
210
211
	mode             = "mode_BB"
	block            = "NULL"
	pinned           = "yes"
	arity            = "variable"
212
	input_name       = "cfgpred"
213
	flags            = []
214
	attr_struct      = "block_attr"
215
	attrs            = [
216
217
		Attribute("entity", type="ir_entity*", init="NULL",
		          comment="entity representing this block"),
218
	]
219
	customSerializer = True
Moritz Kroll's avatar
Moritz Kroll committed
220
221

	init = '''
222
	res->attr.block.irg.irg     = irg;
223
	res->attr.block.backedge    = new_backedge_arr(get_irg_obstack(irg), arity);
Moritz Kroll's avatar
Moritz Kroll committed
224
	set_Block_matured(res, 1);
225
226

	/* Create and initialize array for Phi-node construction. */
227
	if (irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_CONSTRUCTION)) {
228
		res->attr.block.graph_arr = NEW_ARR_DZ(ir_node*, get_irg_obstack(irg), irg->n_loc);
229
	}
230
	'''
231

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

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

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

Matthias Braun's avatar
Matthias Braun committed
300
301
@op
class Cond:
302
	"""Conditionally change control flow."""
303
304
305
	ins      = [
		("selector",  "condition parameter"),
	]
306
307
308
309
	outs     = [
		("false", "control flow if operand is \"false\""),
		("true",  "control flow if operand is \"true\""),
	]
310
311
	flags    = [ "cfopcode", "forking" ]
	pinned   = "yes"
312
	attrs    = [
313
314
315
		Attribute("jmp_pred", type="cond_jmp_predicate",
		          init="COND_JMP_PRED_NONE",
		          comment = "can indicate the most likely jump"),
316
	]
317
	attr_struct = "cond_attr"
318

Matthias Braun's avatar
Matthias Braun committed
319
320
@op
class Switch:
Matthias Braun's avatar
Matthias Braun committed
321
322
323
324
325
326
327
328
329
330
331
332
	"""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  = [
333
334
335
336
		Attribute("n_outs", type="unsigned",
		          comment="number of outputs (including pn_Switch_default)"),
		Attribute("table", type="ir_switch_table*",
		          comment="table describing mapping from input values to Proj numbers"),
Matthias Braun's avatar
Matthias Braun committed
337
338
339
340
	]
	attr_struct = "switch_attr"
	attrs_name  = "switcha"

Matthias Braun's avatar
Matthias Braun committed
341
342
@op
class Confirm:
343
344
345
346
347
348
349
350
351
	"""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."""
352
353
354
355
	ins      = [
		("value",  "value to express a constraint for"),
		("bound",  "value to compare against"),
	]
356
	mode     = "get_irn_mode(irn_value)"
Matthias Braun's avatar
Matthias Braun committed
357
	flags    = [ ]
358
	pinned   = "yes"
359
	attrs    = [
360
361
		Attribute("relation", type="ir_relation",
		          comment="relation of value to bound"),
362
363
364
	]
	attr_struct = "confirm_attr"

Matthias Braun's avatar
Matthias Braun committed
365
366
@op
class Const:
367
	"""Returns a constant value."""
368
	flags      = [ "constlike", "start_block" ]
369
370
	block      = "get_irg_start_block(irg)"
	mode       = "get_tarval_mode(tarval)"
371
	pinned     = "no"
372
	attrs      = [
373
374
		Attribute("tarval", type="ir_tarval*",
		          comment="constant value (a tarval object)"),
375
376
	]
	attr_struct = "const_attr"
377
	attrs_name  = "con"
378

Matthias Braun's avatar
Matthias Braun committed
379
@op
380
class Conv:
381
	"""Converts values between modes"""
382
383
384
385
386
	flags  = []
	pinned = "no"
	ins    = [
		("op", "operand")
	]
387

Matthias Braun's avatar
Matthias Braun committed
388
389
390
391
392
393
394
395
396
397
@op
class Bitcast:
	"""Converts a value between modes with different arithmetics but same
	number of bits by reinterpreting the bits in the new mode"""
	flags = []
	pinned = "no"
	ins = [
		("op", "operand")
	]

Matthias Braun's avatar
Matthias Braun committed
398
399
@op
class CopyB:
Matthias Braun's avatar
Matthias Braun committed
400
	"""Copies a block of memory with statically known size/type."""
401
402
403
404
405
	ins   = [
		("mem",  "memory dependency"),
		("dst",  "destination address"),
		("src",  "source address"),
	]
406
407
	mode  = "mode_M"
	flags = [ "uses_memory" ]
408
	attrs = [
409
410
411
412
413
		Attribute("type", type="ir_type*", comment="type of copied data"),
		Attribute("volatility", type="ir_volatility",
		          init="flags & cons_volatile ? volatility_is_volatile : volatility_non_volatile",
		          to_flags="%s == volatility_is_volatile ? cons_volatile : cons_none",
		          comment="volatile CopyB nodes have a visible side-effect and may not be optimized"),
414
415
	]
	attr_struct = "copyb_attr"
416
	constructor_args = [
417
418
		Attribute("flags", type="ir_cons_flags",
		          comment="specifies volatility"),
419
	]
420
	pinned      = "no"
421

Matthias Braun's avatar
Matthias Braun committed
422
423
@op
class Div:
424
	"""returns the quotient of its 2 operands"""
425
426
427
428
429
	ins   = [
		("mem",   "memory dependency"),
		("left",  "first operand"),
		("right", "second operand"),
	]
430
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
431
		("M",         "memory result"),
432
		("res",       "result of computation"),
Matthias Braun's avatar
Matthias Braun committed
433
434
		("X_regular", "control flow when no exception occurs"),
		("X_except",  "control flow when exception occured"),
435
	]
436
	flags = [ "fragile", "uses_memory", "const_memory" ]
437
	attrs = [
438
439
440
		Attribute("resmode", type="ir_mode*",
		          comment="mode of the result value"),
		Attribute("no_remainder", type="int", init="0"),
441
	]
442
	attr_struct = "div_attr"
443
	pinned      = "exception"
444
	throws_init = "false"
445
446
	op_index    = 1
	arity_override = "oparity_binary"
447

Matthias Braun's avatar
Matthias Braun committed
448
449
@op
class Dummy:
450
451
452
	"""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."""
453
454
	ins        = []
	flags      = [ "cfopcode", "start_block", "constlike", "dump_noblock" ]
455
456
457
	pinned     = "yes"
	block      = "get_irg_start_block(irg)"

Matthias Braun's avatar
Matthias Braun committed
458
459
@op
class End:
460
461
	"""Last node of a graph. It references nodes in endless loops (so called
	keepalive edges)"""
462
463
464
	mode             = "mode_X"
	pinned           = "yes"
	arity            = "dynamic"
465
	input_name       = "keepalive"
466
467
468
	flags            = [ "cfopcode" ]
	block            = "get_irg_end_block(irg)"
	singleton        = True
469

Matthias Braun's avatar
Matthias Braun committed
470
@op
471
class Eor(Binop):
Matthias Braun's avatar
Matthias Braun committed
472
473
474
	"""returns the result of a bitwise exclusive or operation of its operands.

	This is also known as the Xor operation."""
475
	flags    = [ "commutative" ]
476

Matthias Braun's avatar
Matthias Braun committed
477
478
@op
class Free:
479
	"""Frees a block of memory previously allocated by an Alloc node"""
480
481
482
	ins = [
		("mem", "memory dependency" ),
		("ptr", "pointer to the object to free"),
483
	]
484
	mode   = "mode_M"
485
	flags  = [ "uses_memory", "const_memory" ]
486
487
	pinned = "yes"

Matthias Braun's avatar
Matthias Braun committed
488
489
@op
class Id:
Matthias Braun's avatar
Matthias Braun committed
490
491
492
493
	"""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."""
494
495
496
	ins    = [
	   ("pred", "the value which is returned unchanged")
	]
497
498
499
	pinned = "no"
	flags  = []

Matthias Braun's avatar
Matthias Braun committed
500
501
@op
class IJmp:
502
503
504
	"""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"""
505
506
	mode     = "mode_X"
	pinned   = "yes"
507
508
509
	ins      = [
	   ("target", "target address of the jump"),
	]
510
	flags    = [ "cfopcode", "forking", "keep", "unknown_jump" ]
511

Matthias Braun's avatar
Matthias Braun committed
512
513
@op
class Jmp:
514
	"""Jumps to the block connected through the out-value"""
515
516
517
518
519
	mode     = "mode_X"
	pinned   = "yes"
	ins      = []
	flags    = [ "cfopcode" ]

Matthias Braun's avatar
Matthias Braun committed
520
521
@op
class Load:
522
	"""Loads a value from memory (heap or stack)."""
523
524
525
526
	ins   = [
		("mem", "memory dependency"),
		("ptr",  "address to load from"),
	]
527
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
528
		("M",         "memory result"),
529
		("res",       "result of load operation"),
Matthias Braun's avatar
Matthias Braun committed
530
531
		("X_regular", "control flow when no exception occurs"),
		("X_except",  "control flow when exception occured"),
532
	]
533
	flags    = [ "fragile", "uses_memory", "const_memory" ]
534
	pinned   = "exception"
535
	attrs    = [
536
537
538
539
540
541
542
543
544
545
		Attribute("mode", type="ir_mode*",
		          comment="mode of the value to be loaded"),
		Attribute("volatility", type="ir_volatility",
		          init="flags & cons_volatile ? volatility_is_volatile : volatility_non_volatile",
		          to_flags="%s == volatility_is_volatile ? cons_volatile : cons_none",
		          comment="volatile loads are a visible side-effect and may not be optimized"),
		Attribute("unaligned", type="ir_align",
		          init="flags & cons_unaligned ? align_non_aligned : align_is_aligned",
		          to_flags="%s == align_non_aligned ? cons_unaligned : cons_none",
		          comment="pointers to unaligned loads don't need to respect the load-mode/type alignments"),
546
547
	]
	attr_struct = "load_attr"
548
	constructor_args = [
549
550
		Attribute("flags", type="ir_cons_flags",
		          comment="specifies alignment, volatility and pin state"),
551
	]
552
	pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
553
	throws_init = "(flags & cons_throws_exception) != 0"
554

Matthias Braun's avatar
Matthias Braun committed
555
@op
556
class Minus:
Andreas Seltenreich's avatar
Andreas Seltenreich committed
557
	"""returns the additive inverse of its operand"""
558
559
560
561
562
	flags  = []
	pinned = "no"
	ins    = [
		("op", "operand")
	]
563

Matthias Braun's avatar
Matthias Braun committed
564
565
@op
class Mod:
566
567
568
	"""returns the remainder of its operands from an implied division.

	Examples:
569

570
571
572
573
574
	* mod(5,3)   produces 2
	* mod(5,-3)  produces 2
	* mod(-5,3)  produces -2
	* mod(-5,-3) produces -2
	"""
575
576
577
578
579
	ins   = [
		("mem",   "memory dependency"),
		("left",  "first operand"),
		("right", "second operand"),
	]
580
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
581
		("M",         "memory result"),
582
		("res",       "result of computation"),
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
	flags = [ "fragile", "uses_memory", "const_memory" ]
587
	attrs = [
588
		Attribute("resmode", type="ir_mode*", comment="mode of the result"),
589
	]
590
	attr_struct = "mod_attr"
591
	pinned      = "exception"
592
	throws_init = "false"
593
594
	op_index    = 1
	arity_override = "oparity_binary"
Matthias Braun's avatar
Matthias Braun committed
595

596
class Mul(Binop):
597
	"""returns the product of its operands"""
598
599
600
	flags = [ "commutative" ]

class Mulh(Binop):
601
602
	"""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)"""
603
604
	flags = [ "commutative" ]

Matthias Braun's avatar
Matthias Braun committed
605
606
@op
class Mux:
607
608
	"""returns the false or true operand depending on the value of the sel
	operand"""
609
610
611
612
613
	ins    = [
	   ("sel",   "value making the output selection"),
	   ("false", "selected if sel input is false"),
	   ("true",  "selected if sel input is true"),
	]
614
615
616
	flags  = []
	pinned = "no"

Matthias Braun's avatar
Matthias Braun committed
617
618
@op
class NoMem:
619
	"""Placeholder node for cases where you don't need any memory input"""
620
	mode          = "mode_M"
621
	flags         = [ "dump_noblock", "start_block" ]
622
	pinned        = "yes"
623
	block         = "get_irg_start_block(irg)"
624
	singleton     = True
625

Matthias Braun's avatar
Matthias Braun committed
626
@op
627
class Not:
628
	"""returns the bitwise complement of a value. Works for boolean values, too."""
629
630
631
632
633
	flags  = []
	pinned = "no"
	ins    = [
		("op", "operand")
	]
634

635
636
637
638
@op
class Offset(EntConst):
	"""Symbolic constant that represents the offset of an entity in its owner type."""

Matthias Braun's avatar
Matthias Braun committed
639
@op
640
class Or(Binop):
641
	"""returns the result of a bitwise or operation of its operands"""
642
643
	flags = [ "commutative" ]

Matthias Braun's avatar
Matthias Braun committed
644
645
@op
class Phi:
646
647
648
	"""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."""
649
650
	pinned        = "yes"
	arity         = "variable"
651
	input_name    = "pred"
652
	flags         = []
653
654
655
656
	attrs         = [
		Attribute("loop", type="int", init="0",
		          comment="wether Phi represents the observable effect of a (possibly) nonterminating loop"),
	]
657
	attr_struct   = "phi_attr"
658
	init          = '''
659
	res->attr.phi.u.backedge = new_backedge_arr(get_irg_obstack(irg), arity);'''
Matthias Braun's avatar
Matthias Braun committed
660
	customSerializer = True
661

Matthias Braun's avatar
Matthias Braun committed
662
663
@op
class Pin:
664
665
666
	"""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."""
667
668
669
	ins      = [
		("op", "value which is pinned"),
	]
670
	mode     = "get_irn_mode(irn_op)"
Matthias Braun's avatar
Matthias Braun committed
671
	flags    = [ ]
672
673
	pinned   = "yes"

Matthias Braun's avatar
Matthias Braun committed
674
675
@op
class Proj:
676
	"""returns an entry of a tuple value"""
677
	ins        = [
678
679
		("pred", "the tuple value from which a part is extracted"),
	]
680
681
682
	flags      = []
	pinned     = "no"
	block      = "get_nodes_block(irn_pred)"
683
	usesGraph  = False
684
	attrs      = [
685
686
		Attribute("proj", type="long",
		          comment="number of tuple component to be extracted"),
687
	]
688
	attr_struct = "proj_attr"
689

Matthias Braun's avatar
Matthias Braun committed
690
691
@op
class Raise:
692
693
694
	"""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."""
695
696
697
698
	ins    = [
		("mem",     "memory dependency"),
		("exo_ptr", "pointer to exception object to be thrown"),
	]
699
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
700
701
		("M", "memory result"),
		("X", "control flow to exception handler"),
702
	]
Matthias Braun's avatar
Matthias Braun committed
703
	flags  = [ "cfopcode" ]
704
705
	pinned = "yes"

Matthias Braun's avatar
Matthias Braun committed
706
707
@op
class Return:
708
709
	"""Returns from the current function. Takes memory and return values as
	operands."""
710
	ins        = [
711
712
		("mem", "memory dependency"),
	]
713
714
715
716
717
	arity      = "variable"
	input_name = "res"
	mode       = "mode_X"
	flags      = [ "cfopcode" ]
	pinned     = "yes"
718

Matthias Braun's avatar
Matthias Braun committed
719
720
@op
class Sel:
721
722
	"""Computes the address of an array element from the array base pointer and
	an index.
723

724
725
726
727
728
729
	A Sel node must only produce a NULL pointer if the ptr input is NULL."""
	ins = [
		("ptr",   "pointer to array to select from"),
		("index", "index to select"),
	]
	flags  = []
730
	mode   = "mode_P"
731
732
733
734
735
736
737
738
739
740
741
742
743
744
	pinned = "no"
	attrs  = [
		Attribute("type", type="ir_type*",
		          comment="array type"),
	]
	attr_struct = "sel_attr"

@op
class Member:
	"""Computes the address of a compound type member given the base address
	of an instance of the compound type.

	A Member node must only produce a NULL pointer if the ptr input is NULL."""
	ins = [
745
746
		("ptr", "pointer to object to select from"),
	]
747
	flags   = []
748
	mode    = "mode_P"
749
750
	pinned  = "no"
	attrs   = [
751
752
		Attribute("entity", type="ir_entity*",
		          comment="entity which is selected"),
753
	]
754
	attr_struct = "member_attr"
755

Matthias Braun's avatar
Matthias Braun committed
756
@op
757
class Shl(Binop):
758
	"""Returns its first operands bits shifted left by the amount of the 2nd
759
760
761
762
	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."""
763
764
	flags = []

Matthias Braun's avatar
Matthias Braun committed
765
@op
766
class Shr(Binop):
767
	"""Returns its first operands bits shifted right by the amount of the 2nd
768
769
770
771
	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."""
772
773
	flags = []

Matthias Braun's avatar
Matthias Braun committed
774
@op
775
class Shrs(Binop):
776
777
	"""Returns its first operands bits shifted right by the amount of the 2nd
	operand. The leftmost bit (usually the sign bit) stays the same
778
779
780
781
	(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."""
782
783
	flags = []

Matthias Braun's avatar
Matthias Braun committed
784
785
@op
class Start:
786
	"""The first node of a graph. Execution starts with this node."""
787
788
789
790
791
792
	outs       = [
		("X_initial_exec", "control flow"),
		("M",              "initial memory"),
		("P_frame_base",   "frame base pointer"),
		("T_args",         "function arguments")
	]
793
794
795
796
797
	mode             = "mode_T"
	pinned           = "yes"
	flags            = [ "cfopcode" ]
	singleton        = True
	block            = "get_irg_start_block(irg)"
798

Matthias Braun's avatar
Matthias Braun committed
799
800
@op
class Store:
801
	"""Stores a value into memory (heap or stack)."""
802
803
804
805
806
	ins   = [
	   ("mem",   "memory dependency"),
	   ("ptr",   "address to store to"),
	   ("value", "value to store"),
	]
807
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
808
809
810
		("M",         "memory result"),
		("X_regular", "control flow when no exception occurs"),
		("X_except",  "control flow when exception occured"),
811
	]
812
813
814
815
	flags    = [ "fragile", "uses_memory" ]
	pinned   = "exception"
	attr_struct = "store_attr"
	pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
816
	throws_init = "(flags & cons_throws_exception) != 0"
817
	attrs = [
818
819
820
821
822
823
824
825
		Attribute("volatility", type="ir_volatility",
		          init="flags & cons_volatile ? volatility_is_volatile : volatility_non_volatile",
		          to_flags="%s == volatility_is_volatile ? cons_volatile : cons_none",
		          comment="volatile stores are a visible side-effect and may not be optimized"),
		Attribute("unaligned", type="ir_align",
		          init="flags & cons_unaligned ? align_non_aligned : align_is_aligned",
		          to_flags="%s == align_non_aligned ? cons_unaligned : cons_none",
		          comment="pointers to unaligned stores don't need to respect the load-mode/type alignments"),
826
	]
827
	constructor_args = [
828
829
		Attribute("flags", type="ir_cons_flags",
		          comment="specifies alignment, volatility and pin state"),
830
831
	]

Matthias Braun's avatar
Matthias Braun committed
832
@op
833
class Sub(Binop):
834
	"""returns the difference of its operands"""
835
836
	flags = []

837
@op
838
839
class Size(TypeConst):
	"""A symbolic constant that represents the size of a type"""
840

Matthias Braun's avatar
Matthias Braun committed
841
842
@op
class Sync:
843
844
845
846
847
	"""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."""
848
849
850
851
852
	mode       = "mode_M"
	flags      = []
	pinned     = "no"
	arity      = "dynamic"
	input_name = "pred"
853

Matthias Braun's avatar
Matthias Braun committed
854
855
@op
class Tuple:
856
857
858
859
860
861
862
	"""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
863
	just changing its opcode and giving it a new in array."""
864
865
866
867
868
	arity      = "variable"
	input_name = "pred"
	mode       = "mode_T"
	pinned     = "no"
	flags      = []
869

Matthias Braun's avatar
Matthias Braun committed
870
871
@op
class Unknown:
872
	"""Returns an unknown (at compile- and runtime) value. It is a valid
Matthias Braun's avatar
Matthias Braun committed
873
874
	optimization to replace an Unknown by any other constant value.

Matthias Braun's avatar
Matthias Braun committed
875
	Be careful when optimising Unknown values, you cannot simply replace
Matthias Braun's avatar
Matthias Braun committed
876
877
	Unknown+x or Unknown<x with a new Unknown node if there are multiple
	users of the original unknown node!"""
878
879
	pinned     = "yes"
	block      = "get_irg_start_block(irg)"
Matthias Braun's avatar
Matthias Braun committed
880
	flags      = [ "start_block", "constlike", "dump_noblock" ]