ir_spec.py 26.8 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 Node, abstract, op, Attribute, prepare_nodes
8
from jinjautil import export
9

Matthias Braun's avatar
Matthias Braun committed
10
name = "ir"
11

Matthias Braun's avatar
Matthias Braun committed
12
13
@abstract
@op
14
class Binop(Node):
15
	"""Binary nodes have exactly 2 inputs"""
16
	name     = "binop"
17
	ins      = [
18
19
		("left",   "first operand"),
		("right", "second operand"),
20
	]
21
22
	op_index       = 0
	arity_override = "oparity_binary"
23

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

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

Matthias Braun's avatar
Matthias Braun committed
48
@op
49
class Add(Binop):
50
	"""returns the sum of its operands"""
51
	mode  = "get_irn_mode(mode_is_reference(get_irn_mode(irn_right)) ? irn_right : irn_left)"
52
	flags = [ "commutative" ]
53

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

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

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

Matthias Braun's avatar
Matthias Braun committed
82
@op
83
class Anchor(Node):
84
	"""Utility node used to "hold" nodes in a graph that might possibly not be
85
86
87
	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
88
	known. All other well-known graph-nodes like Start, End, NoMem, ...
89
	are found by looking at the respective Anchor operand."""
90
91
92
93
94
95
96
97
98
99
	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" ),
	]
100
101
102
103
104
	mode        = "mode_ANY"
	flags       = [ "dump_noblock" ]
	pinned      = "yes"
	singleton   = True
	constructor = False
105

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

Matthias Braun's avatar
Matthias Braun committed
112
@op
113
class ASM(Node):
Matthias Braun's avatar
Matthias Braun committed
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
	"""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)
	"""
141
142
143
144
145
146
147
148
149
	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         = [
150
151
		("mem",    "memory dependency"),
	]
152
	attrs       = [
153
154
155
156
157
158
159
160
161
162
163
		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"),
164
165
166
	]
	# constructor is written manually at the moment, because of the clobbers+
	# constraints arrays needing special handling (2 arguments for 1 attribute)
167
	constructor = False
168

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

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

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

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

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

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

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

Matthias Braun's avatar
Matthias Braun committed
255
@op
256
class Call(Node):
257
258
259
260
	"""Calls other code. Control flow is transfered to ptr, additional
	operands are passed to the called code. Called code usually performs a
	return operation. The operands of this return operation are the result
	of the Call node."""
261
	ins         = [
262
263
264
		("mem",   "memory dependency"),
		("ptr",   "pointer to called code"),
	]
265
266
267
	arity       = "variable"
	input_name  = "param"
	outs        = [
Matthias Braun's avatar
Matthias Braun committed
268
		("M",                "memory result"),
269
		("T_result",         "tuple containing all results"),
Matthias Braun's avatar
Matthias Braun committed
270
271
		("X_regular",        "control flow when no exception occurs"),
		("X_except",         "control flow when exception occured"),
272
	]
273
274
	flags       = [ "fragile", "uses_memory" ]
	attrs       = [
275
276
		Attribute("type", type="ir_type*",
		          comment="type of the call (usually type of the called procedure)"),
277
278
	]
	attr_struct = "call_attr"
279
	pinned      = "exception"
280
	pinned_init = "op_pin_state_pinned"
281
	throws_init = "false"
282
283
	init = '''
	assert((get_unknown_type() == type) || is_Method_type(type));
284
	'''
285

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

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

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

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

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

Matthias Braun's avatar
Matthias Braun committed
376
@op
377
class Conv(Node):
378
	"""Converts values between modes"""
379
380
381
382
	flags  = []
	ins    = [
		("op", "operand")
	]
383

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

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

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

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

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

	This is also known as the Xor operation."""
468
469
	mode  = "get_irn_mode(irn_left)"
	flags = [ "commutative" ]
470

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

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

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

Matthias Braun's avatar
Matthias Braun committed
506
@op
507
class Jmp(Node):
508
	"""Jumps to the block connected through the out-value"""
509
510
511
512
513
	mode     = "mode_X"
	pinned   = "yes"
	ins      = []
	flags    = [ "cfopcode" ]

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

Matthias Braun's avatar
Matthias Braun committed
551
@op
552
class Minus(Node):
Andreas Seltenreich's avatar
Andreas Seltenreich committed
553
	"""returns the additive inverse of its operand"""
554
	mode   = "get_irn_mode(irn_op)"
555
556
557
558
	flags  = []
	ins    = [
		("op", "operand")
	]
559

Matthias Braun's avatar
Matthias Braun committed
560
@op
561
class Mod(Node):
562
563
564
	"""returns the remainder of its operands from an implied division.

	Examples:
565

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

592
class Mul(Binop):
593
	"""returns the product of its operands"""
594
	mode  = "get_irn_mode(irn_left)"
595
596
597
	flags = [ "commutative" ]

class Mulh(Binop):
598
599
	"""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)"""
600
	mode  = "get_irn_mode(irn_left)"
601
602
	flags = [ "commutative" ]

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

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

Matthias Braun's avatar
Matthias Braun committed
623
@op
624
class Not(Node):
625
	"""returns the bitwise complement of a value. Works for boolean values, too."""
626
	mode   = "get_irn_mode(irn_op)"
627
628
629
630
	flags  = []
	ins    = [
		("op", "operand")
	]
631

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

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

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

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

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

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

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

Matthias Braun's avatar
Matthias Braun committed
716
@op
717
class Sel(Node):
718
719
	"""Computes the address of an array element from the array base pointer and
	an index.
720

721
722
723
724
725
726
	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  = []
727
	mode   = "mode_P"
728
729
730
731
732
733
734
	attrs  = [
		Attribute("type", type="ir_type*",
		          comment="array type"),
	]
	attr_struct = "sel_attr"

@op
735
class Member(Node):
736
737
738
739
740
	"""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 = [
741
742
		("ptr", "pointer to object to select from"),
	]
743
	flags   = []
744
	mode    = "mode_P"
745
	attrs   = [
746
747
		Attribute("entity", type="ir_entity*",
		          comment="entity which is selected"),
748
	]
749
	attr_struct = "member_attr"
750

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

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

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

Matthias Braun's avatar
Matthias Braun committed
782
@op
783
class Start(Node):
784
	"""The first node of a graph. Execution starts with this node."""
785
	outs = [
786
787
788
789
		("M",              "initial memory"),
		("P_frame_base",   "frame base pointer"),
		("T_args",         "function arguments")
	]
790
791
792
793
	mode      = "mode_T"
	pinned    = "yes"
	flags     = [ "start_block" ]
	singleton = True
794

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

Matthias Braun's avatar
Matthias Braun committed
830
@op
831
class Sub(Binop):
832
	"""returns the difference of its operands"""
833
	mode  = "mode_is_reference(get_irn_mode(irn_right)) ? get_reference_offset_mode(get_irn_mode(irn_left)) : get_irn_mode(irn_left)"
834
835
	flags = []

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

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

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

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

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

(nodes, abstract_nodes) = prepare_nodes(globals())
export(nodes, "nodes")
export(abstract_nodes, "abstract_nodes")
export(globals(), "spec")