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