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