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 irops 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
	op_index       = 0
	arity_override = "oparity_binary"
22

23
24
25
26
27
28
29
@abstract
@op
class EntConst(object):
	"""Symbolic constant that represents an aspect of an entity"""
	name       = "entconst"
	flags      = [ "constlike", "start_block" ]
	attrs      = [
30
		Attribute("entity", type="ir_entity*", comment="entity to operate on"),
31
32
33
34
	]
	attr_struct = "entconst_attr"
	attrs_name  = "entc"

35
36
@abstract
@op
37
class TypeConst(object):
38
39
40
41
	"""A symbolic constant that represents an aspect of a type"""
	name       = "typeconst"
	flags      = [ "constlike", "start_block" ]
	attrs      = [
42
		Attribute("type", type="ir_type*", comment="type to operate on"),
43
44
45
46
	]
	attr_struct = "typeconst_attr"
	attrs_name  = "typec"

Matthias Braun's avatar
Matthias Braun committed
47
@op
48
class Add(Binop):
49
	"""returns the sum of its operands"""
50
	flags = [ "commutative" ]
51

52
53
54
@op
class Address(EntConst):
	"""Symbolic constant that represents the address of an entity (variable or method)"""
55
	mode = "mode_P"
56

57
58
59
60
@op
class Align(TypeConst):
	"""A symbolic constant that represents the alignment of a type"""

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

Matthias Braun's avatar
Matthias Braun committed
80
@op
81
class Anchor(object):
82
	"""Utility node used to "hold" nodes in a graph that might possibly not be
83
84
85
	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
86
	known. All other well-known graph-nodes like Start, End, NoMem, ...
87
	are found by looking at the respective Anchor operand."""
88
89
90
91
92
93
94
95
96
97
	ins = [
		("end_block",   "block the end node belongs to" ),
		("start_block", "block the start node belongs to" ),
		("end",         "end node of this ir_graph" ),
		("start",       "start node of this ir_graph" ),
		("frame",       "frame of this ir_graph" ),
		("initial_mem", "initial memory of this ir_graph" ),
		("args",        "argument proj of the start node" ),
		("no_mem",      "the only NoMem node of this ir_graph" ),
	]
98
99
100
101
102
	mode        = "mode_ANY"
	flags       = [ "dump_noblock" ]
	pinned      = "yes"
	singleton   = True
	constructor = False
103

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

Matthias Braun's avatar
Matthias Braun committed
109
@op
110
class ASM(object):
Matthias Braun's avatar
Matthias Braun committed
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
136
137
	"""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)
	"""
138
139
140
141
142
143
144
145
146
	mode        = "mode_T"
	arity       = "variable"
	input_name  = "input"
	flags       = [ "keep", "uses_memory" ]
	pinned      = "exception"
	pinned_init = "op_pin_state_pinned"
	attr_struct = "asm_attr"
	attrs_name  = "assem"
	ins         = [
147
148
		("mem",    "memory dependency"),
	]
149
	attrs       = [
150
151
152
153
154
155
156
157
158
159
160
		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"),
161
162
163
	]
	# constructor is written manually at the moment, because of the clobbers+
	# constraints arrays needing special handling (2 arguments for 1 attribute)
164
	constructor = False
165

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

177
	The gigo optimizations ensures that nodes with Bad as their block, get
Christoph Mallon's avatar
Christoph Mallon committed
178
	replaced by Bad themselves. Nodes with at least 1 Bad input get exchanged
179
180
181
182
	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
183
	optimization phase. Block, Phi, Tuple with only Bad inputs however are
184
185
186
187
	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
188
	flags         = [ "start_block", "dump_noblock" ]
189
	pinned        = "yes"
190

Matthias Braun's avatar
Matthias Braun committed
191
@op
192
class Deleted(object):
193
194
	"""Internal node which is temporary set to nodes which are already removed
	from the graph."""
195
196
197
198
	mode        = "mode_Bad"
	flags       = [ ]
	pinned      = "yes"
	constructor = False
199

Matthias Braun's avatar
Matthias Braun committed
200
@op
201
class Block(object):
202
	"""A basic block"""
203
204
205
206
207
208
209
210
	mode        = "mode_BB"
	block       = "NULL"
	pinned      = "yes"
	arity       = "variable"
	input_name  = "cfgpred"
	flags       = []
	attr_struct = "block_attr"
	attrs       = [
211
212
		Attribute("entity", type="ir_entity*", init="NULL",
		          comment="entity representing this block"),
213
	]
214
	serializer  = False
Moritz Kroll's avatar
Moritz Kroll committed
215
216

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

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

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

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

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

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

Matthias Braun's avatar
Matthias Braun committed
314
@op
315
class Switch(object):
Matthias Braun's avatar
Matthias Braun committed
316
317
318
319
320
321
322
323
324
	"""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"),
	]
325
	mode   = "mode_T"
Matthias Braun's avatar
Matthias Braun committed
326
327
328
	flags  = [ "cfopcode", "forking" ]
	pinned = "yes"
	attrs  = [
329
330
331
332
		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
333
334
335
336
	]
	attr_struct = "switch_attr"
	attrs_name  = "switcha"

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

Matthias Braun's avatar
Matthias Braun committed
361
@op
362
class Const(object):
363
	"""Returns a constant value."""
364
	flags      = [ "constlike", "start_block" ]
365
	mode       = "get_tarval_mode(tarval)"
366
	attrs      = [
367
368
		Attribute("tarval", type="ir_tarval*",
		          comment="constant value (a tarval object)"),
369
370
	]
	attr_struct = "const_attr"
371
	attrs_name  = "con"
372

Matthias Braun's avatar
Matthias Braun committed
373
@op
374
class Conv(object):
375
	"""Converts values between modes"""
376
377
378
379
	flags  = []
	ins    = [
		("op", "operand")
	]
380

Matthias Braun's avatar
Matthias Braun committed
381
@op
382
class Bitcast(object):
Matthias Braun's avatar
Matthias Braun committed
383
384
385
386
387
388
389
	"""Converts a value between modes with different arithmetics but same
	number of bits by reinterpreting the bits in the new mode"""
	flags = []
	ins = [
		("op", "operand")
	]

Matthias Braun's avatar
Matthias Braun committed
390
@op
391
class CopyB(object):
Matthias Braun's avatar
Matthias Braun committed
392
	"""Copies a block of memory with statically known size/type."""
393
394
395
396
397
	ins   = [
		("mem",  "memory dependency"),
		("dst",  "destination address"),
		("src",  "source address"),
	]
398
399
	mode  = "mode_M"
	flags = [ "uses_memory" ]
400
	attrs = [
401
402
403
404
405
		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"),
406
407
	]
	attr_struct = "copyb_attr"
408
	constructor_args = [
409
410
		Attribute("flags", type="ir_cons_flags",
		          comment="specifies volatility"),
411
	]
412

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

Matthias Braun's avatar
Matthias Braun committed
439
@op
440
class Dummy(object):
441
442
443
	"""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."""
444
445
	ins        = []
	flags      = [ "cfopcode", "start_block", "constlike", "dump_noblock" ]
446
447
	pinned     = "yes"

Matthias Braun's avatar
Matthias Braun committed
448
@op
449
class End(object):
450
451
	"""Last node of a graph. It references nodes in endless loops (so called
	keepalive edges)"""
452
453
454
	mode             = "mode_X"
	pinned           = "yes"
	arity            = "dynamic"
455
	input_name       = "keepalive"
456
457
458
	flags            = [ "cfopcode" ]
	block            = "get_irg_end_block(irg)"
	singleton        = True
459

Matthias Braun's avatar
Matthias Braun committed
460
@op
461
class Eor(Binop):
Matthias Braun's avatar
Matthias Braun committed
462
463
464
	"""returns the result of a bitwise exclusive or operation of its operands.

	This is also known as the Xor operation."""
465
	flags    = [ "commutative" ]
466

Matthias Braun's avatar
Matthias Braun committed
467
@op
468
class Free(object):
469
	"""Frees a block of memory previously allocated by an Alloc node"""
470
471
472
	ins = [
		("mem", "memory dependency" ),
		("ptr", "pointer to the object to free"),
473
	]
474
	mode   = "mode_M"
475
	flags  = [ "uses_memory", "const_memory" ]
476
477
	pinned = "yes"

Matthias Braun's avatar
Matthias Braun committed
478
@op
479
class Id(object):
Matthias Braun's avatar
Matthias Braun committed
480
481
482
483
	"""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."""
484
485
486
	ins    = [
	   ("pred", "the value which is returned unchanged")
	]
487
488
	flags       = []
	constructor = False
489

Matthias Braun's avatar
Matthias Braun committed
490
@op
491
class IJmp(object):
492
493
494
	"""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"""
495
496
	mode     = "mode_X"
	pinned   = "yes"
497
498
499
	ins      = [
	   ("target", "target address of the jump"),
	]
500
	flags    = [ "cfopcode", "forking", "keep", "unknown_jump" ]
501

Matthias Braun's avatar
Matthias Braun committed
502
@op
503
class Jmp(object):
504
	"""Jumps to the block connected through the out-value"""
505
506
507
508
509
	mode     = "mode_X"
	pinned   = "yes"
	ins      = []
	flags    = [ "cfopcode" ]

Matthias Braun's avatar
Matthias Braun committed
510
@op
511
class Load(object):
512
	"""Loads a value from memory (heap or stack)."""
513
514
515
516
	ins   = [
		("mem", "memory dependency"),
		("ptr",  "address to load from"),
	]
517
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
518
		("M",         "memory result"),
519
		("res",       "result of load operation"),
Matthias Braun's avatar
Matthias Braun committed
520
521
		("X_regular", "control flow when no exception occurs"),
		("X_except",  "control flow when exception occured"),
522
	]
523
	flags    = [ "fragile", "uses_memory", "const_memory" ]
524
	pinned   = "exception"
525
	attrs    = [
526
527
		Attribute("mode", type="ir_mode*",
		          comment="mode of the value to be loaded"),
528
529
                Attribute("type", type="ir_type*",
                          comment="The type of the object which is stored at ptr (need not match with mode)"),
530
531
532
533
534
535
536
537
		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"),
538
539
	]
	attr_struct = "load_attr"
540
	constructor_args = [
541
542
		Attribute("flags", type="ir_cons_flags",
		          comment="specifies alignment, volatility and pin state"),
543
	]
544
	pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
545
	throws_init = "(flags & cons_throws_exception) != 0"
546

Matthias Braun's avatar
Matthias Braun committed
547
@op
548
class Minus(object):
Andreas Seltenreich's avatar
Andreas Seltenreich committed
549
	"""returns the additive inverse of its operand"""
550
551
552
553
	flags  = []
	ins    = [
		("op", "operand")
	]
554

Matthias Braun's avatar
Matthias Braun committed
555
@op
556
class Mod(object):
557
558
559
	"""returns the remainder of its operands from an implied division.

	Examples:
560

561
562
563
564
565
	* mod(5,3)   produces 2
	* mod(5,-3)  produces 2
	* mod(-5,3)  produces -2
	* mod(-5,-3) produces -2
	"""
566
567
568
569
570
	ins   = [
		("mem",   "memory dependency"),
		("left",  "first operand"),
		("right", "second operand"),
	]
571
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
572
		("M",         "memory result"),
573
		("res",       "result of computation"),
Matthias Braun's avatar
Matthias Braun committed
574
575
		("X_regular", "control flow when no exception occurs"),
		("X_except",  "control flow when exception occured"),
576
	]
577
	flags = [ "fragile", "uses_memory", "const_memory" ]
578
	attrs = [
579
		Attribute("resmode", type="ir_mode*", comment="mode of the result"),
580
	]
581
	attr_struct = "mod_attr"
582
	pinned      = "exception"
583
	throws_init = "false"
584
585
	op_index    = 1
	arity_override = "oparity_binary"
Matthias Braun's avatar
Matthias Braun committed
586

587
class Mul(Binop):
588
	"""returns the product of its operands"""
589
590
591
	flags = [ "commutative" ]

class Mulh(Binop):
592
593
	"""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)"""
594
595
	flags = [ "commutative" ]

Matthias Braun's avatar
Matthias Braun committed
596
@op
597
class Mux(object):
598
599
	"""returns the false or true operand depending on the value of the sel
	operand"""
600
601
602
603
604
	ins    = [
	   ("sel",   "value making the output selection"),
	   ("false", "selected if sel input is false"),
	   ("true",  "selected if sel input is true"),
	]
605
606
	flags  = []

Matthias Braun's avatar
Matthias Braun committed
607
@op
608
class NoMem(object):
609
	"""Placeholder node for cases where you don't need any memory input"""
610
	mode          = "mode_M"
611
	flags         = [ "dump_noblock", "start_block" ]
612
613
	pinned        = "yes"
	singleton     = True
614

Matthias Braun's avatar
Matthias Braun committed
615
@op
616
class Not(object):
617
	"""returns the bitwise complement of a value. Works for boolean values, too."""
618
619
620
621
	flags  = []
	ins    = [
		("op", "operand")
	]
622

623
624
625
626
@op
class Offset(EntConst):
	"""Symbolic constant that represents the offset of an entity in its owner type."""

Matthias Braun's avatar
Matthias Braun committed
627
@op
628
class Or(Binop):
629
	"""returns the result of a bitwise or operation of its operands"""
630
631
	flags = [ "commutative" ]

Matthias Braun's avatar
Matthias Braun committed
632
@op
633
class Phi(object):
634
635
636
	"""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."""
637
638
639
640
641
	pinned      = "yes"
	arity       = "variable"
	input_name  = "pred"
	flags       = []
	attrs       = [
642
643
644
		Attribute("loop", type="int", init="0",
		          comment="wether Phi represents the observable effect of a (possibly) nonterminating loop"),
	]
645
646
	attr_struct = "phi_attr"
	init        = '''
647
	res->attr.phi.u.backedge = new_backedge_arr(get_irg_obstack(irg), arity);'''
648
	serializer  = False
649

Matthias Braun's avatar
Matthias Braun committed
650
@op
651
class Pin(object):
652
653
654
	"""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."""
655
656
657
	ins      = [
		("op", "value which is pinned"),
	]
658
	mode     = "get_irn_mode(irn_op)"
Matthias Braun's avatar
Matthias Braun committed
659
	flags    = [ ]
660
661
	pinned   = "yes"

Matthias Braun's avatar
Matthias Braun committed
662
@op
663
class Proj(object):
664
	"""returns an entry of a tuple value"""
665
	ins        = [
666
667
		("pred", "the tuple value from which a part is extracted"),
	]
668
669
	flags      = []
	block      = "get_nodes_block(irn_pred)"
670
	usesGraph  = False
671
	attrs      = [
672
		Attribute("num", type="unsigned",
673
		          comment="number of tuple component to be extracted"),
674
	]
675
	attr_struct = "proj_attr"
676

Matthias Braun's avatar
Matthias Braun committed
677
@op
678
class Raise(object):
679
680
681
	"""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."""
682
683
684
685
	ins    = [
		("mem",     "memory dependency"),
		("exo_ptr", "pointer to exception object to be thrown"),
	]
686
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
687
688
		("M", "memory result"),
		("X", "control flow to exception handler"),
689
	]
Matthias Braun's avatar
Matthias Braun committed
690
	flags  = [ "cfopcode" ]
691
692
	pinned = "yes"

Matthias Braun's avatar
Matthias Braun committed
693
@op
694
class Return(object):
695
696
	"""Returns from the current function. Takes memory and return values as
	operands."""
697
	ins        = [
698
699
		("mem", "memory dependency"),
	]
700
701
702
703
704
	arity      = "variable"
	input_name = "res"
	mode       = "mode_X"
	flags      = [ "cfopcode" ]
	pinned     = "yes"
705

Matthias Braun's avatar
Matthias Braun committed
706
@op
707
class Sel(object):
708
709
	"""Computes the address of an array element from the array base pointer and
	an index.
710

711
712
713
714
715
716
	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  = []
717
	mode   = "mode_P"
718
719
720
721
722
723
724
	attrs  = [
		Attribute("type", type="ir_type*",
		          comment="array type"),
	]
	attr_struct = "sel_attr"

@op
725
class Member(object):
726
727
728
729
730
	"""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 = [
731
732
		("ptr", "pointer to object to select from"),
	]
733
	flags   = []
734
	mode    = "mode_P"
735
	attrs   = [
736
737
		Attribute("entity", type="ir_entity*",
		          comment="entity which is selected"),
738
	]
739
	attr_struct = "member_attr"
740

Matthias Braun's avatar
Matthias Braun committed
741
@op
742
class Shl(Binop):
743
	"""Returns its first operands bits shifted left by the amount of the 2nd
744
745
746
747
	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."""
748
749
	flags = []

Matthias Braun's avatar
Matthias Braun committed
750
@op
751
class Shr(Binop):
752
	"""Returns its first operands bits shifted right by the amount of the 2nd
753
754
755
756
	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."""
757
758
	flags = []

Matthias Braun's avatar
Matthias Braun committed
759
@op
760
class Shrs(Binop):
761
762
	"""Returns its first operands bits shifted right by the amount of the 2nd
	operand. The leftmost bit (usually the sign bit) stays the same
763
764
765
766
	(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."""
767
768
	flags = []

Matthias Braun's avatar
Matthias Braun committed
769
@op
770
class Start(object):
771
	"""The first node of a graph. Execution starts with this node."""
772
	outs = [
773
774
775
776
		("M",              "initial memory"),
		("P_frame_base",   "frame base pointer"),
		("T_args",         "function arguments")
	]
777
778
779
780
	mode      = "mode_T"
	pinned    = "yes"
	flags     = [ "start_block" ]
	singleton = True
781

Matthias Braun's avatar
Matthias Braun committed
782
@op
783
class Store(object):
784
	"""Stores a value into memory (heap or stack)."""
785
786
787
788
789
	ins   = [
	   ("mem",   "memory dependency"),
	   ("ptr",   "address to store to"),
	   ("value", "value to store"),
	]
790
	outs  = [
Matthias Braun's avatar
Matthias Braun committed
791
792
793
		("M",         "memory result"),
		("X_regular", "control flow when no exception occurs"),
		("X_except",  "control flow when exception occured"),
794
	]
795
796
797
798
	flags    = [ "fragile", "uses_memory" ]
	pinned   = "exception"
	attr_struct = "store_attr"
	pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
799
	throws_init = "(flags & cons_throws_exception) != 0"
800
	attrs = [
801
802
                Attribute("type", type="ir_type*",
                          comment="The type of the object which is stored at ptr (need not match with value's type)"),
803
804
805
806
807
808
809
810
		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"),
811
	]
812
	constructor_args = [
813
814
		Attribute("flags", type="ir_cons_flags",
		          comment="specifies alignment, volatility and pin state"),
815
816
	]

Matthias Braun's avatar
Matthias Braun committed
817
@op
818
class Sub(Binop):
819
	"""returns the difference of its operands"""
820
821
	flags = []

822
@op
823
824
class Size(TypeConst):
	"""A symbolic constant that represents the size of a type"""
825

Matthias Braun's avatar
Matthias Braun committed
826
@op
827
class Sync(object):
828
829
830
831
832
	"""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."""
833
834
835
836
	mode       = "mode_M"
	flags      = []
	arity      = "dynamic"
	input_name = "pred"
837

Matthias Braun's avatar
Matthias Braun committed
838
@op
839
class Tuple(object):
840
841
842
843
844
845
846
	"""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
847
	just changing its opcode and giving it a new in array."""
848
849
850
851
	arity      = "variable"
	input_name = "pred"
	mode       = "mode_T"
	flags      = []
852

Matthias Braun's avatar
Matthias Braun committed
853
@op
854
class Unknown(object):
855
	"""Returns an unknown (at compile- and runtime) value. It is a valid
Matthias Braun's avatar
Matthias Braun committed
856
857
	optimization to replace an Unknown by any other constant value.

Matthias Braun's avatar
Matthias Braun committed
858
	Be careful when optimising Unknown values, you cannot simply replace
Matthias Braun's avatar
Matthias Braun committed
859
860
	Unknown+x or Unknown<x with a new Unknown node if there are multiple
	users of the original unknown node!"""
861
	pinned     = "yes"
Matthias Braun's avatar
Matthias Braun committed
862
	flags      = [ "start_block", "constlike", "dump_noblock" ]