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