ir_spec.py 26.3 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
	attrs = [
		dict(
			name = "input_constraints",
			type = "ir_asm_constraint*",
		),
		dict(
			name = "n_output_constraints",
			type = "int",
			noprop = True,
		),
		dict(
			name = "output_constraints",
			type = "ir_asm_constraint*",
		),
		dict(
			name = "n_clobbers",
			type = "int",
			noprop = True,
		),
		dict(
			name = "clobbers",
			type = "ident**",
		),
		dict(
			name = "text",
			type = "ident*",
		),
	]
	# constructor is written manually at the moment, because of the clobbers+
	# constraints arrays needing special handling (2 arguments for 1 attribute)
	noconstructor = True
114
115

class Bad(Op):
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
	"""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."""
133
	mode          = "mode_T"
134
135
136
	flags         = [ "cfopcode", "start_block", "dump_noblock" ]
	pinned        = "yes"
	knownBlock    = True
137
	block         = "get_irg_start_block(irg)"
138
139
	singleton     = True
	attr_struct   = "bad_attr"
140
	init = '''
141
	res->attr.bad.irg.irg = irg;
142
143
	'''

144
class Deleted(Op):
145
146
	"""Internal node which is temporary set to nodes which are already removed
	from the graph."""
147
148
149
150
151
	mode             = "mode_Bad"
	flags            = [ ]
	pinned           = "yes"
	noconstructor    = True
	customSerializer = True
152

153
class Block(Op):
154
	"""A basic block"""
155
156
157
158
159
160
161
162
	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
163
164

	init = '''
165
	res->attr.block.irg.irg     = irg;
Moritz Kroll's avatar
Moritz Kroll committed
166
167
	res->attr.block.backedge    = new_backedge_arr(irg->obst, arity);
	set_Block_matured(res, 1);
168
169

	/* Create and initialize array for Phi-node construction. */
170
171
172
	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*));
173
	}
174
	'''
175

176
class Borrow(Binop):
177
	"""Returns the borrow bit from and implied subtractions of its 2 operands"""
178
179
	flags = []

180
class Bound(Op):
181
182
	"""Performs a bounds-check: if lower <= index < upper then return index,
	otherwise throw an exception."""
183
	ins    = [ "mem", "index", "lower", "upper" ]
184
185
186
187
188
189
	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"),
	]
190
191
192
193
 	flags  = [ "fragile", "highlevel" ]
	pinned = "exception"
	pinned_init = "op_pin_state_pinned"
	attr_struct = "bound_attr"
194
	attrs_name  = "bound"
195
196

class Builtin(Op):
197
	"""performs a backend-specific builtin."""
198
199
	ins      = [ "mem" ]
	arity    = "variable"
200
201
202
203
	outs     = [
		("M",        "memory result", "pn_Generic_M"),
		("1_result", "first result",  "pn_Generic_other"),
	]
204
	flags    = [ "uses_memory" ]
205
	attrs    = [
206
207
208
209
		dict(
			type = "ir_builtin_kind",
			name = "kind"
		),
210
		dict(
211
212
213
			type = "ir_type*",
			name = "type"
		)
214
215
216
217
	]
	pinned      = "memory"
	pinned_init = "op_pin_state_pinned"
	attr_struct = "builtin_attr"
218
	init   = '''
219
220
221
	assert((get_unknown_type() == type) || is_Method_type(type));
	'''

222
class Call(Op):
223
224
225
226
	"""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."""
227
228
	ins      = [ "mem", "ptr" ]
	arity    = "variable"
229
230
231
232
233
234
235
	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"),
	]
236
	flags    = [ "fragile", "uses_memory" ]
237
	attrs    = [
238
239
240
		dict(
			type = "ir_type*",
			name = "type"
241
242
243
244
245
246
		),
		dict(
			type = "unsigned",
			name = "tail_call",
			# the tail call attribute can only be set by analysis
			init = "0"
247
		)
248
249
250
251
	]
	attr_struct = "call_attr"
	pinned      = "memory"
	pinned_init = "op_pin_state_pinned"
252
253
	init = '''
	assert((get_unknown_type() == type) || is_Method_type(type));
254
	'''
255

256
class Carry(Binop):
257
258
	"""Computes the value of the carry-bit that would result when adding the 2
	operands"""
259
260
	flags = [ "commutative" ]

Michael Beck's avatar
Michael Beck committed
261
class Cast(Unop):
262
	"""perform a high-level type cast"""
263
264
	mode     = "get_irn_mode(irn_op)"
	flags    = [ "highlevel" ]
265
266
267
268
269
	attrs    = [
		dict(
			type = "ir_type*",
			name = "type"
		)
270
271
	]
	attr_struct = "cast_attr"
272
	init     = "assert(is_atomic_type(type));"
273
274

class Cmp(Binop):
275
	"""Returns the relation of 2 operands"""
276
	outs  = [
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
		("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"),
293
	]
294
295
296
	flags = []

class Cond(Op):
297
298
299
300
301
302
303
304
305
306
307
308
309
	"""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.
	"""
310
	ins      = [ "selector" ]
311
312
313
314
	outs     = [
		("false", "control flow if operand is \"false\""),
		("true",  "control flow if operand is \"true\""),
	]
315
316
	flags    = [ "cfopcode", "forking" ]
	pinned   = "yes"
317
318
319
320
321
322
323
324
325
326
327
	attrs    = [
		dict(
			name = "default_proj",
			type = "long",
			init = "0"
		),
		dict(
			name = "jmp_pred",
			type = "cond_jmp_predicate",
			init = "COND_JMP_PRED_NONE"
		)
328
	]
329
	attr_struct = "cond_attr"
330

331
class Confirm(Op):
332
333
334
335
336
337
338
339
340
	"""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."""
341
342
343
344
	ins      = [ "value", "bound" ]
	mode     = "get_irn_mode(irn_value)"
	flags    = [ "highlevel" ]
	pinned   = "yes"
345
346
347
348
349
	attrs    = [
		dict(
			name = "cmp",
			type = "pn_Cmp"
		),
350
351
	]
	attr_struct = "confirm_attr"
352
	attrs_name  = "confirm"
353
354

class Const(Op):
355
	"""Returns a constant value."""
356
	flags      = [ "constlike", "start_block" ]
357
358
	block      = "get_irg_start_block(irg)"
	mode       = "get_tarval_mode(tarval)"
359
360
	knownBlock = True
	pinned     = "no"
361
362
	attrs      = [
		dict(
Matthias Braun's avatar
Matthias Braun committed
363
			type = "ir_tarval*",
364
365
			name = "tarval",
		)
366
367
	]
	attr_struct = "const_attr"
368
	attrs_name  = "con"
369

370
class Conv(Unop):
371
	"""Converts values between modes"""
372
	flags = []
373
374
375
376
377
378
	attrs = [
		dict(
			name = "strict",
			type = "int",
			init = "0",
		)
379
380
	]
	attr_struct = "conv_attr"
381
	attrs_name  = "conv"
382
383

class CopyB(Op):
384
	"""Copies a block of memory"""
385
	ins   = [ "mem", "dst", "src" ]
386
387
388
389
390
	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"),
	]
391
	flags = [ "fragile", "uses_memory" ]
392
393
	attrs = [
		dict(
394
395
			name = "type",
			type = "ir_type*"
396
		)
397
398
	]
	attr_struct = "copyb_attr"
399
	attrs_name  = "copyb"
400
401
	pinned      = "memory"
	pinned_init = "op_pin_state_pinned"
402

403
class Div(Op):
404
	"""returns the quotient of its 2 operands, integer version"""
405
	ins   = [ "mem", "left", "right" ]
406
407
408
409
410
411
	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"),
	]
412
413
	flags = [ "fragile", "uses_memory" ]
	attrs_name = "divmod"
414
415
416
417
418
	attrs = [
		dict(
			type = "ir_mode*",
			name = "resmode"
		),
Moritz Kroll's avatar
Moritz Kroll committed
419
420
421
422
		dict(
			name = "no_remainder",
			type = "int",
			init = "0",
423
		)
424
425
426
427
428
	]
	attr_struct = "divmod_attr"
	pinned      = "exception"
	op_index    = 1
	arity_override = "oparity_binary"
429

430
class DivMod(Op):
431
	"""divides its 2 operands and computes the remainder of the division"""
432
	ins   = [ "mem", "left", "right" ]
433
434
435
436
437
438
439
	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"),
	]
440
441
	flags = [ "fragile", "uses_memory" ]
	attrs_name = "divmod"
442
443
444
445
446
	attrs = [
		dict(
			type = "ir_mode*",
			name = "resmode"
		),
447
448
449
450
451
452
453
	]
	attr_struct = "divmod_attr"
	pinned      = "exception"
	op_index    = 1
	arity_override = "oparity_binary"

class Dummy(Op):
454
455
456
	"""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."""
457
458
	ins        = []
	flags      = [ "cfopcode", "start_block", "constlike", "dump_noblock" ]
459
460
461
462
463
	knownBlock = True
	pinned     = "yes"
	block      = "get_irg_start_block(irg)"

class End(Op):
464
465
	"""Last node of a graph. It references nodes in endless loops (so called
	keepalive edges)"""
466
467
468
469
470
471
472
473
	mode             = "mode_X"
	pinned           = "yes"
	arity            = "dynamic"
	flags            = [ "cfopcode" ]
	knownBlock       = True
	block            = "get_irg_end_block(irg)"
	singleton        = True
	customSerializer = True
474
475

class Eor(Binop):
476
	"""returns the result of a bitwise exclusive or operation of its operands"""
477
	flags    = [ "commutative" ]
478

479
class Free(Op):
480
	"""Frees a block of memory previously allocated by an Alloc node"""
481
482
483
484
	ins    = [ "mem", "ptr", "size" ]
	mode   = "mode_M"
	flags  = [ "uses_memory" ]
	pinned = "yes"
485
	attrs  = [
486
		dict(
487
488
			name = "type",
			type = "ir_type*"
489
490
		),
		dict(
491
492
			name = "where",
			type = "ir_where_alloc"
493
		)
494
495
496
497
	]
	attr_struct = "free_attr"

class Id(Op):
498
	"""Returns its operand unchanged."""
499
500
501
502
503
	ins    = [ "pred" ]
	pinned = "no"
	flags  = []

class IJmp(Op):
504
505
506
	"""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"""
507
508
509
510
511
512
	mode     = "mode_X"
	pinned   = "yes"
	ins      = [ "target" ]
	flags    = [ "cfopcode", "forking", "keep" ]

class InstOf(Op):
513
	"""Tests wether an object is an instance of a class-type"""
514
	ins   = [ "store", "obj" ]
515
516
517
518
519
520
	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"),
	]
521
	flags = [ "highlevel" ]
522
523
524
525
526
	attrs = [
		dict(
			name = "type",
			type = "ir_type*"
		)
527
528
529
530
531
532
	]
	attr_struct = "io_attr"
	pinned      = "memory"
	pinned_init = "op_pin_state_floats"

class Jmp(Op):
533
	"""Jumps to the block connected through the out-value"""
534
535
536
537
538
539
	mode     = "mode_X"
	pinned   = "yes"
	ins      = []
	flags    = [ "cfopcode" ]

class Load(Op):
540
	"""Loads a value from memory (heap or stack)."""
541
	ins      = [ "mem", "ptr" ]
542
543
544
545
546
547
	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"),
	]
548
549
550
	flags    = [ "fragile", "uses_memory" ]
	pinned   = "exception"
	pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
551
552
553
554
555
556
	attrs    = [
		dict(
			type = "ir_mode*",
			name = "mode",
			java_name = "load_mode"
		),
557
558
	]
	attr_struct = "load_attr"
559
560
	constructor_args = [
		dict(
Moritz Kroll's avatar
Moritz Kroll committed
561
			type = "ir_cons_flags",
562
563
			name = "flags",
		),
564
	]
565
566
567
568
	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;
	'''
569
570

class Minus(Unop):
571
	"""returns the difference between its operands"""
572
573
574
	flags = []

class Mod(Op):
575
576
577
578
579
580
581
582
	"""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
	"""
583
	ins   = [ "mem", "left", "right" ]
584
585
586
587
588
589
	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"),
	]
590
591
	flags = [ "fragile", "uses_memory" ]
	attrs_name = "divmod"
592
	attrs = [
593
		dict(
594
595
			type = "ir_mode*",
			name = "resmode"
596
		),
597
598
599
600
601
	]
	attr_struct = "divmod_attr"
	pinned      = "exception"
	op_index    = 1
	arity_override = "oparity_binary"
Matthias Braun's avatar
Matthias Braun committed
602

603
class Mul(Binop):
604
	"""returns the product of its operands"""
605
606
607
	flags = [ "commutative" ]

class Mulh(Binop):
608
609
	"""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)"""
610
611
612
	flags = [ "commutative" ]

class Mux(Op):
613
614
	"""returns the false or true operand depending on the value of the sel
	operand"""
615
616
617
618
619
	ins    = [ "sel", "false", "true" ]
	flags  = []
	pinned = "no"

class NoMem(Op):
620
	"""Placeholder node for cases where you don't need any memory input"""
621
622
623
624
	mode          = "mode_M"
	flags         = [ "dump_noblock", "dump_noinput" ]
	pinned        = "yes"
	knownBlock    = True
625
	block         = "get_irg_start_block(irg)"
626
	singleton     = True
627
628

class Not(Unop):
629
630
631
	"""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."""
632
633
634
	flags = []

class Or(Binop):
635
	"""returns the result of a bitwise or operation of its operands"""
636
637
638
	flags = [ "commutative" ]

class Phi(Op):
639
640
641
	"""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."""
642
643
644
645
	pinned        = "yes"
	arity         = "variable"
	flags         = []
	attr_struct   = "phi_attr"
646
647
648
	init          = '''
	res->attr.phi.u.backedge = new_backedge_arr(irg->obst, arity);'''
	init_after_opt = '''
Matthias Braun's avatar
Matthias Braun committed
649
650
	/* Memory Phis in endless loops must be kept alive.
	   As we can't distinguish these easily we keep all of them alive. */
651
652
	if (is_Phi(res) && mode == mode_M)
		add_End_keepalive(get_irg_end(irg), res);'''
653
654

class Pin(Op):
655
656
657
	"""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."""
658
659
660
661
662
663
	ins      = [ "op" ]
	mode     = "get_irn_mode(irn_op)"
	flags    = [ "highlevel" ]
	pinned   = "yes"

class Proj(Op):
664
	"""returns an entry of a tuple value"""
665
666
667
668
669
670
671
672
	ins              = [ "pred" ]
	flags            = []
	pinned           = "no"
	knownBlock       = True
	knownGraph       = True
	block            = "get_nodes_block(irn_pred)"
	graph            = "get_irn_irg(irn_pred)"
	customSerializer = True
673
	attrs      = [
674
675
		dict(
			type = "long",
676
			name = "proj",
677
		),
678
	]
679
	attr_struct = "proj_attr"
680
681

class Quot(Op):
682
	"""returns the quotient of its 2 operands, floatingpoint version"""
683
	ins   = [ "mem", "left", "right" ]
684
685
686
687
688
689
	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"),
	]
690
691
	flags = [ "fragile", "uses_memory" ]
	attrs_name = "divmod"
692
	attrs = [
693
		dict(
694
695
696
			type = "ir_mode*",
			name = "resmode"
		),
697
698
699
700
701
702
703
	]
	attr_struct = "divmod_attr"
	pinned      = "exception"
	op_index    = 1
	arity_override = "oparity_binary"

class Raise(Op):
704
705
706
	"""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."""
707
	ins    = [ "mem", "exo_ptr" ]
708
709
710
711
	outs  = [
		("M", "memory result",                     "pn_Generic_M"),
		("X", "control flow to exception handler", "pn_Generic_X_regular"),
	]
712
713
714
715
	flags  = [ "highlevel", "cfopcode" ]
	pinned = "yes"

class Return(Op):
716
717
	"""Returns from the current function. Takes memory and return values as
	operands."""
718
719
720
721
722
723
724
	ins      = [ "mem" ]
	arity    = "variable"
	mode     = "mode_X"
	flags    = [ "cfopcode" ]
	pinned   = "yes"

class Rotl(Binop):
725
726
	"""Returns its first operand bits rotated left by the amount in the 2nd
	operand"""
727
728
729
	flags    = []

class Sel(Op):
730
731
	"""Computes the address of a entity of a compound type given the base
	address of an instance of the compound type."""
732
733
734
735
736
	ins    = [ "mem", "ptr" ]
	arity  = "variable"
	flags  = []
	mode   = "is_Method_type(get_entity_type(entity)) ? mode_P_code : mode_P_data"
	pinned = "no"
737
	attrs  = [
738
		dict(
739
740
741
			type = "ir_entity*",
			name = "entity"
		)
742
743
744
745
	]
	attr_struct = "sel_attr"

class Shl(Binop):
746
747
	"""Returns its first operands bits shifted left by the amount of the 2nd
	operand"""
748
749
750
	flags = []

class Shr(Binop):
751
752
	"""Returns its first operands bits shifted right by the amount of the 2nd
	operand. No special handling for the sign bit (zero extension)"""
753
754
755
	flags = []

class Shrs(Binop):
756
757
758
	"""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)"""
759
760
761
	flags = []

class Start(Op):
762
	"""The first node of a graph. Execution starts with this node."""
763
764
765
766
767
768
769
	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")
	]
770
771
772
773
774
775
776
	mode             = "mode_T"
	pinned           = "yes"
	flags            = [ "cfopcode" ]
	singleton        = True
	knownBlock       = True
	customSerializer = True
	block            = "get_irg_start_block(irg)"
777
778

class Store(Op):
779
	"""Stores a value into memory (heap or stack)."""
780
	ins      = [ "mem", "ptr", "value" ]
781
782
783
784
785
	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"),
	]
786
787
788
789
	flags    = [ "fragile", "uses_memory" ]
	pinned   = "exception"
	attr_struct = "store_attr"
	pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
790
	constructor_args = [
791
		dict(
792
793
			type = "ir_cons_flags",
			name = "flags",
794
		),
795
	]
796
797
798
799
	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;
	'''
800
801

class Sub(Binop):
802
	"""returns the difference of its operands"""
803
804
805
	flags = []

class SymConst(Op):
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
	"""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."""
823
824
825
826
	mode       = "mode_P"
	flags      = [ "constlike", "start_block" ]
	knownBlock = True
	pinned     = "no"
827
	attrs      = [
828
		dict(
829
			type = "ir_entity*",
830
831
			name = "entity",
			noprop = True
832
		)
833
834
	]
	attr_struct = "symconst_attr"
835
	customSerializer = True
836
837
838
	# constructor is written manually at the moment, because of the strange
	# union argument
	noconstructor = True
839
840

class Sync(Op):
841
842
843
844
845
	"""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."""
846
847
848
	mode     = "mode_M"
	flags    = []
	pinned   = "no"
849
	arity    = "dynamic"
850

851
class Tuple(Op):
852
853
854
855
856
857
858
859
	"""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."""
860
861
862
863
864
865
	arity  = "variable"
	mode   = "mode_T"
	pinned = "no"
	flags  = [ "labeled" ]

class Unknown(Op):
866
867
	"""Returns an unknown (at compile- and runtime) value. It is a valid
	optimisation to replace an Unknown by any other constant value."""
868
869
870
	knownBlock = True
	pinned     = "yes"
	block      = "get_irg_start_block(irg)"
871
	flags      = [ "cfopcode", "start_block", "constlike", "dump_noblock" ]
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887

# 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))