belive: Remove the visited bitset for liveness calculation.
[libfirm] / scripts / ir_spec.py
1 # Firm node specifications
2 # The comments are in (standard python) restructured text format and are used
3 # to generate documentation.
4 from spec_util import abstract, op
5
6 name = "ir"
7
8 @abstract
9 @op
10 class Unop(object):
11         """Unary nodes have exactly 1 input"""
12         name     = "unop"
13         ins      = [
14                 ("op",  "operand"),
15         ]
16         op_index = 0
17         pinned   = "no"
18
19 @abstract
20 @op
21 class Binop(object):
22         """Binary nodes have exactly 2 inputs"""
23         name     = "binop"
24         ins      = [
25                 ( "left",   "first operand" ),
26                 ( "right", "second operand" ),
27         ]
28         op_index = 0
29         pinned   = "no"
30
31 @op
32 class Add(Binop):
33         """returns the sum of its operands"""
34         flags = [ "commutative" ]
35
36 @op
37 class Alloc:
38         """allocates a block of memory.
39         It can be specified whether the memory should be allocated to the stack
40         or to the heap.
41         Allocates memory for one or more objects (depending on value on count input).
42         """
43         ins   = [
44                 ("mem",   "memory dependency" ),
45                 ("count", "number of objects to allocate" ),
46         ]
47         outs  = [
48                 ("M",         "memory result"),
49                 ("res",       "pointer to newly allocated memory"),
50                 ("X_regular", "control flow when no exception occurs"),
51                 ("X_except",  "control flow when exception occured"),
52         ]
53         attrs = [
54                 dict(
55                         name    = "type",
56                         type    = "ir_type*",
57                         comment = "type of the objects to allocate",
58                 ),
59                 dict(
60                         name    = "where",
61                         type    = "ir_where_alloc",
62                         comment = "whether to allocate the variable on the stack or heap",
63                 )
64         ]
65         flags       = [ "fragile", "uses_memory" ]
66         pinned      = "exception"
67         throws_init = "false"
68         pinned_init = "op_pin_state_pinned"
69         attr_struct = "alloc_attr"
70
71 @op
72 class Anchor:
73         """utiliy node used to "hold" nodes in a graph that might possibly not be
74         reachable by other means or which should be reachable immediately without
75         searching through the graph.
76         Each firm-graph contains exactly one anchor node whose address is always
77         known. All other well-known graph-nodes like Start, End, NoMem, Bad, ...
78         are found by looking at the respective Anchor operand."""
79         mode             = "mode_ANY"
80         arity            = "variable"
81         flags            = [ "dump_noblock" ]
82         pinned           = "yes"
83         attr_struct      = "irg_attr"
84         knownBlock       = True
85         singleton        = True
86         noconstructor    = True
87         customSerializer = True
88
89 @op
90 class And(Binop):
91         """returns the result of a bitwise and operation of its operands"""
92         flags    = [ "commutative" ]
93
94 @op
95 class ASM:
96         """executes assembler fragments of the target machine.
97
98         The node contains a template for an assembler snippet. The compiler will
99         replace occurences of %0 to %9 with input/output registers,
100         %% with a single % char. Some backends allow additional specifiers (for
101         example %w3, %l3, %h3 on x86 to get a 16bit, 8hit low, 8bit high part
102         of a register).
103         After the replacements the text is emitted into the final assembly.
104
105         The clobber list contains names of registers which have an undefined value
106         after the assembler instruction is executed; it may also contain 'memory'
107         or 'cc' if global state/memory changes or the condition code registers
108         (some backends implicitely set cc, memory clobbers on all ASM statements).
109
110         Example (an i386 instruction)::
111
112                 ASM(text="btsl %1, %0",
113                         input_constraints = ["=m", "r"],
114                         clobbers = ["cc"])
115
116         As there are no output, the %0 references the first input which is just an
117         address which the asm operation writes to. %1 references to an input which
118         is passed as a register. The condition code register has an unknown value
119         after the instruction.
120
121         (This format is inspired by the gcc extended asm syntax)
122         """
123         mode             = "mode_T"
124         arity            = "variable"
125         flags            = [ "keep", "uses_memory" ]
126         pinned           = "memory"
127         pinned_init      = "op_pin_state_pinned"
128         attr_struct      = "asm_attr"
129         attrs_name       = "assem"
130         customSerializer = True
131         ins   = [
132                 ("mem",    "memory dependency"),
133         ]
134         attrs = [
135                 dict(
136                         name    = "input_constraints",
137                         type    = "ir_asm_constraint*",
138                         comment = "input constraints",
139                 ),
140                 dict(
141                         name    = "n_output_constraints",
142                         type    = "size_t",
143                         noprop  = True,
144                         comment = "number of output constraints",
145                 ),
146                 dict(
147                         name    = "output_constraints",
148                         type    = "ir_asm_constraint*",
149                         comment = "output constraints",
150                 ),
151                 dict(
152                         name    = "n_clobbers",
153                         type    = "size_t",
154                         noprop  = True,
155                         comment = "number of clobbered registers/memory",
156                 ),
157                 dict(
158                         name    = "clobbers",
159                         type    = "ident**",
160                         comment = "list of clobbered registers/memory",
161                 ),
162                 dict(
163                         name    = "text",
164                         type    = "ident*",
165                         comment = "assembler text",
166                 ),
167         ]
168         # constructor is written manually at the moment, because of the clobbers+
169         # constraints arrays needing special handling (2 arguments for 1 attribute)
170         noconstructor = True
171
172 @op
173 class Bad:
174         """Bad nodes indicate invalid input, which is values which should never be
175         computed.
176
177         The typical use case for the Bad node is removing unreachable code.
178         Frontends should set the current_block to Bad when it is clear that
179         following code must be unreachable (ie. after a goto or return statement).
180         Optimisations also set block predecessors to Bad when it becomes clear,
181         that a control flow edge can never be executed.
182
183         The gigo optimisations ensures that nodes with Bad as their block, get
184         replaced by Bad themselves. Nodes with at least 1 Bad input get exchanged
185         with Bad too. Exception to this rule are Block, Phi, Tuple and End node;
186         This is because removing inputs from a Block is hairy operation (requiring,
187         Phis to be shortened too for example). So instead of removing block inputs
188         they are set to Bad, and the actual removal is left to the control flow
189         optimisation phase. Block, Phi, Tuple with only Bad inputs however are
190         replaced by Bad right away."""
191         flags         = [ "start_block", "dump_noblock" ]
192         pinned        = "yes"
193         knownBlock    = True
194         block         = "get_irg_start_block(irg)"
195         attr_struct   = "bad_attr"
196         init = '''
197         res->attr.bad.irg.irg = irg;
198         '''
199
200 @op
201 class Deleted:
202         """Internal node which is temporary set to nodes which are already removed
203         from the graph."""
204         mode             = "mode_Bad"
205         flags            = [ ]
206         pinned           = "yes"
207         noconstructor    = True
208         customSerializer = True # this has no serializer
209
210 @op
211 class Block:
212         """A basic block"""
213         mode             = "mode_BB"
214         knownBlock       = True
215         block            = "NULL"
216         pinned           = "yes"
217         arity            = "variable"
218         flags            = []
219         attr_struct      = "block_attr"
220         attrs            = [
221                 dict(
222                         name    = "entity",
223                         type    = "ir_entity*",
224                         comment = "entity representing this block",
225                         init    = "NULL",
226                 ),
227         ]
228         customSerializer = True
229
230         init = '''
231         res->attr.block.irg.irg     = irg;
232         res->attr.block.backedge    = new_backedge_arr(get_irg_obstack(irg), arity);
233         set_Block_matured(res, 1);
234
235         /* Create and initialize array for Phi-node construction. */
236         if (irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_CONSTRUCTION)) {
237                 res->attr.block.graph_arr = NEW_ARR_DZ(ir_node*, get_irg_obstack(irg), irg->n_loc);
238         }
239         '''
240
241 @op
242 class Borrow(Binop):
243         """Returns the borrow bit from and implied subtractions of its 2 operands"""
244         flags = []
245
246 @op
247 class Bound:
248         """Performs a bounds-check: if lower <= index < upper then return index,
249         otherwise throw an exception."""
250         ins    = [
251                 ("mem",    "memory dependency"),
252                 ("index",  "value to test"),
253                 ("lower",  "lower bound (inclusive)"),
254                 ("upper",  "upper bound (exclusive)"),
255         ]
256         outs  = [
257                 ("M",         "memory result"),
258                 ("res",       "the checked index"),
259                 ("X_regular", "control flow when no exception occurs"),
260                 ("X_except",  "control flow when exception occured"),
261         ]
262         flags  = [ "fragile", "highlevel" ]
263         pinned = "exception"
264         pinned_init = "op_pin_state_pinned"
265         throws_init = "false"
266         attr_struct = "bound_attr"
267
268 @op
269 class Builtin:
270         """performs a backend-specific builtin."""
271         ins      = [
272                 ("mem", "memory dependency"),
273         ]
274         arity    = "variable"
275         outs     = [
276                 ("M", "memory result"),
277                 # results follow here
278         ]
279         flags    = [ "uses_memory" ]
280         attrs    = [
281                 dict(
282                         type    = "ir_builtin_kind",
283                         name    = "kind",
284                         comment = "kind of builtin",
285                 ),
286                 dict(
287                         type    = "ir_type*",
288                         name    = "type",
289                         comment = "method type for the builtin call",
290                 )
291         ]
292         pinned      = "memory"
293         pinned_init = "op_pin_state_pinned"
294         attr_struct = "builtin_attr"
295         init   = '''
296         assert((get_unknown_type() == type) || is_Method_type(type));
297         '''
298
299 @op
300 class Call:
301         """Calls other code. Control flow is transfered to ptr, additional
302         operands are passed to the called code. Called code usually performs a
303         return operation. The operands of this return operation are the result
304         of the Call node."""
305         ins      = [
306                 ("mem",   "memory dependency"),
307                 ("ptr",   "pointer to called code"),
308         ]
309         arity    = "variable"
310         outs     = [
311                 ("M",                "memory result"),
312                 ("T_result",         "tuple containing all results"),
313                 ("X_regular",        "control flow when no exception occurs"),
314                 ("X_except",         "control flow when exception occured"),
315         ]
316         flags    = [ "fragile", "uses_memory" ]
317         attrs    = [
318                 dict(
319                         type    = "ir_type*",
320                         name    = "type",
321                         comment = "type of the call (usually type of the called procedure)",
322                 ),
323         ]
324         attr_struct = "call_attr"
325         pinned      = "memory"
326         pinned_init = "op_pin_state_pinned"
327         throws_init = "false"
328         init = '''
329         assert((get_unknown_type() == type) || is_Method_type(type));
330         '''
331
332 @op
333 class Carry(Binop):
334         """Computes the value of the carry-bit that would result when adding the 2
335         operands"""
336         flags = [ "commutative" ]
337
338 @op
339 class Cast(Unop):
340         """perform a high-level type cast"""
341         mode     = "get_irn_mode(irn_op)"
342         flags    = [ "highlevel" ]
343         attrs    = [
344                 dict(
345                         type    = "ir_type*",
346                         name    = "type",
347                         comment = "target type of the case",
348                 )
349         ]
350         attr_struct = "cast_attr"
351         init     = "assert(is_atomic_type(type));"
352
353 @op
354 class Cmp(Binop):
355         """Compares its two operands and checks whether a specified
356            relation (like less or equal) is fulfilled."""
357         flags = []
358         mode  = "mode_b"
359         attrs = [
360                 dict(
361                         type    = "ir_relation",
362                         name    = "relation",
363                         comment = "Comparison relation"
364                 )
365         ]
366         attr_struct = "cmp_attr"
367
368 @op
369 class Cond:
370         """Conditionally change control flow."""
371         ins      = [
372                 ("selector",  "condition parameter"),
373         ]
374         outs     = [
375                 ("false", "control flow if operand is \"false\""),
376                 ("true",  "control flow if operand is \"true\""),
377         ]
378         flags    = [ "cfopcode", "forking" ]
379         pinned   = "yes"
380         attrs    = [
381                 dict(
382                         name    = "jmp_pred",
383                         type    = "cond_jmp_predicate",
384                         init    = "COND_JMP_PRED_NONE",
385                         comment = "can indicate the most likely jump",
386                 ),
387         ]
388         attr_struct = "cond_attr"
389
390 @op
391 class Switch:
392         """Change control flow. The destination is choosen based on an integer input value which is looked up in a table.
393
394         Backends can implement this efficiently using a jump table."""
395         ins    = [
396                 ("selector", "input selector"),
397         ]
398         outs   = [
399                 ("default", "control flow if no other case matches"),
400         ]
401         flags  = [ "cfopcode", "forking" ]
402         pinned = "yes"
403         attrs  = [
404                 dict(
405                         name    = "n_outs",
406                         type    = "unsigned",
407                         comment = "number of outputs (including pn_Switch_default)",
408                 ),
409                 dict(
410                         name    = "table",
411                         type    = "ir_switch_table*",
412                         comment = "table describing mapping from input values to Proj numbers",
413                 ),
414         ]
415         attr_struct = "switch_attr"
416         attrs_name  = "switcha"
417
418 @op
419 class Confirm:
420         """Specifies constraints for a value. This allows explicit representation
421         of path-sensitive properties. (Example: This value is always >= 0 on 1
422         if-branch then all users within that branch are rerouted to a confirm-node
423         specifying this property).
424
425         A constraint is specified for the relation between value and bound.
426         value is always returned.
427         Note that this node does NOT check or assert the constraint, it merely
428         specifies it."""
429         ins      = [
430                 ("value",  "value to express a constraint for"),
431                 ("bound",  "value to compare against"),
432         ]
433         mode     = "get_irn_mode(irn_value)"
434         flags    = [ "highlevel" ]
435         pinned   = "yes"
436         attrs    = [
437                 dict(
438                         name    = "relation",
439                         type    = "ir_relation",
440                         comment = "relation of value to bound",
441                 ),
442         ]
443         attr_struct = "confirm_attr"
444
445 @op
446 class Const:
447         """Returns a constant value."""
448         flags      = [ "constlike", "start_block" ]
449         block      = "get_irg_start_block(irg)"
450         mode       = "get_tarval_mode(tarval)"
451         knownBlock = True
452         pinned     = "no"
453         attrs      = [
454                 dict(
455                         type    = "ir_tarval*",
456                         name    = "tarval",
457                         comment = "constant value (a tarval object)",
458                 )
459         ]
460         attr_struct = "const_attr"
461         attrs_name  = "con"
462
463 @op
464 class Conv(Unop):
465         """Converts values between modes"""
466         flags = []
467
468 @op
469 class CopyB:
470         """Copies a block of memory with statically known size/type."""
471         ins   = [
472                 ("mem",  "memory dependency"),
473                 ("dst",  "destination address"),
474                 ("src",  "source address"),
475         ]
476         outs  = [
477                 ("M",         "memory result"),
478                 ("X_regular", "control flow when no exception occurs"),
479                 ("X_except",  "control flow when exception occured"),
480         ]
481         flags = [ "fragile", "uses_memory" ]
482         attrs = [
483                 dict(
484                         name    = "type",
485                         type    = "ir_type*",
486                         comment = "type of copied data",
487                 )
488         ]
489         attr_struct = "copyb_attr"
490         pinned      = "memory"
491         pinned_init = "op_pin_state_pinned"
492         throws_init = "false"
493
494 @op
495 class Div:
496         """returns the quotient of its 2 operands"""
497         ins   = [
498                 ("mem",   "memory dependency"),
499                 ("left",  "first operand"),
500                 ("right", "second operand"),
501         ]
502         outs  = [
503                 ("M",         "memory result"),
504                 ("res",       "result of computation"),
505                 ("X_regular", "control flow when no exception occurs"),
506                 ("X_except",  "control flow when exception occured"),
507         ]
508         flags = [ "fragile", "uses_memory" ]
509         attrs = [
510                 dict(
511                         type    = "ir_mode*",
512                         name    = "resmode",
513                         comment = "mode of the result value",
514                 ),
515                 dict(
516                         name = "no_remainder",
517                         type = "int",
518                         init = "0",
519                 )
520         ]
521         attr_struct = "div_attr"
522         pinned      = "exception"
523         throws_init = "false"
524         op_index    = 1
525         arity_override = "oparity_binary"
526
527 @op
528 class Dummy:
529         """A placeholder value. This is used when constructing cyclic graphs where
530         you have cases where not all predecessors of a phi-node are known. Dummy
531         nodes are used for the unknown predecessors and replaced later."""
532         ins        = []
533         flags      = [ "cfopcode", "start_block", "constlike", "dump_noblock" ]
534         knownBlock = True
535         pinned     = "yes"
536         block      = "get_irg_start_block(irg)"
537
538 @op
539 class End:
540         """Last node of a graph. It references nodes in endless loops (so called
541         keepalive edges)"""
542         mode             = "mode_X"
543         pinned           = "yes"
544         arity            = "dynamic"
545         flags            = [ "cfopcode" ]
546         knownBlock       = True
547         block            = "get_irg_end_block(irg)"
548         singleton        = True
549
550 @op
551 class Eor(Binop):
552         """returns the result of a bitwise exclusive or operation of its operands.
553
554         This is also known as the Xor operation."""
555         flags    = [ "commutative" ]
556
557 @op
558 class Free:
559         """Frees a block of memory previously allocated by an Alloc node"""
560         ins    = [
561                 ("mem",   "memory dependency" ),
562                 ("ptr",   "pointer to the object to free"),
563                 ("count", "number of objects to allocate" ),
564         ]
565         mode   = "mode_M"
566         flags  = [ "uses_memory" ]
567         pinned = "yes"
568         attrs  = [
569                 dict(
570                         name    = "type",
571                         type    = "ir_type*",
572                         comment = "type of the allocated variable",
573                 ),
574                 dict(
575                         name    = "where",
576                         type    = "ir_where_alloc",
577                         comment = "whether allocation was on the stack or heap",
578                 )
579         ]
580         attr_struct = "free_attr"
581
582 @op
583 class Id:
584         """Returns its operand unchanged.
585
586         This is mainly used when exchanging nodes. Usually you shouldn't see Id
587         nodes since the getters/setters for node inputs skip them automatically."""
588         ins    = [
589            ("pred", "the value which is returned unchanged")
590         ]
591         pinned = "no"
592         flags  = []
593
594 @op
595 class IJmp:
596         """Jumps to the code in its argument. The code has to be in the same
597         function and the the destination must be one of the blocks reachable
598         by the tuple results"""
599         mode     = "mode_X"
600         pinned   = "yes"
601         ins      = [
602            ("target", "target address of the jump"),
603         ]
604         flags    = [ "cfopcode", "forking", "keep", "unknown_jump" ]
605
606 @op
607 class InstOf:
608         """Tests whether an object is an instance of a class-type"""
609         ins   = [
610            ("store", "memory dependency"),
611            ("obj",   "pointer to object being queried")
612         ]
613         outs  = [
614                 ("M",         "memory result"),
615                 ("res",       "checked object pointer"),
616                 ("X_regular", "control flow when no exception occurs"),
617                 ("X_except",  "control flow when exception occured"),
618         ]
619         flags = [ "highlevel" ]
620         attrs = [
621                 dict(
622                         name    = "type",
623                         type    = "ir_type*",
624                         comment = "type to check ptr for",
625                 )
626         ]
627         attr_struct = "io_attr"
628         pinned      = "memory"
629         pinned_init = "op_pin_state_floats"
630
631 @op
632 class Jmp:
633         """Jumps to the block connected through the out-value"""
634         mode     = "mode_X"
635         pinned   = "yes"
636         ins      = []
637         flags    = [ "cfopcode" ]
638
639 @op
640 class Load:
641         """Loads a value from memory (heap or stack)."""
642         ins   = [
643                 ("mem", "memory dependency"),
644                 ("ptr",  "address to load from"),
645         ]
646         outs  = [
647                 ("M",         "memory result"),
648                 ("res",       "result of load operation"),
649                 ("X_regular", "control flow when no exception occurs"),
650                 ("X_except",  "control flow when exception occured"),
651         ]
652         flags    = [ "fragile", "uses_memory" ]
653         pinned   = "exception"
654         attrs    = [
655                 dict(
656                         type      = "ir_mode*",
657                         name      = "mode",
658                         comment   = "mode of the value to be loaded",
659                 ),
660                 dict(
661                         type      = "ir_volatility",
662                         name      = "volatility",
663                         comment   = "volatile loads are a visible side-effect and may not be optimized",
664                         init      = "flags & cons_volatile ? volatility_is_volatile : volatility_non_volatile",
665                         to_flags  = "%s == volatility_is_volatile ? cons_volatile : cons_none"
666                 ),
667                 dict(
668                         type      = "ir_align",
669                         name      = "unaligned",
670                         comment   = "pointers to unaligned loads don't need to respect the load-mode/type alignments",
671                         init      = "flags & cons_unaligned ? align_non_aligned : align_is_aligned",
672                         to_flags  = "%s == align_non_aligned ? cons_unaligned : cons_none"
673                 ),
674         ]
675         attr_struct = "load_attr"
676         constructor_args = [
677                 dict(
678                         type    = "ir_cons_flags",
679                         name    = "flags",
680                         comment = "specifies alignment, volatility and pin state",
681                 ),
682         ]
683         pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
684         throws_init = "(flags & cons_throws_exception) != 0"
685
686 @op
687 class Minus(Unop):
688         """returns the additive inverse of its operand"""
689         flags = []
690
691 @op
692 class Mod:
693         """returns the remainder of its operands from an implied division.
694
695         Examples:
696
697         * mod(5,3)   produces 2
698         * mod(5,-3)  produces 2
699         * mod(-5,3)  produces -2
700         * mod(-5,-3) produces -2
701         """
702         ins   = [
703                 ("mem",   "memory dependency"),
704                 ("left",  "first operand"),
705                 ("right", "second operand"),
706         ]
707         outs  = [
708                 ("M",         "memory result"),
709                 ("res",       "result of computation"),
710                 ("X_regular", "control flow when no exception occurs"),
711                 ("X_except",  "control flow when exception occured"),
712         ]
713         flags = [ "fragile", "uses_memory" ]
714         attrs = [
715                 dict(
716                         type    = "ir_mode*",
717                         name    = "resmode",
718                         comment = "mode of the result",
719                 ),
720         ]
721         attr_struct = "mod_attr"
722         pinned      = "exception"
723         throws_init = "false"
724         op_index    = 1
725         arity_override = "oparity_binary"
726
727 class Mul(Binop):
728         """returns the product of its operands"""
729         flags = [ "commutative" ]
730
731 class Mulh(Binop):
732         """returns the upper word of the product of its operands (the part which
733         would not fit into the result mode of a normal Mul anymore)"""
734         flags = [ "commutative" ]
735
736 @op
737 class Mux:
738         """returns the false or true operand depending on the value of the sel
739         operand"""
740         ins    = [
741            ("sel",   "value making the output selection"),
742            ("false", "selected if sel input is false"),
743            ("true",  "selected if sel input is true"),
744         ]
745         flags  = []
746         pinned = "no"
747
748 @op
749 class NoMem:
750         """Placeholder node for cases where you don't need any memory input"""
751         mode          = "mode_M"
752         flags         = [ "dump_noblock" ]
753         pinned        = "yes"
754         knownBlock    = True
755         block         = "get_irg_start_block(irg)"
756         singleton     = True
757
758 @op
759 class Not(Unop):
760         """returns the bitwise complement of a value. Works for boolean values, too."""
761         flags = []
762
763 @op
764 class Or(Binop):
765         """returns the result of a bitwise or operation of its operands"""
766         flags = [ "commutative" ]
767
768 @op
769 class Phi:
770         """Choose a value based on control flow. A phi node has 1 input for each
771         predecessor of its block. If a block is entered from its nth predecessor
772         all phi nodes produce their nth input as result."""
773         pinned        = "yes"
774         arity         = "variable"
775         flags         = []
776         attr_struct   = "phi_attr"
777         init          = '''
778         res->attr.phi.u.backedge = new_backedge_arr(get_irg_obstack(irg), arity);'''
779         customSerializer = True
780
781 @op
782 class Pin:
783         """Pin the value of the node node in the current block. No users of the Pin
784         node can float above the Block of the Pin. The node cannot float behind
785         this block. Often used to Pin the NoMem node."""
786         ins      = [
787                 ("op", "value which is pinned"),
788         ]
789         mode     = "get_irn_mode(irn_op)"
790         flags    = [ "highlevel" ]
791         pinned   = "yes"
792
793 @op
794 class Proj:
795         """returns an entry of a tuple value"""
796         ins              = [
797                 ("pred", "the tuple value from which a part is extracted"),
798         ]
799         flags            = []
800         pinned           = "no"
801         knownBlock       = True
802         knownGraph       = True
803         block            = "get_nodes_block(irn_pred)"
804         graph            = "get_irn_irg(irn_pred)"
805         attrs      = [
806                 dict(
807                         type    = "long",
808                         name    = "proj",
809                         comment = "number of tuple component to be extracted",
810                 ),
811         ]
812         attr_struct = "proj_attr"
813
814 @op
815 class Raise:
816         """Raises an exception. Unconditional change of control flow. Writes an
817         explicit Except variable to memory to pass it to the exception handler.
818         Must be lowered to a Call to a runtime check function."""
819         ins    = [
820                 ("mem",     "memory dependency"),
821                 ("exo_ptr", "pointer to exception object to be thrown"),
822         ]
823         outs  = [
824                 ("M", "memory result"),
825                 ("X", "control flow to exception handler"),
826         ]
827         flags  = [ "highlevel", "cfopcode" ]
828         pinned = "yes"
829
830 @op
831 class Return:
832         """Returns from the current function. Takes memory and return values as
833         operands."""
834         ins      = [
835                 ("mem", "memory dependency"),
836         ]
837         arity    = "variable"
838         mode     = "mode_X"
839         flags    = [ "cfopcode" ]
840         pinned   = "yes"
841
842 class Rotl(Binop):
843         """Returns its first operand bits rotated left by the amount in the 2nd
844         operand"""
845         flags    = []
846
847 @op
848 class Sel:
849         """Computes the address of a entity of a compound type given the base
850         address of an instance of the compound type.
851
852         Optimisations assume that a Sel node can only produce a NULL pointer if the
853         ptr input was NULL."""
854         ins    = [
855                 ("mem", "memory dependency"),
856                 ("ptr", "pointer to object to select from"),
857         ]
858         arity  = "variable"
859         flags  = []
860         mode   = "is_Method_type(get_entity_type(entity)) ? mode_P_code : mode_P_data"
861         pinned = "no"
862         attrs  = [
863                 dict(
864                         type    = "ir_entity*",
865                         name    = "entity",
866                         comment = "entity which is selected",
867                 )
868         ]
869         attr_struct = "sel_attr"
870
871 @op
872 class Shl(Binop):
873         """Returns its first operands bits shifted left by the amount of the 2nd
874         operand.
875         The right input (shift amount) must be an unsigned integer value.
876         If the result mode has modulo_shift!=0, then the effective shift amount is
877         the right input modulo this modulo_shift amount."""
878         flags = []
879
880 @op
881 class Shr(Binop):
882         """Returns its first operands bits shifted right by the amount of the 2nd
883         operand. No special handling for the sign bit is performed (zero extension).
884         The right input (shift amount) must be an unsigned integer value.
885         If the result mode has modulo_shift!=0, then the effective shift amount is
886         the right input modulo this modulo_shift amount."""
887         flags = []
888
889 @op
890 class Shrs(Binop):
891         """Returns its first operands bits shifted right by the amount of the 2nd
892         operand. The leftmost bit (usually the sign bit) stays the same
893         (sign extension).
894         The right input (shift amount) must be an unsigned integer value.
895         If the result mode has modulo_shift!=0, then the effective shift amount is
896         the right input modulo this modulo_shift amount."""
897         flags = []
898
899 @op
900 class Start:
901         """The first node of a graph. Execution starts with this node."""
902         outs       = [
903                 ("X_initial_exec", "control flow"),
904                 ("M",              "initial memory"),
905                 ("P_frame_base",   "frame base pointer"),
906                 ("T_args",         "function arguments")
907         ]
908         mode             = "mode_T"
909         pinned           = "yes"
910         flags            = [ "cfopcode" ]
911         singleton        = True
912         knownBlock       = True
913         block            = "get_irg_start_block(irg)"
914
915 @op
916 class Store:
917         """Stores a value into memory (heap or stack)."""
918         ins   = [
919            ("mem",   "memory dependency"),
920            ("ptr",   "address to store to"),
921            ("value", "value to store"),
922         ]
923         outs  = [
924                 ("M",         "memory result"),
925                 ("X_regular", "control flow when no exception occurs"),
926                 ("X_except",  "control flow when exception occured"),
927         ]
928         flags    = [ "fragile", "uses_memory" ]
929         pinned   = "exception"
930         attr_struct = "store_attr"
931         pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
932         throws_init = "(flags & cons_throws_exception) != 0"
933         attrs = [
934                 dict(
935                         type      = "ir_volatility",
936                         name      = "volatility",
937                         comment   = "volatile stores are a visible side-effect and may not be optimized",
938                         init      = "flags & cons_volatile ? volatility_is_volatile : volatility_non_volatile",
939                         to_flags  = "%s == volatility_is_volatile ? cons_volatile : cons_none"
940                 ),
941                 dict(
942                         type      = "ir_align",
943                         name      = "unaligned",
944                         comment   = "pointers to unaligned stores don't need to respect the load-mode/type alignments",
945                         init      = "flags & cons_unaligned ? align_non_aligned : align_is_aligned",
946                         to_flags  = "%s == align_non_aligned ? cons_unaligned : cons_none"
947                 ),
948         ]
949         constructor_args = [
950                 dict(
951                         type    = "ir_cons_flags",
952                         name    = "flags",
953                         comment = "specifies alignment, volatility and pin state",
954                 ),
955         ]
956
957 @op
958 class Sub(Binop):
959         """returns the difference of its operands"""
960         flags = []
961
962 @op
963 class SymConst:
964         """A symbolic constant.
965
966          - *symconst_type_size* The symbolic constant represents the size of a type.
967                                 The type of which the constant represents the size
968                                 is given explicitly.
969          - *symconst_type_align* The symbolic constant represents the alignment of a
970                                 type.  The type of which the constant represents the
971                                 size is given explicitly.
972          - *symconst_addr_ent*  The symbolic constant represents the address of an
973                                 entity (variable or method).  The variable is given
974                                 explicitly by a firm entity.
975          - *symconst_ofs_ent*   The symbolic constant represents the offset of an
976                                 entity in its owner type.
977          - *symconst_enum_const* The symbolic constant is a enumeration constant of
978                                 an enumeration type."""
979         mode       = "mode_P"
980         flags      = [ "constlike", "start_block" ]
981         knownBlock = True
982         pinned     = "no"
983         attrs      = [
984                 dict(
985                         type    = "ir_entity*",
986                         name    = "entity",
987                         noprop  = True,
988                         comment = "entity whose address is returned",
989                 )
990         ]
991         attr_struct = "symconst_attr"
992         customSerializer = True
993         # constructor is written manually at the moment, because of the strange
994         # union argument
995         noconstructor = True
996
997 @op
998 class Sync:
999         """The Sync operation unifies several partial memory blocks. These blocks
1000         have to be pairwise disjunct or the values in common locations have to
1001         be identical.  This operation allows to specify all operations that
1002         eventually need several partial memory blocks as input with a single
1003         entrance by unifying the memories with a preceding Sync operation."""
1004         mode     = "mode_M"
1005         flags    = []
1006         pinned   = "no"
1007         arity    = "dynamic"
1008
1009 @op
1010 class Tuple:
1011         """Builds a Tuple from single values.
1012
1013         This is needed to implement optimizations that remove a node that produced
1014         a tuple.  The node can be replaced by the Tuple operation so that the
1015         following Proj nodes have not to be changed. (They are hard to find due to
1016         the implementation with pointers in only one direction.) The Tuple node is
1017         smaller than any other node, so that a node can be changed into a Tuple by
1018         just changing its opcode and giving it a new in array."""
1019         arity  = "variable"
1020         mode   = "mode_T"
1021         pinned = "no"
1022         flags  = []
1023
1024 @op
1025 class Unknown:
1026         """Returns an unknown (at compile- and runtime) value. It is a valid
1027         optimisation to replace an Unknown by any other constant value."""
1028         knownBlock = True
1029         pinned     = "yes"
1030         block      = "get_irg_start_block(irg)"
1031         flags      = [ "start_block", "constlike", "dump_noblock" ]