1 from spec_util import abstract, setnodedefaults
4 """Base class for firm nodes"""
8 """Unary nodes have exactly 1 input"""
18 """Binary nodes have exactly 2 inputs"""
21 ( "left", "first operand" ),
22 ( "right", "second operand" ),
29 """returns the sum of its operands"""
30 flags = [ "commutative" ]
33 """allocates a block of memory.
34 It can be specified whether the variable should be allocated to the stack
37 ("mem", "memory dependency" ),
38 ("count", "number of objects to allocate" ),
41 ("M", "memory result", "pn_Generic_M"),
42 ("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
43 ("X_except", "control flow when exception occured", "pn_Generic_X_except"),
44 ("res", "pointer to newly allocated memory", "pn_Generic_other"),
50 comment = "type of the allocated variable",
54 type = "ir_where_alloc",
55 comment = "whether to allocate the variable on the stack or heap",
58 flags = [ "fragile", "uses_memory" ]
60 attr_struct = "alloc_attr"
63 """utiliy node used to "hold" nodes in a graph that might possibly not be
64 reachable by other means or which should be reachable immediately without
65 searching through the graph.
66 Each firm-graph contains exactly one anchor node whose address is always
67 known. All other well-known graph-nodes like Start, End, NoMem, Bad, ...
68 are found by looking at the respective Anchor operand."""
71 flags = [ "dump_noblock" ]
73 attr_struct = "irg_attr"
77 customSerializer = True
80 """returns the result of a bitwise and operation of its operands"""
81 flags = [ "commutative" ]
84 """executes assembler fragments of the target machine"""
87 flags = [ "keep", "uses_memory" ]
89 pinned_init = "op_pin_state_pinned"
90 attr_struct = "asm_attr"
92 customSerializer = True
95 name = "input_constraints",
96 type = "ir_asm_constraint*",
97 comment = "input constraints",
100 name = "n_output_constraints",
103 comment = "number of output constraints",
106 name = "output_constraints",
107 type = "ir_asm_constraint*",
108 comment = "output constraints",
114 comment = "number of clobbered registers/memory",
119 comment = "list of clobbered registers/memory",
124 comment = "assembler text",
127 # constructor is written manually at the moment, because of the clobbers+
128 # constraints arrays needing special handling (2 arguments for 1 attribute)
132 """Bad nodes indicate invalid input, which is values which should never be
135 The typical use case for the Bad node is removing unreachable code.
136 Frontends should set the current_block to Bad when it is clear that
137 following code must be unreachable (ie. after a goto or return statement).
138 Optimisations also set block predecessors to Bad when it becomes clear,
139 that a control flow edge can never be executed.
141 The gigo optimisations ensures that nodes with Bad as their block, get
142 replaced by Bad themselfes. Nodes with at least 1 Bad input get exchanged
143 with Bad too. Exception to this rule are Block, Phi, Tuple and End node;
144 This is because removing inputs from a Block is hairy operation (requiring,
145 Phis to be shortened too for example). So instead of removing block inputs
146 they are set to Bad, and the actual removal is left to the control flow
147 optimisation phase. Block, Phi, Tuple with only Bad inputs however are
148 replaced by Bad right away."""
150 flags = [ "cfopcode", "start_block", "dump_noblock" ]
153 block = "get_irg_start_block(irg)"
155 attr_struct = "bad_attr"
157 res->attr.bad.irg.irg = irg;
161 """Internal node which is temporary set to nodes which are already removed
167 customSerializer = True
176 flags = [ "labeled" ]
177 attr_struct = "block_attr"
178 customSerializer = True
181 res->attr.block.irg.irg = irg;
182 res->attr.block.backedge = new_backedge_arr(irg->obst, arity);
183 set_Block_matured(res, 1);
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*));
193 """Returns the borrow bit from and implied subtractions of its 2 operands"""
197 """Performs a bounds-check: if lower <= index < upper then return index,
198 otherwise throw an exception."""
200 ("mem", "memory dependency"),
201 ("index", "value to test"),
202 ("lower", "lower bound (inclusive)"),
203 ("upper", "upper bound (exclusive)"),
206 ("M", "memory result", "pn_Generic_M"),
207 ("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
208 ("X_except", "control flow when exception occured", "pn_Generic_X_except"),
209 ("res", "the checked index", "pn_Generic_other"),
211 flags = [ "fragile", "highlevel" ]
213 pinned_init = "op_pin_state_pinned"
214 attr_struct = "bound_attr"
218 """performs a backend-specific builtin."""
220 ("mem", "memory dependency"),
224 ("M", "memory result", "pn_Generic_M"),
225 ("1_result", "first result", "pn_Generic_other"),
227 flags = [ "uses_memory" ]
230 type = "ir_builtin_kind",
232 comment = "kind of builtin",
237 comment = "method type for the builtin call",
241 pinned_init = "op_pin_state_pinned"
242 attr_struct = "builtin_attr"
244 assert((get_unknown_type() == type) || is_Method_type(type));
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
253 ("mem", "memory dependency"),
254 ("ptr", "pointer to called code"),
258 ("M", "memory result", "pn_Generic_M"),
259 ("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
260 ("X_except", "control flow when exception occured", "pn_Generic_X_except"),
261 ("T_result", "tuple containing all results", "pn_Generic_other"),
262 ("P_value_res_base", "pointer to memory register containing copied results passed by value"),
264 flags = [ "fragile", "uses_memory" ]
269 comment = "type of the call (usually type of the called procedure)",
274 # the tail call attribute can only be set by analysis
278 attr_struct = "call_attr"
280 pinned_init = "op_pin_state_pinned"
282 assert((get_unknown_type() == type) || is_Method_type(type));
286 """Computes the value of the carry-bit that would result when adding the 2
288 flags = [ "commutative" ]
291 """perform a high-level type cast"""
292 mode = "get_irn_mode(irn_op)"
293 flags = [ "highlevel" ]
298 comment = "target type of the case",
301 attr_struct = "cast_attr"
302 init = "assert(is_atomic_type(type));"
305 """Returns the relation of 2 operands"""
307 ("False", "always false", "0"),
308 ("Eq", "equal", "1"),
310 ("Le", "less or equal", "pn_Cmp_Eq|pn_Cmp_Lt"),
311 ("Gt", "greater", "4"),
312 ("Ge", "greater or equal", "pn_Cmp_Eq|pn_Cmp_Gt"),
313 ("Lg", "less or greater ('not equal' for integer numbers)", "pn_Cmp_Lt|pn_Cmp_Gt"),
314 ("Leg", "less, equal or greater ('not unordered')", "pn_Cmp_Lt|pn_Cmp_Eq|pn_Cmp_Gt"),
315 ("Uo", "unordered", "8"),
316 ("Ue", "unordered or equal", "pn_Cmp_Uo|pn_Cmp_Eq"),
317 ("Ul", "unordered or less", "pn_Cmp_Uo|pn_Cmp_Lt"),
318 ("Ule", "unordered, less or equal", "pn_Cmp_Uo|pn_Cmp_Lt|pn_Cmp_Eq"),
319 ("Ug", "unordered or greater", "pn_Cmp_Uo|pn_Cmp_Gt"),
320 ("Uge", "onordered, greater or equal", "pn_Cmp_Uo|pn_Cmp_Gt|pn_Cmp_Eq"),
321 ("Ne", "unordered, less or greater ('not equal' for floatingpoint numbers)", "pn_Cmp_Uo|pn_Cmp_Lt|pn_Cmp_Gt"),
322 ("True", "always true", "15"),
327 """Conditionally change control flow. There are two versions of this node:
330 Input: A value of mode_b
331 Output: A tuple of two control flows. The first is taken if the input is
332 false, the second if it is true.
335 Input: A value of mode_Iu
336 Output: A tuple of n control flows. If the Cond's input is i, control flow
337 will proceed along output i. If the input is >= n control flow proceeds
338 along output def_proj.
341 ("selector", "condition parameter"),
344 ("false", "control flow if operand is \"false\""),
345 ("true", "control flow if operand is \"true\""),
347 flags = [ "cfopcode", "forking" ]
351 name = "default_proj",
354 comment = "Proj-number of default case for switch-Cond",
358 type = "cond_jmp_predicate",
359 init = "COND_JMP_PRED_NONE",
360 comment = "can indicate the most likely jump",
363 attr_struct = "cond_attr"
366 """Specifies constraints for a value. This allows explicit representation
367 of path-sensitive properties. (Example: This value is always >= 0 on 1
368 if-branch then all users within that branch are rerouted to a confirm-node
369 specifying this property).
371 A constraint is specified for the relation between value and bound.
372 value is always returned.
373 Note that this node does NOT check or assert the constraint, it merely
376 ("value", "value to express a constraint for"),
377 ("bound", "value to compare against"),
379 mode = "get_irn_mode(irn_value)"
380 flags = [ "highlevel" ]
386 comment = "compare operation",
389 attr_struct = "confirm_attr"
390 attrs_name = "confirm"
393 """Returns a constant value."""
394 flags = [ "constlike", "start_block" ]
395 block = "get_irg_start_block(irg)"
396 mode = "get_tarval_mode(tarval)"
403 comment = "constant value (a tarval object)",
406 attr_struct = "const_attr"
410 """Converts values between modes"""
417 comment = "force floating point to restrict precision even if backend computes in higher precision (deprecated)",
420 attr_struct = "conv_attr"
424 """Copies a block of memory"""
426 ("mem", "memory dependency"),
427 ("dst", "destination address"),
428 ("src", "source address"),
431 ("M", "memory result", "pn_Generic_M"),
432 ("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
433 ("X_except", "control flow when exception occured", "pn_Generic_X_except"),
435 flags = [ "fragile", "uses_memory" ]
440 comment = "type of copied data",
443 attr_struct = "copyb_attr"
446 pinned_init = "op_pin_state_pinned"
449 """returns the quotient of its 2 operands"""
451 ("mem", "memory dependency"),
452 ("left", "first operand"),
453 ("right", "second operand"),
456 ("M", "memory result", "pn_Generic_M"),
457 ("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
458 ("X_except", "control flow when exception occured", "pn_Generic_X_except"),
459 ("res", "result of computation", "pn_Generic_other"),
461 flags = [ "fragile", "uses_memory" ]
462 attrs_name = "divmod"
467 comment = "mode of the result value",
470 name = "no_remainder",
475 attr_struct = "divmod_attr"
478 arity_override = "oparity_binary"
481 """A placeholder value. This is used when constructing cyclic graphs where
482 you have cases where not all predecessors of a phi-node are known. Dummy
483 nodes are used for the unknown predecessors and replaced later."""
485 flags = [ "cfopcode", "start_block", "constlike", "dump_noblock" ]
488 block = "get_irg_start_block(irg)"
491 """Last node of a graph. It references nodes in endless loops (so called
496 flags = [ "cfopcode" ]
498 block = "get_irg_end_block(irg)"
500 customSerializer = True
503 """returns the result of a bitwise exclusive or operation of its operands"""
504 flags = [ "commutative" ]
507 """Frees a block of memory previously allocated by an Alloc node"""
509 ("mem", "memory dependency" ),
510 ("ptr", "pointer to the object to free"),
511 ("size", "number of objects to allocate" ),
514 flags = [ "uses_memory" ]
520 comment = "type of the allocated variable",
524 type = "ir_where_alloc",
525 comment = "whether allocation was on the stack or heap",
528 attr_struct = "free_attr"
531 """Returns its operand unchanged."""
533 ("pred", "the value which is returned unchanged")
539 """Jumps to the code in its argument. The code has to be in the same
540 function and the the destination must be one of the blocks reachable
541 by the tuple results"""
545 ("target", "target address of the jump"),
547 flags = [ "cfopcode", "forking", "keep" ]
550 """Tests wether an object is an instance of a class-type"""
552 ("store", "memory dependency"),
553 ("obj", "pointer to object being queried")
556 ("M", "memory result", "pn_Generic_M"),
557 ("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
558 ("X_except", "control flow when exception occured", "pn_Generic_X_except"),
559 ("res", "checked object pointer", "pn_Generic_other"),
561 flags = [ "highlevel" ]
566 comment = "type to check ptr for",
569 attr_struct = "io_attr"
571 pinned_init = "op_pin_state_floats"
574 """Jumps to the block connected through the out-value"""
578 flags = [ "cfopcode" ]
581 """Loads a value from memory (heap or stack)."""
583 ("mem", "memory dependency"),
584 ("ptr", "address to load from"),
587 ("M", "memory result", "pn_Generic_M"),
588 ("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
589 ("X_except", "control flow when exception occured", "pn_Generic_X_except"),
590 ("res", "result of load operation", "pn_Generic_other"),
592 flags = [ "fragile", "uses_memory" ]
598 java_name = "load_mode",
599 comment = "mode of the value to be loaded",
602 attr_struct = "load_attr"
605 type = "ir_cons_flags",
607 comment = "specifies alignment, volatility and pin state",
610 pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
612 res->attr.load.volatility = flags & cons_volatile ? volatility_is_volatile : volatility_non_volatile;
613 res->attr.load.aligned = flags & cons_unaligned ? align_non_aligned : align_is_aligned;
617 """returns the difference between its operands"""
621 """returns the remainder of its operands from an implied division.
624 * mod(5,3) produces 2
625 * mod(5,-3) produces 2
626 * mod(-5,3) produces -2
627 * mod(-5,-3) produces -2
630 ("mem", "memory dependency"),
631 ("left", "first operand"),
632 ("right", "second operand"),
635 ("M", "memory result", "pn_Generic_M"),
636 ("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
637 ("X_except", "control flow when exception occured", "pn_Generic_X_except"),
638 ("res", "result of computation", "pn_Generic_other"),
640 flags = [ "fragile", "uses_memory" ]
641 attrs_name = "divmod"
646 comment = "mode of the result",
649 attr_struct = "divmod_attr"
652 arity_override = "oparity_binary"
655 """returns the product of its operands"""
656 flags = [ "commutative" ]
659 """returns the upper word of the product of its operands (the part which
660 would not fit into the result mode of a normal Mul anymore)"""
661 flags = [ "commutative" ]
664 """returns the false or true operand depending on the value of the sel
667 ("sel", "value making the output selection"),
668 ("false", "selected if sel input is false"),
669 ("true", "selected if sel input is true"),
675 """Placeholder node for cases where you don't need any memory input"""
677 flags = [ "dump_noblock", "dump_noinput" ]
680 block = "get_irg_start_block(irg)"
684 """returns the logical complement of a value. Works for integer values too.
685 If the input is false/zero then true/one is returned, otherwise false/zero
690 """returns the result of a bitwise or operation of its operands"""
691 flags = [ "commutative" ]
694 """Choose a value based on control flow. A phi node has 1 input for each
695 predecessor of its block. If a block is entered from its nth predecessor
696 all phi nodes produce their nth input as result."""
700 attr_struct = "phi_attr"
702 res->attr.phi.u.backedge = new_backedge_arr(irg->obst, arity);'''
704 /* Memory Phis in endless loops must be kept alive.
705 As we can't distinguish these easily we keep all of them alive. */
706 if (is_Phi(res) && mode == mode_M)
707 add_End_keepalive(get_irg_end(irg), res);'''
710 """Pin the value of the node node in the current block. No users of the Pin
711 node can float above the Block of the Pin. The node cannot float behind
712 this block. Often used to Pin the NoMem node."""
714 ("op", "value which is pinned"),
716 mode = "get_irn_mode(irn_op)"
717 flags = [ "highlevel" ]
721 """returns an entry of a tuple value"""
723 ("pred", "the tuple value from which a part is extracted"),
729 block = "get_nodes_block(irn_pred)"
730 graph = "get_irn_irg(irn_pred)"
731 customSerializer = True
736 comment = "number of tuple component to be extracted",
739 attr_struct = "proj_attr"
742 """Raises an exception. Unconditional change of control flow. Writes an
743 explicit Except variable to memory to pass it to the exception handler.
744 Must be lowered to a Call to a runtime check function."""
746 ("mem", "memory dependency"),
747 ("exo_ptr", "pointer to exception object to be thrown"),
750 ("M", "memory result", "pn_Generic_M"),
751 ("X", "control flow to exception handler", "pn_Generic_X_regular"),
753 flags = [ "highlevel", "cfopcode" ]
757 """Returns from the current function. Takes memory and return values as
760 ("mem", "memory dependency"),
764 flags = [ "cfopcode" ]
768 """Returns its first operand bits rotated left by the amount in the 2nd
773 """Computes the address of a entity of a compound type given the base
774 address of an instance of the compound type."""
776 ("mem", "memory dependency"),
777 ("ptr", "pointer to object to select from"),
781 mode = "is_Method_type(get_entity_type(entity)) ? mode_P_code : mode_P_data"
787 comment = "entity which is selected",
790 attr_struct = "sel_attr"
793 """Returns its first operands bits shifted left by the amount of the 2nd
798 """Returns its first operands bits shifted right by the amount of the 2nd
799 operand. No special handling for the sign bit (zero extension)"""
803 """Returns its first operands bits shifted right by the amount of the 2nd
804 operand. The leftmost bit (usually the sign bit) stays the same
809 """The first node of a graph. Execution starts with this node."""
811 ("X_initial_exec", "control flow"),
812 ("M", "initial memory"),
813 ("P_frame_base", "frame base pointer"),
814 ("P_tls", "pointer to thread local storage segment"),
815 ("T_args", "function arguments")
819 flags = [ "cfopcode" ]
822 customSerializer = True
823 block = "get_irg_start_block(irg)"
826 """Stores a value into memory (heap or stack)."""
828 ("mem", "memory dependency"),
829 ("ptr", "address to store to"),
830 ("value", "value to store"),
833 ("M", "memory result", "pn_Generic_M"),
834 ("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
835 ("X_except", "control flow when exception occured", "pn_Generic_X_except"),
837 flags = [ "fragile", "uses_memory" ]
839 attr_struct = "store_attr"
840 pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
843 type = "ir_cons_flags",
845 comment = "specifies alignment, volatility and pin state",
849 res->attr.store.volatility = flags & cons_volatile ? volatility_is_volatile : volatility_non_volatile;
850 res->attr.store.aligned = flags & cons_unaligned ? align_non_aligned : align_is_aligned;
854 """returns the difference of its operands"""
858 """A symbolic constant.
860 - symconst_type_tag The symbolic constant represents a type tag. The
861 type the tag stands for is given explicitly.
862 - symconst_type_size The symbolic constant represents the size of a type.
863 The type of which the constant represents the size
865 - symconst_type_align The symbolic constant represents the alignment of a
866 type. The type of which the constant represents the
867 size is given explicitly.
868 - symconst_addr_ent The symbolic constant represents the address of an
869 entity (variable or method). The variable is given
870 explicitly by a firm entity.
871 - symconst_ofs_ent The symbolic constant represents the offset of an
872 entity in its owner type.
873 - symconst_enum_const The symbolic constant is a enumeration constant of
874 an enumeration type."""
876 flags = [ "constlike", "start_block" ]
884 comment = "entity whose address is returned",
887 attr_struct = "symconst_attr"
888 customSerializer = True
889 # constructor is written manually at the moment, because of the strange
894 """The Sync operation unifies several partial memory blocks. These blocks
895 have to be pairwise disjunct or the values in common locations have to
896 be identical. This operation allows to specify all operations that
897 eventually need several partial memory blocks as input with a single
898 entrance by unifying the memories with a preceding Sync operation."""
905 """Builds a Tuple from single values.
907 This is needed to implement optimizations that remove a node that produced
908 a tuple. The node can be replaced by the Tuple operation so that the
909 following Proj nodes have not to be changed. (They are hard to find due to
910 the implementation with pointers in only one direction.) The Tuple node is
911 smaller than any other node, so that a node can be changed into a Tuple by
912 just changing it's opcode and giving it a new in array."""
916 flags = [ "labeled" ]
919 """Returns an unknown (at compile- and runtime) value. It is a valid
920 optimisation to replace an Unknown by any other constant value."""
923 block = "get_irg_start_block(irg)"
924 flags = [ "cfopcode", "start_block", "constlike", "dump_noblock" ]
928 def getOpList(namespace):
930 for t in namespace.values():
934 if issubclass(t, Op):
939 nodes = getOpList(globals())
940 nodes = sorted(nodes, lambda x,y: cmp(x.name, y.name))