ir_spec.py 25.5 KB
Newer Older
1
2
3
from spec_util import abstract, setnodedefaults

class Op(object):
4
	"""Base class for firm nodes"""
5
6
7
abstract(Op)

class Unop(Op):
8
	"""Unary nodes have exactly 1 input"""
9
10
11
12
13
14
15
	name     = "unop"
	ins      = [ "op" ]
	op_index = 0
	pinned   = "no"
abstract(Unop)

class Binop(Op):
16
	"""Binary nodes have exactly 2 inputs"""
17
18
19
20
21
22
23
	name     = "binop"
	ins      = [ "left", "right" ]
	op_index = 0
	pinned   = "no"
abstract(Binop)

class Add(Binop):
24
	"""returns the sum of its operands"""
25
26
27
	flags = ["commutative"]

class Alloc(Op):
28
29
30
	"""allocates a block of memory.
	It can be specified whether the variable should be allocated to the stack
	or to the heap."""
31
	ins   = [ "mem", "count" ]
32
33
34
35
36
37
	outs  = [
		("M",         "memory result",                         "pn_Generic_M"),
		("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
		("X_except",  "control flow when exception occured",   "pn_Generic_X_except"),
		("res",       "pointer to newly allocated memory",     "pn_Generic_other"),
	]
38
	flags = [ "fragile", "uses_memory" ]
39
40
41
42
43
44
45
46
47
	attrs = [
		dict(
			name = "type",
			type = "ir_type*"
		),
		dict(
			name = "where",
			type = "ir_where_alloc"
		)
48
49
50
51
52
	]
	pinned      = "yes"
	attr_struct = "alloc_attr"

class Anchor(Op):
53
54
55
56
57
58
	"""utiliy node used to "hold" nodes in a graph that might possibly not be
	reachable by other means or which should be reachable immediately without
	searching through the graph.
	Each firm-graph contains exactly one anchor node whose address is always
	known. All other well-known graph-nodes like Start, End, NoMem, Bad, ...
	are found by looking at the respective Anchor operand."""
59
60
61
62
63
64
65
66
67
	mode             = "mode_ANY"
	arity            = "variable"
	flags            = [ "dump_noblock" ]
	pinned           = "yes"
	attr_struct      = "irg_attr"
	knownBlock       = True
	singleton        = True
	noconstructor    = True
	customSerializer = True
68
69

class And(Binop):
70
	"""returns the result of a bitwise and operation of its operands"""
71
72
73
	flags    = [ "commutative" ]

class ASM(Op):
74
	"""executes assembler fragments of the target machine"""
75
76
77
78
79
80
81
82
	mode             = "mode_T"
	arity            = "variable"
	flags            = [ "keep", "uses_memory" ]
	pinned           = "memory"
	pinned_init      = "op_pin_state_pinned"
	attr_struct      = "asm_attr"
	attrs_name       = "assem"
	customSerializer = True
83
84

class Bad(Op):
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
	"""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).
	Optimisations also set block predecessors to Bad when it becomes clear,
	that a control flow edge can never be executed.

	The gigo optimisations ensures that nodes with Bad as their block, get
	replaced by Bad themselfes. Nodes with at least 1 Bad input get exchanged
	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
	optimisation phase. Block, Phi, Tuple with only Bad inputs however are
	replaced by Bad right away."""
102
	mode          = "mode_T"
103
104
105
	flags         = [ "cfopcode", "start_block", "dump_noblock" ]
	pinned        = "yes"
	knownBlock    = True
106
	block         = "get_irg_start_block(irg)"
107
108
	singleton     = True
	attr_struct   = "bad_attr"
109
	init = '''
110
	res->attr.bad.irg.irg = irg;
111
112
	'''

113
class Deleted(Op):
114
115
	"""Internal node which is temporary set to nodes which are already removed
	from the graph."""
116
117
118
119
120
	mode             = "mode_Bad"
	flags            = [ ]
	pinned           = "yes"
	noconstructor    = True
	customSerializer = True
121

122
class Block(Op):
123
	"""A basic block"""
124
125
126
127
128
129
130
131
	mode             = "mode_BB"
	knownBlock       = True
	block            = "NULL"
	pinned           = "yes"
	arity            = "variable"
	flags            = [ "labeled" ]
	attr_struct      = "block_attr"
	customSerializer = True
Moritz Kroll's avatar
Moritz Kroll committed
132
133

	init = '''
134
	res->attr.block.irg.irg     = irg;
Moritz Kroll's avatar
Moritz Kroll committed
135
136
	res->attr.block.backedge    = new_backedge_arr(irg->obst, arity);
	set_Block_matured(res, 1);
137
138

	/* Create and initialize array for Phi-node construction. */
139
140
141
	if (get_irg_phase_state(irg) == phase_building) {
		res->attr.block.graph_arr = NEW_ARR_D(ir_node *, irg->obst, irg->n_loc);
		memset(res->attr.block.graph_arr, 0, irg->n_loc * sizeof(ir_node*));
142
	}
143
	'''
144

145
class Borrow(Binop):
146
	"""Returns the borrow bit from and implied subtractions of its 2 operands"""
147
148
	flags = []

149
class Bound(Op):
150
151
	"""Performs a bounds-check: if lower <= index < upper then return index,
	otherwise throw an exception."""
152
	ins    = [ "mem", "index", "lower", "upper" ]
153
154
155
156
157
158
	outs  = [
		("M",         "memory result",                         "pn_Generic_M"),
		("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
		("X_except",  "control flow when exception occured",   "pn_Generic_X_except"),
		("res",       "the checked index",                     "pn_Generic_other"),
	]
159
160
161
162
 	flags  = [ "fragile", "highlevel" ]
	pinned = "exception"
	pinned_init = "op_pin_state_pinned"
	attr_struct = "bound_attr"
163
	attrs_name  = "bound"
164
165

class Builtin(Op):
166
	"""performs a backend-specific builtin."""
167
168
	ins      = [ "mem" ]
	arity    = "variable"
169
170
171
172
	outs     = [
		("M",        "memory result", "pn_Generic_M"),
		("1_result", "first result",  "pn_Generic_other"),
	]
173
	flags    = [ "uses_memory" ]
174
	attrs    = [
175
176
177
178
		dict(
			type = "ir_builtin_kind",
			name = "kind"
		),
179
		dict(
180
181
182
			type = "ir_type*",
			name = "type"
		)
183
184
185
186
	]
	pinned      = "memory"
	pinned_init = "op_pin_state_pinned"
	attr_struct = "builtin_attr"
187
	init   = '''
188
189
190
	assert((get_unknown_type() == type) || is_Method_type(type));
	'''

191
class Call(Op):
192
193
194
195
	"""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."""
196
197
	ins      = [ "mem", "ptr" ]
	arity    = "variable"
198
199
200
201
202
203
204
	outs     = [
		("M",                "memory result",                         "pn_Generic_M"),
		("X_regular",        "control flow when no exception occurs", "pn_Generic_X_regular"),
		("X_except",         "control flow when exception occured",   "pn_Generic_X_except"),
		("T_result",         "tuple containing all results",          "pn_Generic_other"),
		("P_value_res_base", "pointer to memory register containing copied results passed by value"),
	]
205
	flags    = [ "fragile", "uses_memory" ]
206
	attrs    = [
207
208
209
		dict(
			type = "ir_type*",
			name = "type"
210
211
212
213
214
215
		),
		dict(
			type = "unsigned",
			name = "tail_call",
			# the tail call attribute can only be set by analysis
			init = "0"
216
		)
217
218
219
220
	]
	attr_struct = "call_attr"
	pinned      = "memory"
	pinned_init = "op_pin_state_pinned"
221
222
	init = '''
	assert((get_unknown_type() == type) || is_Method_type(type));
223
	'''
224

225
class Carry(Binop):
226
227
	"""Computes the value of the carry-bit that would result when adding the 2
	operands"""
228
229
	flags = [ "commutative" ]

Michael Beck's avatar
Michael Beck committed
230
class Cast(Unop):
231
	"""perform a high-level type cast"""
232
233
	mode     = "get_irn_mode(irn_op)"
	flags    = [ "highlevel" ]
234
235
236
237
238
	attrs    = [
		dict(
			type = "ir_type*",
			name = "type"
		)
239
240
	]
	attr_struct = "cast_attr"
241
	init     = "assert(is_atomic_type(type));"
242
243

class Cmp(Binop):
244
	"""Returns the relation of 2 operands"""
245
	outs  = [
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
		("False", "always false",                            "0"),
		("Eq",    "equal",                                   "1"),
		("Lt",    "less",                                    "2"),
		("Le",    "less or equal",                           "pn_Cmp_Eq|pn_Cmp_Lt"),
		("Gt",    "greater",                                 "4"),
		("Ge",    "greater or equal",                        "pn_Cmp_Eq|pn_Cmp_Gt"),
		("Lg",    "less or greater ('not equal' for integer numbers)", "pn_Cmp_Lt|pn_Cmp_Gt"),
		("Leg",   "less, equal or greater ('not unordered')", "pn_Cmp_Lt|pn_Cmp_Eq|pn_Cmp_Gt"),
		("Uo",    "unordered",                               "8"),
		("Ue",    "unordered or equal",                      "pn_Cmp_Uo|pn_Cmp_Eq"),
		("Ul",    "unordered or less",                       "pn_Cmp_Uo|pn_Cmp_Lt"),
		("Ule",   "unordered, less or equal",                "pn_Cmp_Uo|pn_Cmp_Lt|pn_Cmp_Eq"),
		("Ug",    "unordered or greater",                    "pn_Cmp_Uo|pn_Cmp_Gt"),
		("Uge",   "onordered, greater or equal",             "pn_Cmp_Uo|pn_Cmp_Gt|pn_Cmp_Eq"),
		("Ne",    "unordered, less or greater ('not equal' for floatingpoint numbers)", "pn_Cmp_Uo|pn_Cmp_Lt|pn_Cmp_Gt"),
		("True",  "always true",                             "15"),
262
	]
263
264
265
	flags = []

class Cond(Op):
266
267
268
269
270
271
272
273
274
275
276
277
278
	"""Conditionally change control flow. There are two versions of this node:

	Boolean Cond:
	Input:  A value of mode_b
	Output: A tuple of two control flows. The first is taken if the input is
	        false, the second if it is true.

	Switch Cond:
	Input:  A value of mode_Iu
	Output: A tuple of n control flows. If the Cond's input is i, control flow
	will proceed along output i. If the input is >= n control flow proceeds
	along output def_proj.
	"""
279
	ins      = [ "selector" ]
280
281
282
283
	outs     = [
		("false", "control flow if operand is \"false\""),
		("true",  "control flow if operand is \"true\""),
	]
284
285
	flags    = [ "cfopcode", "forking" ]
	pinned   = "yes"
286
287
288
289
290
291
292
293
294
295
296
	attrs    = [
		dict(
			name = "default_proj",
			type = "long",
			init = "0"
		),
		dict(
			name = "jmp_pred",
			type = "cond_jmp_predicate",
			init = "COND_JMP_PRED_NONE"
		)
297
	]
298
	attr_struct = "cond_attr"
299

300
class Confirm(Op):
301
302
303
304
305
306
307
308
309
	"""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."""
310
311
312
313
	ins      = [ "value", "bound" ]
	mode     = "get_irn_mode(irn_value)"
	flags    = [ "highlevel" ]
	pinned   = "yes"
314
315
316
317
318
	attrs    = [
		dict(
			name = "cmp",
			type = "pn_Cmp"
		),
319
320
	]
	attr_struct = "confirm_attr"
321
	attrs_name  = "confirm"
322
323

class Const(Op):
324
	"""Returns a constant value."""
325
326
327
328
329
	mode       = ""
	flags      = [ "constlike", "start_block" ]
	knownBlock = True
	pinned     = "no"
	attrs_name = "con"
330
331
	attrs      = [
		dict(
Matthias Braun's avatar
Matthias Braun committed
332
			type = "ir_tarval*",
333
334
			name = "tarval",
		)
335
336
	]
	attr_struct = "const_attr"
337

338
class Conv(Unop):
339
	"""Converts values between modes"""
340
	flags = []
341
342
343
344
345
346
	attrs = [
		dict(
			name = "strict",
			type = "int",
			init = "0",
		)
347
348
	]
	attr_struct = "conv_attr"
349
	attrs_name  = "conv"
350
351

class CopyB(Op):
352
	"""Copies a block of memory"""
353
	ins   = [ "mem", "dst", "src" ]
354
355
356
357
358
	outs  = [
		("M",         "memory result",                         "pn_Generic_M"),
		("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
		("X_except",  "control flow when exception occured",   "pn_Generic_X_except"),
	]
359
	flags = [ "fragile", "uses_memory" ]
360
361
	attrs = [
		dict(
362
363
			name = "type",
			type = "ir_type*"
364
		)
365
366
	]
	attr_struct = "copyb_attr"
367
	attrs_name  = "copyb"
368
369
	pinned      = "memory"
	pinned_init = "op_pin_state_pinned"
370

371
class Div(Op):
372
	"""returns the quotient of its 2 operands, integer version"""
373
	ins   = [ "mem", "left", "right" ]
374
375
376
377
378
379
	outs  = [
		("M",         "memory result",                         "pn_Generic_M"),
		("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
		("X_except",  "control flow when exception occured",   "pn_Generic_X_except"),
		("res",       "result of computation",                 "pn_Generic_other"),
	]
380
381
	flags = [ "fragile", "uses_memory" ]
	attrs_name = "divmod"
382
383
384
385
386
	attrs = [
		dict(
			type = "ir_mode*",
			name = "resmode"
		),
Moritz Kroll's avatar
Moritz Kroll committed
387
388
389
390
		dict(
			name = "no_remainder",
			type = "int",
			init = "0",
391
		)
392
393
394
395
396
	]
	attr_struct = "divmod_attr"
	pinned      = "exception"
	op_index    = 1
	arity_override = "oparity_binary"
397

398
class DivMod(Op):
399
	"""divides its 2 operands and computes the remainder of the division"""
400
	ins   = [ "mem", "left", "right" ]
401
402
403
404
405
406
407
	outs  = [
		("M",         "memory result",                         "pn_Generic_M"),
		("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
		("X_except",  "control flow when exception occured",   "pn_Generic_X_except"),
		("res_div",   "result of computation a/b",             "pn_Generic_other"),
		("res_mod",   "result of computation a%b"),
	]
408
409
	flags = [ "fragile", "uses_memory" ]
	attrs_name = "divmod"
410
411
412
413
414
	attrs = [
		dict(
			type = "ir_mode*",
			name = "resmode"
		),
415
416
417
418
419
420
421
	]
	attr_struct = "divmod_attr"
	pinned      = "exception"
	op_index    = 1
	arity_override = "oparity_binary"

class Dummy(Op):
422
423
424
	"""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."""
425
426
	ins        = []
	flags      = [ "cfopcode", "start_block", "constlike", "dump_noblock" ]
427
428
429
430
431
	knownBlock = True
	pinned     = "yes"
	block      = "get_irg_start_block(irg)"

class End(Op):
432
433
	"""Last node of a graph. It references nodes in endless loops (so called
	keepalive edges)"""
434
435
436
437
438
439
440
441
	mode             = "mode_X"
	pinned           = "yes"
	arity            = "dynamic"
	flags            = [ "cfopcode" ]
	knownBlock       = True
	block            = "get_irg_end_block(irg)"
	singleton        = True
	customSerializer = True
442
443

class Eor(Binop):
444
	"""returns the result of a bitwise exclusive or operation of its operands"""
445
	flags    = [ "commutative" ]
446

447
class Free(Op):
448
	"""Frees a block of memory previously allocated by an Alloc node"""
449
450
451
452
	ins    = [ "mem", "ptr", "size" ]
	mode   = "mode_M"
	flags  = [ "uses_memory" ]
	pinned = "yes"
453
	attrs  = [
454
		dict(
455
456
			name = "type",
			type = "ir_type*"
457
458
		),
		dict(
459
460
			name = "where",
			type = "ir_where_alloc"
461
		)
462
463
464
465
	]
	attr_struct = "free_attr"

class Id(Op):
466
	"""Returns its operand unchanged."""
467
468
469
470
471
	ins    = [ "pred" ]
	pinned = "no"
	flags  = []

class IJmp(Op):
472
473
474
	"""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"""
475
476
477
478
479
480
	mode     = "mode_X"
	pinned   = "yes"
	ins      = [ "target" ]
	flags    = [ "cfopcode", "forking", "keep" ]

class InstOf(Op):
481
	"""Tests wether an object is an instance of a class-type"""
482
	ins   = [ "store", "obj" ]
483
484
485
486
487
488
	outs  = [
		("M",         "memory result",                         "pn_Generic_M"),
		("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
		("X_except",  "control flow when exception occured",   "pn_Generic_X_except"),
		("res",       "checked object pointer",                "pn_Generic_other"),
	]
489
	flags = [ "highlevel" ]
490
491
492
493
494
	attrs = [
		dict(
			name = "type",
			type = "ir_type*"
		)
495
496
497
498
499
500
	]
	attr_struct = "io_attr"
	pinned      = "memory"
	pinned_init = "op_pin_state_floats"

class Jmp(Op):
501
	"""Jumps to the block connected through the out-value"""
502
503
504
505
506
507
	mode     = "mode_X"
	pinned   = "yes"
	ins      = []
	flags    = [ "cfopcode" ]

class Load(Op):
508
	"""Loads a value from memory (heap or stack)."""
509
	ins      = [ "mem", "ptr" ]
510
511
512
513
514
515
	outs  = [
		("M",         "memory result",                         "pn_Generic_M"),
		("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
		("X_except",  "control flow when exception occured",   "pn_Generic_X_except"),
		("res",       "result of load operation",              "pn_Generic_other"),
	]
516
517
518
	flags    = [ "fragile", "uses_memory" ]
	pinned   = "exception"
	pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
519
520
521
522
523
524
	attrs    = [
		dict(
			type = "ir_mode*",
			name = "mode",
			java_name = "load_mode"
		),
525
526
	]
	attr_struct = "load_attr"
527
528
	constructor_args = [
		dict(
Moritz Kroll's avatar
Moritz Kroll committed
529
			type = "ir_cons_flags",
530
531
			name = "flags",
		),
532
	]
533
534
535
536
	init = '''
	res->attr.load.volatility = flags & cons_volatile ? volatility_is_volatile : volatility_non_volatile;
	res->attr.load.aligned = flags & cons_unaligned ? align_non_aligned : align_is_aligned;
	'''
537
538

class Minus(Unop):
539
	"""returns the difference between its operands"""
540
541
542
	flags = []

class Mod(Op):
543
544
545
546
547
548
549
550
	"""returns the remainder of its operands from an implied division.

	Examples:
	* mod(5,3)   produces 2
	* mod(5,-3)  produces 2
	* mod(-5,3)  produces -2
	* mod(-5,-3) produces -2
	"""
551
	ins   = [ "mem", "left", "right" ]
552
553
554
555
556
557
	outs  = [
		("M",         "memory result",                         "pn_Generic_M"),
		("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
		("X_except",  "control flow when exception occured",   "pn_Generic_X_except"),
		("res",       "result of computation",                 "pn_Generic_other"),
	]
558
559
	flags = [ "fragile", "uses_memory" ]
	attrs_name = "divmod"
560
	attrs = [
561
		dict(
562
563
			type = "ir_mode*",
			name = "resmode"
564
		),
565
566
567
568
569
	]
	attr_struct = "divmod_attr"
	pinned      = "exception"
	op_index    = 1
	arity_override = "oparity_binary"
Matthias Braun's avatar
Matthias Braun committed
570

571
class Mul(Binop):
572
	"""returns the product of its operands"""
573
574
575
	flags = [ "commutative" ]

class Mulh(Binop):
576
577
	"""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)"""
578
579
580
	flags = [ "commutative" ]

class Mux(Op):
581
582
	"""returns the false or true operand depending on the value of the sel
	operand"""
583
584
585
586
587
	ins    = [ "sel", "false", "true" ]
	flags  = []
	pinned = "no"

class NoMem(Op):
588
	"""Placeholder node for cases where you don't need any memory input"""
589
590
591
592
	mode          = "mode_M"
	flags         = [ "dump_noblock", "dump_noinput" ]
	pinned        = "yes"
	knownBlock    = True
593
	block         = "get_irg_start_block(irg)"
594
	singleton     = True
595
596

class Not(Unop):
597
598
599
	"""returns the logical complement of a value. Works for integer values too.
	If the input is false/zero then true/one is returned, otherwise false/zero
	is returned."""
600
601
602
	flags = []

class Or(Binop):
603
	"""returns the result of a bitwise or operation of its operands"""
604
605
606
	flags = [ "commutative" ]

class Phi(Op):
607
608
609
	"""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."""
610
611
612
613
	pinned        = "yes"
	arity         = "variable"
	flags         = []
	attr_struct   = "phi_attr"
Matthias Braun's avatar
Matthias Braun committed
614
615
616
617
618
619
	init = '''
	/* Memory Phis in endless loops must be kept alive.
	   As we can't distinguish these easily we keep all of them alive. */
   	if (is_Phi(res) && mode == mode_M)
		add_End_keepalive(get_irg_end(irg), res);
	'''
620
621

class Pin(Op):
622
623
624
	"""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."""
625
626
627
628
629
630
	ins      = [ "op" ]
	mode     = "get_irn_mode(irn_op)"
	flags    = [ "highlevel" ]
	pinned   = "yes"

class Proj(Op):
631
	"""returns an entry of a tuple value"""
632
633
634
635
636
637
638
639
	ins              = [ "pred" ]
	flags            = []
	pinned           = "no"
	knownBlock       = True
	knownGraph       = True
	block            = "get_nodes_block(irn_pred)"
	graph            = "get_irn_irg(irn_pred)"
	customSerializer = True
640
	attrs      = [
641
642
		dict(
			type = "long",
643
			name = "proj",
644
		),
645
	]
646
	attr_struct = "proj_attr"
647
648

class Quot(Op):
649
	"""returns the quotient of its 2 operands, floatingpoint version"""
650
	ins   = [ "mem", "left", "right" ]
651
652
653
654
655
656
	outs  = [
		("M",         "memory result",                         "pn_Generic_M"),
		("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
		("X_except",  "control flow when exception occured",   "pn_Generic_X_except"),
		("res",       "result of computation",                 "pn_Generic_other"),
	]
657
658
	flags = [ "fragile", "uses_memory" ]
	attrs_name = "divmod"
659
	attrs = [
660
		dict(
661
662
663
			type = "ir_mode*",
			name = "resmode"
		),
664
665
666
667
668
669
670
	]
	attr_struct = "divmod_attr"
	pinned      = "exception"
	op_index    = 1
	arity_override = "oparity_binary"

class Raise(Op):
671
672
673
	"""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."""
674
	ins    = [ "mem", "exo_ptr" ]
675
676
677
678
	outs  = [
		("M", "memory result",                     "pn_Generic_M"),
		("X", "control flow to exception handler", "pn_Generic_X_regular"),
	]
679
680
681
682
	flags  = [ "highlevel", "cfopcode" ]
	pinned = "yes"

class Return(Op):
683
684
	"""Returns from the current function. Takes memory and return values as
	operands."""
685
686
687
688
689
690
691
	ins      = [ "mem" ]
	arity    = "variable"
	mode     = "mode_X"
	flags    = [ "cfopcode" ]
	pinned   = "yes"

class Rotl(Binop):
692
693
	"""Returns its first operand bits rotated left by the amount in the 2nd
	operand"""
694
695
696
	flags    = []

class Sel(Op):
697
698
	"""Computes the address of a entity of a compound type given the base
	address of an instance of the compound type."""
699
700
701
702
703
	ins    = [ "mem", "ptr" ]
	arity  = "variable"
	flags  = []
	mode   = "is_Method_type(get_entity_type(entity)) ? mode_P_code : mode_P_data"
	pinned = "no"
704
	attrs  = [
705
		dict(
706
707
708
			type = "ir_entity*",
			name = "entity"
		)
709
710
711
712
	]
	attr_struct = "sel_attr"

class Shl(Binop):
713
714
	"""Returns its first operands bits shifted left by the amount of the 2nd
	operand"""
715
716
717
	flags = []

class Shr(Binop):
718
719
	"""Returns its first operands bits shifted right by the amount of the 2nd
	operand. No special handling for the sign bit (zero extension)"""
720
721
722
	flags = []

class Shrs(Binop):
723
724
725
	"""Returns its first operands bits shifted right by the amount of the 2nd
	operand. The leftmost bit (usually the sign bit) stays the same
	(sign extension)"""
726
727
728
	flags = []

class Start(Op):
729
	"""The first node of a graph. Execution starts with this node."""
730
731
732
733
734
735
736
	outs       = [
		("X_initial_exec", "control flow"),
		("M",              "initial memory"),
		("P_frame_base",   "frame base pointer"),
		("P_tls",          "pointer to thread local storage segment"),
		("T_args",         "function arguments")
	]
737
738
739
740
741
742
743
	mode             = "mode_T"
	pinned           = "yes"
	flags            = [ "cfopcode" ]
	singleton        = True
	knownBlock       = True
	customSerializer = True
	block            = "get_irg_start_block(irg)"
744
745

class Store(Op):
746
	"""Stores a value into memory (heap or stack)."""
747
	ins      = [ "mem", "ptr", "value" ]
748
749
750
751
752
	outs  = [
		("M",         "memory result",                         "pn_Generic_M"),
		("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
		("X_except",  "control flow when exception occured",   "pn_Generic_X_except"),
	]
753
754
755
756
	flags    = [ "fragile", "uses_memory" ]
	pinned   = "exception"
	attr_struct = "store_attr"
	pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
757
	constructor_args = [
758
		dict(
759
760
			type = "ir_cons_flags",
			name = "flags",
761
		),
762
	]
763
764
765
766
	init = '''
	res->attr.store.volatility = flags & cons_volatile ? volatility_is_volatile : volatility_non_volatile;
	res->attr.store.aligned = flags & cons_unaligned ? align_non_aligned : align_is_aligned;
	'''
767
768

class Sub(Binop):
769
	"""returns the difference of its operands"""
770
771
772
	flags = []

class SymConst(Op):
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
	"""A symbolic constant.

	 - symconst_type_tag   The symbolic constant represents a type tag.  The
	                       type the tag stands for is given explicitly.
	 - symconst_type_size  The symbolic constant represents the size of a type.
	                       The type of which the constant represents the size
	                       is given explicitly.
	 - symconst_type_align The symbolic constant represents the alignment of a
	                       type.  The type of which the constant represents the
	                       size is given explicitly.
	 - symconst_addr_ent   The symbolic constant represents the address of an
	                       entity (variable or method).  The variable is given
	                       explicitly by a firm entity.
	 - symconst_ofs_ent    The symbolic constant represents the offset of an
	                       entity in its owner type.
	 - symconst_enum_const The symbolic constant is a enumeration constant of
	                       an enumeration type."""
790
791
792
793
	mode       = "mode_P"
	flags      = [ "constlike", "start_block" ]
	knownBlock = True
	pinned     = "no"
794
	attrs      = [
795
		dict(
796
			type = "ir_entity*",
797
798
			name = "entity",
			noprop = True
799
		)
800
801
	]
	attr_struct = "symconst_attr"
802
	customSerializer = True
803
804

class Sync(Op):
805
806
807
808
809
	"""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."""
810
811
812
	mode     = "mode_M"
	flags    = []
	pinned   = "no"
813
	arity    = "dynamic"
814

815
class Tuple(Op):
816
817
818
819
820
821
822
823
	"""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
	just changing it's opcode and giving it a new in array."""
824
825
826
827
828
829
	arity  = "variable"
	mode   = "mode_T"
	pinned = "no"
	flags  = [ "labeled" ]

class Unknown(Op):
830
831
	"""Returns an unknown (at compile- and runtime) value. It is a valid
	optimisation to replace an Unknown by any other constant value."""
832
833
834
	knownBlock = True
	pinned     = "yes"
	block      = "get_irg_start_block(irg)"
835
	flags      = [ "cfopcode", "start_block", "constlike", "dump_noblock" ]
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851

# Prepare node list

def getOpList(namespace):
	nodes = []
	for t in namespace.values():
		if type(t) != type:
			continue

		if issubclass(t, Op):
			setnodedefaults(t)
			nodes.append(t)
	return nodes

nodes = getOpList(globals())
nodes = sorted(nodes, lambda x,y: cmp(x.name, y.name))