ir_spec.py 26.6 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
	flags = [ "commutative" ]
52

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

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

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

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

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

Matthias Braun's avatar
Matthias Braun committed
111
@op
112
class ASM(Node):
Matthias Braun's avatar
Matthias Braun committed
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
138
139
	"""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)
	"""
140
141
142
143
144
145
146
147
148
	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         = [
149
150
		("mem",    "memory dependency"),
	]
151
	attrs       = [
152
153
154
155
156
157
158
159
160
161
162
		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"),
163
164
165
	]
	# constructor is written manually at the moment, because of the clobbers+
	# constraints arrays needing special handling (2 arguments for 1 attribute)
166
	constructor = False
167

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	Examples:
564

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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