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