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"),
42 ("X_regular", "control flow when no exception occurs"),
43 ("X_except", "control flow when exception occured"),
44 ("res", "pointer to newly allocated memory"),
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 pinned_init = "op_pin_state_pinned"
61 attr_struct = "alloc_attr"
64 """utiliy node used to "hold" nodes in a graph that might possibly not be
65 reachable by other means or which should be reachable immediately without
66 searching through the graph.
67 Each firm-graph contains exactly one anchor node whose address is always
68 known. All other well-known graph-nodes like Start, End, NoMem, Bad, ...
69 are found by looking at the respective Anchor operand."""
72 flags = [ "dump_noblock" ]
74 attr_struct = "irg_attr"
78 customSerializer = True
81 """returns the result of a bitwise and operation of its operands"""
82 flags = [ "commutative" ]
85 """executes assembler fragments of the target machine"""
88 flags = [ "keep", "uses_memory" ]
90 pinned_init = "op_pin_state_pinned"
91 attr_struct = "asm_attr"
93 customSerializer = True
96 name = "input_constraints",
97 type = "ir_asm_constraint*",
98 comment = "input constraints",
101 name = "n_output_constraints",
104 comment = "number of output constraints",
107 name = "output_constraints",
108 type = "ir_asm_constraint*",
109 comment = "output constraints",
115 comment = "number of clobbered registers/memory",
120 comment = "list of clobbered registers/memory",
125 comment = "assembler text",
128 # constructor is written manually at the moment, because of the clobbers+
129 # constraints arrays needing special handling (2 arguments for 1 attribute)
133 """Bad nodes indicate invalid input, which is values which should never be
136 The typical use case for the Bad node is removing unreachable code.
137 Frontends should set the current_block to Bad when it is clear that
138 following code must be unreachable (ie. after a goto or return statement).
139 Optimisations also set block predecessors to Bad when it becomes clear,
140 that a control flow edge can never be executed.
142 The gigo optimisations ensures that nodes with Bad as their block, get
143 replaced by Bad themselfes. Nodes with at least 1 Bad input get exchanged
144 with Bad too. Exception to this rule are Block, Phi, Tuple and End node;
145 This is because removing inputs from a Block is hairy operation (requiring,
146 Phis to be shortened too for example). So instead of removing block inputs
147 they are set to Bad, and the actual removal is left to the control flow
148 optimisation phase. Block, Phi, Tuple with only Bad inputs however are
149 replaced by Bad right away."""
150 flags = [ "start_block", "dump_noblock" ]
153 block = "get_irg_start_block(irg)"
154 attr_struct = "bad_attr"
156 res->attr.bad.irg.irg = irg;
160 """Internal node which is temporary set to nodes which are already removed
166 customSerializer = True
175 flags = [ "labeled" ]
176 attr_struct = "block_attr"
177 customSerializer = True
180 res->attr.block.irg.irg = irg;
181 res->attr.block.backedge = new_backedge_arr(irg->obst, arity);
182 set_Block_matured(res, 1);
184 /* Create and initialize array for Phi-node construction. */
185 if (get_irg_phase_state(irg) == phase_building) {
186 res->attr.block.graph_arr = NEW_ARR_D(ir_node *, irg->obst, irg->n_loc);
187 memset(res->attr.block.graph_arr, 0, irg->n_loc * sizeof(ir_node*));
192 """Returns the borrow bit from and implied subtractions of its 2 operands"""
196 """Performs a bounds-check: if lower <= index < upper then return index,
197 otherwise throw an exception."""
199 ("mem", "memory dependency"),
200 ("index", "value to test"),
201 ("lower", "lower bound (inclusive)"),
202 ("upper", "upper bound (exclusive)"),
205 ("M", "memory result"),
206 ("X_regular", "control flow when no exception occurs"),
207 ("X_except", "control flow when exception occured"),
208 ("res", "the checked index"),
210 flags = [ "fragile", "highlevel" ]
212 pinned_init = "op_pin_state_pinned"
213 attr_struct = "bound_attr"
217 """performs a backend-specific builtin."""
219 ("mem", "memory dependency"),
223 ("M", "memory result"),
224 ("1_result", "first result"),
226 flags = [ "uses_memory" ]
229 type = "ir_builtin_kind",
231 comment = "kind of builtin",
236 comment = "method type for the builtin call",
240 pinned_init = "op_pin_state_pinned"
241 attr_struct = "builtin_attr"
243 assert((get_unknown_type() == type) || is_Method_type(type));
247 """Calls other code. Control flow is transfered to ptr, additional
248 operands are passed to the called code. Called code usually performs a
249 return operation. The operands of this return operation are the result
252 ("mem", "memory dependency"),
253 ("ptr", "pointer to called code"),
257 ("M", "memory result"),
258 ("X_regular", "control flow when no exception occurs"),
259 ("X_except", "control flow when exception occured"),
260 ("T_result", "tuple containing all results"),
262 flags = [ "fragile", "uses_memory" ]
267 comment = "type of the call (usually type of the called procedure)",
272 # the tail call attribute can only be set by analysis
276 attr_struct = "call_attr"
278 pinned_init = "op_pin_state_pinned"
280 assert((get_unknown_type() == type) || is_Method_type(type));
284 """Computes the value of the carry-bit that would result when adding the 2
286 flags = [ "commutative" ]
289 """perform a high-level type cast"""
290 mode = "get_irn_mode(irn_op)"
291 flags = [ "highlevel" ]
296 comment = "target type of the case",
299 attr_struct = "cast_attr"
300 init = "assert(is_atomic_type(type));"
303 """Compares its two operands and checks whether a specified
304 relation (like less or equal) is fulfilled."""
309 type = "ir_relation",
311 comment = "Comparison relation"
314 attr_struct = "cmp_attr"
317 """Conditionally change control flow. There are two versions of this node:
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.
325 Input: A value of mode_Iu
326 Output: A tuple of n control flows. If the Cond's input is i, control flow
327 will proceed along output i. If the input is >= n control flow proceeds
328 along output def_proj.
331 ("selector", "condition parameter"),
334 ("false", "control flow if operand is \"false\""),
335 ("true", "control flow if operand is \"true\""),
337 flags = [ "cfopcode", "forking" ]
341 name = "default_proj",
344 comment = "Proj-number of default case for switch-Cond",
348 type = "cond_jmp_predicate",
349 init = "COND_JMP_PRED_NONE",
350 comment = "can indicate the most likely jump",
353 attr_struct = "cond_attr"
356 """Specifies constraints for a value. This allows explicit representation
357 of path-sensitive properties. (Example: This value is always >= 0 on 1
358 if-branch then all users within that branch are rerouted to a confirm-node
359 specifying this property).
361 A constraint is specified for the relation between value and bound.
362 value is always returned.
363 Note that this node does NOT check or assert the constraint, it merely
366 ("value", "value to express a constraint for"),
367 ("bound", "value to compare against"),
369 mode = "get_irn_mode(irn_value)"
370 flags = [ "highlevel" ]
375 type = "ir_relation",
376 comment = "relation of value to bound",
379 attr_struct = "confirm_attr"
380 attrs_name = "confirm"
383 """Returns a constant value."""
384 flags = [ "constlike", "start_block" ]
385 block = "get_irg_start_block(irg)"
386 mode = "get_tarval_mode(tarval)"
393 comment = "constant value (a tarval object)",
396 attr_struct = "const_attr"
400 """Converts values between modes"""
407 comment = "force floating point to restrict precision even if backend computes in higher precision (deprecated)",
410 attr_struct = "conv_attr"
414 """Copies a block of memory"""
416 ("mem", "memory dependency"),
417 ("dst", "destination address"),
418 ("src", "source address"),
421 ("M", "memory result"),
422 ("X_regular", "control flow when no exception occurs"),
423 ("X_except", "control flow when exception occured"),
425 flags = [ "fragile", "uses_memory" ]
430 comment = "type of copied data",
433 attr_struct = "copyb_attr"
436 pinned_init = "op_pin_state_pinned"
439 """returns the quotient of its 2 operands"""
441 ("mem", "memory dependency"),
442 ("left", "first operand"),
443 ("right", "second operand"),
446 ("M", "memory result"),
447 ("X_regular", "control flow when no exception occurs"),
448 ("X_except", "control flow when exception occured"),
449 ("res", "result of computation"),
451 flags = [ "fragile", "uses_memory" ]
457 comment = "mode of the result value",
460 name = "no_remainder",
465 attr_struct = "div_attr"
468 arity_override = "oparity_binary"
471 """A placeholder value. This is used when constructing cyclic graphs where
472 you have cases where not all predecessors of a phi-node are known. Dummy
473 nodes are used for the unknown predecessors and replaced later."""
475 flags = [ "cfopcode", "start_block", "constlike", "dump_noblock" ]
478 block = "get_irg_start_block(irg)"
481 """Last node of a graph. It references nodes in endless loops (so called
486 flags = [ "cfopcode" ]
488 block = "get_irg_end_block(irg)"
490 customSerializer = True
493 """returns the result of a bitwise exclusive or operation of its operands"""
494 flags = [ "commutative" ]
497 """Frees a block of memory previously allocated by an Alloc node"""
499 ("mem", "memory dependency" ),
500 ("ptr", "pointer to the object to free"),
501 ("size", "number of objects to allocate" ),
504 flags = [ "uses_memory" ]
510 comment = "type of the allocated variable",
514 type = "ir_where_alloc",
515 comment = "whether allocation was on the stack or heap",
518 attr_struct = "free_attr"
521 """Returns its operand unchanged."""
523 ("pred", "the value which is returned unchanged")
529 """Jumps to the code in its argument. The code has to be in the same
530 function and the the destination must be one of the blocks reachable
531 by the tuple results"""
535 ("target", "target address of the jump"),
537 flags = [ "cfopcode", "forking", "keep", "unknown_jump" ]
540 """Tests whether an object is an instance of a class-type"""
542 ("store", "memory dependency"),
543 ("obj", "pointer to object being queried")
546 ("M", "memory result"),
547 ("X_regular", "control flow when no exception occurs"),
548 ("X_except", "control flow when exception occured"),
549 ("res", "checked object pointer"),
551 flags = [ "highlevel" ]
556 comment = "type to check ptr for",
559 attr_struct = "io_attr"
561 pinned_init = "op_pin_state_floats"
564 """Jumps to the block connected through the out-value"""
568 flags = [ "cfopcode" ]
571 """Loads a value from memory (heap or stack)."""
573 ("mem", "memory dependency"),
574 ("ptr", "address to load from"),
577 ("M", "memory result"),
578 ("X_regular", "control flow when no exception occurs"),
579 ("X_except", "control flow when exception occured"),
580 ("res", "result of load operation"),
582 flags = [ "fragile", "uses_memory" ]
588 comment = "mode of the value to be loaded",
591 type = "ir_volatility",
593 comment = "volatile loads are a visible side-effect and may not be optimized",
594 init = "flags & cons_volatile ? volatility_is_volatile : volatility_non_volatile",
599 comment = "pointers to unaligned loads don't need to respect the load-mode/type alignments",
600 init = "flags & cons_unaligned ? align_non_aligned : align_is_aligned",
603 attr_struct = "load_attr"
606 type = "ir_cons_flags",
608 comment = "specifies alignment, volatility and pin state",
611 pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
614 """returns the difference between its operands"""
618 """returns the remainder of its operands from an implied division.
621 * mod(5,3) produces 2
622 * mod(5,-3) produces 2
623 * mod(-5,3) produces -2
624 * mod(-5,-3) produces -2
627 ("mem", "memory dependency"),
628 ("left", "first operand"),
629 ("right", "second operand"),
632 ("M", "memory result"),
633 ("X_regular", "control flow when no exception occurs"),
634 ("X_except", "control flow when exception occured"),
635 ("res", "result of computation"),
637 flags = [ "fragile", "uses_memory" ]
643 comment = "mode of the result",
646 attr_struct = "mod_attr"
649 arity_override = "oparity_binary"
652 """returns the product of its operands"""
653 flags = [ "commutative" ]
656 """returns the upper word of the product of its operands (the part which
657 would not fit into the result mode of a normal Mul anymore)"""
658 flags = [ "commutative" ]
661 """returns the false or true operand depending on the value of the sel
664 ("sel", "value making the output selection"),
665 ("false", "selected if sel input is false"),
666 ("true", "selected if sel input is true"),
672 """Placeholder node for cases where you don't need any memory input"""
674 flags = [ "dump_noblock", "dump_noinput" ]
677 block = "get_irg_start_block(irg)"
681 """returns the logical complement of a value. Works for integer values too.
682 If the input is false/zero then true/one is returned, otherwise false/zero
687 """returns the result of a bitwise or operation of its operands"""
688 flags = [ "commutative" ]
691 """Choose a value based on control flow. A phi node has 1 input for each
692 predecessor of its block. If a block is entered from its nth predecessor
693 all phi nodes produce their nth input as result."""
697 attr_struct = "phi_attr"
699 res->attr.phi.u.backedge = new_backedge_arr(irg->obst, arity);'''
701 /* Memory Phis in endless loops must be kept alive.
702 As we can't distinguish these easily we keep all of them alive. */
703 if (is_Phi(res) && mode == mode_M)
704 add_End_keepalive(get_irg_end(irg), res);'''
707 """Pin the value of the node node in the current block. No users of the Pin
708 node can float above the Block of the Pin. The node cannot float behind
709 this block. Often used to Pin the NoMem node."""
711 ("op", "value which is pinned"),
713 mode = "get_irn_mode(irn_op)"
714 flags = [ "highlevel" ]
718 """returns an entry of a tuple value"""
720 ("pred", "the tuple value from which a part is extracted"),
726 block = "get_nodes_block(irn_pred)"
727 graph = "get_irn_irg(irn_pred)"
728 customSerializer = True
733 comment = "number of tuple component to be extracted",
736 attr_struct = "proj_attr"
739 """Raises an exception. Unconditional change of control flow. Writes an
740 explicit Except variable to memory to pass it to the exception handler.
741 Must be lowered to a Call to a runtime check function."""
743 ("mem", "memory dependency"),
744 ("exo_ptr", "pointer to exception object to be thrown"),
747 ("M", "memory result"),
748 ("X", "control flow to exception handler"),
750 flags = [ "highlevel", "cfopcode" ]
754 """Returns from the current function. Takes memory and return values as
757 ("mem", "memory dependency"),
761 flags = [ "cfopcode" ]
765 """Returns its first operand bits rotated left by the amount in the 2nd
770 """Computes the address of a entity of a compound type given the base
771 address of an instance of the compound type."""
773 ("mem", "memory dependency"),
774 ("ptr", "pointer to object to select from"),
778 mode = "is_Method_type(get_entity_type(entity)) ? mode_P_code : mode_P_data"
784 comment = "entity which is selected",
787 attr_struct = "sel_attr"
790 """Returns its first operands bits shifted left by the amount of the 2nd
795 """Returns its first operands bits shifted right by the amount of the 2nd
796 operand. No special handling for the sign bit (zero extension)"""
800 """Returns its first operands bits shifted right by the amount of the 2nd
801 operand. The leftmost bit (usually the sign bit) stays the same
806 """The first node of a graph. Execution starts with this node."""
808 ("X_initial_exec", "control flow"),
809 ("M", "initial memory"),
810 ("P_frame_base", "frame base pointer"),
811 ("T_args", "function arguments")
815 flags = [ "cfopcode" ]
818 customSerializer = True
819 block = "get_irg_start_block(irg)"
822 """Stores a value into memory (heap or stack)."""
824 ("mem", "memory dependency"),
825 ("ptr", "address to store to"),
826 ("value", "value to store"),
829 ("M", "memory result"),
830 ("X_regular", "control flow when no exception occurs"),
831 ("X_except", "control flow when exception occured"),
833 flags = [ "fragile", "uses_memory" ]
835 attr_struct = "store_attr"
836 pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
839 type = "ir_volatility",
841 comment = "volatile stores are a visible side-effect and may not be optimized",
842 init = "flags & cons_volatile ? volatility_is_volatile : volatility_non_volatile",
847 comment = "pointers to unaligned stores don't need to respect the load-mode/type alignments",
848 init = "flags & cons_unaligned ? align_non_aligned : align_is_aligned",
853 type = "ir_cons_flags",
855 comment = "specifies alignment, volatility and pin state",
860 """returns the difference of its operands"""
864 """A symbolic constant.
866 - symconst_type_tag The symbolic constant represents a type tag. The
867 type the tag stands for is given explicitly.
868 - symconst_type_size The symbolic constant represents the size of a type.
869 The type of which the constant represents the size
871 - symconst_type_align The symbolic constant represents the alignment of a
872 type. The type of which the constant represents the
873 size is given explicitly.
874 - symconst_addr_ent The symbolic constant represents the address of an
875 entity (variable or method). The variable is given
876 explicitly by a firm entity.
877 - symconst_ofs_ent The symbolic constant represents the offset of an
878 entity in its owner type.
879 - symconst_enum_const The symbolic constant is a enumeration constant of
880 an enumeration type."""
882 flags = [ "constlike", "start_block" ]
890 comment = "entity whose address is returned",
893 attr_struct = "symconst_attr"
894 customSerializer = True
895 # constructor is written manually at the moment, because of the strange
900 """The Sync operation unifies several partial memory blocks. These blocks
901 have to be pairwise disjunct or the values in common locations have to
902 be identical. This operation allows to specify all operations that
903 eventually need several partial memory blocks as input with a single
904 entrance by unifying the memories with a preceding Sync operation."""
911 """Builds a Tuple from single values.
913 This is needed to implement optimizations that remove a node that produced
914 a tuple. The node can be replaced by the Tuple operation so that the
915 following Proj nodes have not to be changed. (They are hard to find due to
916 the implementation with pointers in only one direction.) The Tuple node is
917 smaller than any other node, so that a node can be changed into a Tuple by
918 just changing its opcode and giving it a new in array."""
922 flags = [ "labeled" ]
925 """Returns an unknown (at compile- and runtime) value. It is a valid
926 optimisation to replace an Unknown by any other constant value."""
929 block = "get_irg_start_block(irg)"
930 flags = [ "start_block", "constlike", "dump_noblock" ]
934 def getOpList(namespace):
936 for t in namespace.values():
940 if issubclass(t, Op):
945 nodes = getOpList(globals())
946 nodes = sorted(nodes, lambda x,y: cmp(x.name, y.name))