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