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