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