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