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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	Examples:
561

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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