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 memory should be allocated to the stack
36 Allocates memory for one or more objects (depending on value on count input).
39 ("mem", "memory dependency" ),
40 ("count", "number of objects to allocate" ),
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"),
52 comment = "type of the objects to allocate",
56 type = "ir_where_alloc",
57 comment = "whether to allocate the variable on the stack or heap",
60 flags = [ "fragile", "uses_memory" ]
63 pinned_init = "op_pin_state_pinned"
64 attr_struct = "alloc_attr"
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."""
75 flags = [ "dump_noblock" ]
77 attr_struct = "irg_attr"
81 customSerializer = True
84 """returns the result of a bitwise and operation of its operands"""
85 flags = [ "commutative" ]
88 """executes assembler fragments of the target machine"""
91 flags = [ "keep", "uses_memory" ]
93 pinned_init = "op_pin_state_pinned"
94 attr_struct = "asm_attr"
96 customSerializer = True
98 ("mem", "memory dependency"),
102 name = "input_constraints",
103 type = "ir_asm_constraint*",
104 comment = "input constraints",
107 name = "n_output_constraints",
110 comment = "number of output constraints",
113 name = "output_constraints",
114 type = "ir_asm_constraint*",
115 comment = "output constraints",
121 comment = "number of clobbered registers/memory",
126 comment = "list of clobbered registers/memory",
131 comment = "assembler text",
134 # constructor is written manually at the moment, because of the clobbers+
135 # constraints arrays needing special handling (2 arguments for 1 attribute)
139 """Bad nodes indicate invalid input, which is values which should never be
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.
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" ]
159 block = "get_irg_start_block(irg)"
160 attr_struct = "bad_attr"
162 res->attr.bad.irg.irg = irg;
166 """Internal node which is temporary set to nodes which are already removed
172 customSerializer = True # this has no serializer
182 attr_struct = "block_attr"
187 comment = "entity representing this block",
191 customSerializer = True
194 res->attr.block.irg.irg = irg;
195 res->attr.block.backedge = new_backedge_arr(irg->obst, arity);
196 set_Block_matured(res, 1);
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*));
206 """Returns the borrow bit from and implied subtractions of its 2 operands"""
210 """Performs a bounds-check: if lower <= index < upper then return index,
211 otherwise throw an exception."""
213 ("mem", "memory dependency"),
214 ("index", "value to test"),
215 ("lower", "lower bound (inclusive)"),
216 ("upper", "upper bound (exclusive)"),
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"),
224 flags = [ "fragile", "highlevel" ]
226 pinned_init = "op_pin_state_pinned"
227 throws_init = "false"
228 attr_struct = "bound_attr"
231 """performs a backend-specific builtin."""
233 ("mem", "memory dependency"),
237 ("M", "memory result"),
238 # results follow here
240 flags = [ "uses_memory" ]
243 type = "ir_builtin_kind",
245 comment = "kind of builtin",
250 comment = "method type for the builtin call",
254 pinned_init = "op_pin_state_pinned"
255 attr_struct = "builtin_attr"
257 assert((get_unknown_type() == type) || is_Method_type(type));
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
266 ("mem", "memory dependency"),
267 ("ptr", "pointer to called code"),
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"),
276 flags = [ "fragile", "uses_memory" ]
281 comment = "type of the call (usually type of the called procedure)",
284 attr_struct = "call_attr"
286 pinned_init = "op_pin_state_pinned"
287 throws_init = "false"
289 assert((get_unknown_type() == type) || is_Method_type(type));
293 """Computes the value of the carry-bit that would result when adding the 2
295 flags = [ "commutative" ]
298 """perform a high-level type cast"""
299 mode = "get_irn_mode(irn_op)"
300 flags = [ "highlevel" ]
305 comment = "target type of the case",
308 attr_struct = "cast_attr"
309 init = "assert(is_atomic_type(type));"
312 """Compares its two operands and checks whether a specified
313 relation (like less or equal) is fulfilled."""
318 type = "ir_relation",
320 comment = "Comparison relation"
323 attr_struct = "cmp_attr"
326 """Conditionally change control flow."""
328 ("selector", "condition parameter"),
331 ("false", "control flow if operand is \"false\""),
332 ("true", "control flow if operand is \"true\""),
334 flags = [ "cfopcode", "forking" ]
339 type = "cond_jmp_predicate",
340 init = "COND_JMP_PRED_NONE",
341 comment = "can indicate the most likely jump",
344 attr_struct = "cond_attr"
347 """Change control flow. The destination is choosen based on an integer input value which is looked up in a table.
349 Backends can implement this efficiently using a jump table."""
351 ("selector", "input selector"),
354 ("default", "control flow if no other case matches"),
356 flags = [ "cfopcode", "forking" ]
362 comment = "number of outputs (including pn_Switch_default)",
366 type = "ir_switch_table*",
367 comment = "table describing mapping from input values to Proj numbers",
370 attr_struct = "switch_attr"
371 attrs_name = "switcha"
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).
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
384 ("value", "value to express a constraint for"),
385 ("bound", "value to compare against"),
387 mode = "get_irn_mode(irn_value)"
388 flags = [ "highlevel" ]
393 type = "ir_relation",
394 comment = "relation of value to bound",
397 attr_struct = "confirm_attr"
400 """Returns a constant value."""
401 flags = [ "constlike", "start_block" ]
402 block = "get_irg_start_block(irg)"
403 mode = "get_tarval_mode(tarval)"
410 comment = "constant value (a tarval object)",
413 attr_struct = "const_attr"
417 """Converts values between modes"""
424 comment = "force floating point to restrict precision even if backend computes in higher precision (deprecated)",
427 attr_struct = "conv_attr"
430 """Copies a block of memory with statically known size/type."""
432 ("mem", "memory dependency"),
433 ("dst", "destination address"),
434 ("src", "source address"),
437 ("M", "memory result"),
438 ("X_regular", "control flow when no exception occurs"),
439 ("X_except", "control flow when exception occured"),
441 flags = [ "fragile", "uses_memory" ]
446 comment = "type of copied data",
449 attr_struct = "copyb_attr"
451 pinned_init = "op_pin_state_pinned"
452 throws_init = "false"
455 """returns the quotient of its 2 operands"""
457 ("mem", "memory dependency"),
458 ("left", "first operand"),
459 ("right", "second operand"),
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"),
467 flags = [ "fragile", "uses_memory" ]
472 comment = "mode of the result value",
475 name = "no_remainder",
480 attr_struct = "div_attr"
482 throws_init = "false"
484 arity_override = "oparity_binary"
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."""
491 flags = [ "cfopcode", "start_block", "constlike", "dump_noblock" ]
494 block = "get_irg_start_block(irg)"
497 """Last node of a graph. It references nodes in endless loops (so called
502 flags = [ "cfopcode" ]
504 block = "get_irg_end_block(irg)"
508 """returns the result of a bitwise exclusive or operation of its operands.
510 This is also known as the Xor operation."""
511 flags = [ "commutative" ]
514 """Frees a block of memory previously allocated by an Alloc node"""
516 ("mem", "memory dependency" ),
517 ("ptr", "pointer to the object to free"),
518 ("count", "number of objects to allocate" ),
521 flags = [ "uses_memory" ]
527 comment = "type of the allocated variable",
531 type = "ir_where_alloc",
532 comment = "whether allocation was on the stack or heap",
535 attr_struct = "free_attr"
538 """Returns its operand unchanged.
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."""
543 ("pred", "the value which is returned unchanged")
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"""
555 ("target", "target address of the jump"),
557 flags = [ "cfopcode", "forking", "keep", "unknown_jump" ]
560 """Tests whether an object is an instance of a class-type"""
562 ("store", "memory dependency"),
563 ("obj", "pointer to object being queried")
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"),
571 flags = [ "highlevel" ]
576 comment = "type to check ptr for",
579 attr_struct = "io_attr"
581 pinned_init = "op_pin_state_floats"
584 """Jumps to the block connected through the out-value"""
588 flags = [ "cfopcode" ]
591 """Loads a value from memory (heap or stack)."""
593 ("mem", "memory dependency"),
594 ("ptr", "address to load from"),
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"),
602 flags = [ "fragile", "uses_memory" ]
608 comment = "mode of the value to be loaded",
611 type = "ir_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 : 0"
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 : 0"
625 attr_struct = "load_attr"
628 type = "ir_cons_flags",
630 comment = "specifies alignment, volatility and pin state",
633 pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
634 throws_init = "(flags & cons_throws_exception) != 0"
637 """returns the difference between its operands"""
641 """returns the remainder of its operands from an implied division.
645 * mod(5,3) produces 2
646 * mod(5,-3) produces 2
647 * mod(-5,3) produces -2
648 * mod(-5,-3) produces -2
651 ("mem", "memory dependency"),
652 ("left", "first operand"),
653 ("right", "second operand"),
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"),
661 flags = [ "fragile", "uses_memory" ]
666 comment = "mode of the result",
669 attr_struct = "mod_attr"
671 throws_init = "false"
673 arity_override = "oparity_binary"
676 """returns the product of its operands"""
677 flags = [ "commutative" ]
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" ]
685 """returns the false or true operand depending on the value of the sel
688 ("sel", "value making the output selection"),
689 ("false", "selected if sel input is false"),
690 ("true", "selected if sel input is true"),
696 """Placeholder node for cases where you don't need any memory input"""
698 flags = [ "dump_noblock" ]
701 block = "get_irg_start_block(irg)"
705 """returns the bitwise complement of a value. Works for boolean values, too."""
709 """returns the result of a bitwise or operation of its operands"""
710 flags = [ "commutative" ]
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."""
719 attr_struct = "phi_attr"
721 res->attr.phi.u.backedge = new_backedge_arr(irg->obst, arity);'''
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
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."""
734 ("op", "value which is pinned"),
736 mode = "get_irn_mode(irn_op)"
737 flags = [ "highlevel" ]
741 """returns an entry of a tuple value"""
743 ("pred", "the tuple value from which a part is extracted"),
749 block = "get_nodes_block(irn_pred)"
750 graph = "get_irn_irg(irn_pred)"
755 comment = "number of tuple component to be extracted",
758 attr_struct = "proj_attr"
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."""
765 ("mem", "memory dependency"),
766 ("exo_ptr", "pointer to exception object to be thrown"),
769 ("M", "memory result"),
770 ("X", "control flow to exception handler"),
772 flags = [ "highlevel", "cfopcode" ]
776 """Returns from the current function. Takes memory and return values as
779 ("mem", "memory dependency"),
783 flags = [ "cfopcode" ]
787 """Returns its first operand bits rotated left by the amount in the 2nd
792 """Computes the address of a entity of a compound type given the base
793 address of an instance of the compound type.
795 Optimisations assume that a Sel node can only produce a NULL pointer if the
796 ptr input was NULL."""
798 ("mem", "memory dependency"),
799 ("ptr", "pointer to object to select from"),
803 mode = "is_Method_type(get_entity_type(entity)) ? mode_P_code : mode_P_data"
809 comment = "entity which is selected",
812 attr_struct = "sel_attr"
815 """Returns its first operands bits shifted left by the amount of the 2nd
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."""
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."""
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
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."""
840 """The first node of a graph. Execution starts with this node."""
842 ("X_initial_exec", "control flow"),
843 ("M", "initial memory"),
844 ("P_frame_base", "frame base pointer"),
845 ("T_args", "function arguments")
849 flags = [ "cfopcode" ]
852 block = "get_irg_start_block(irg)"
855 """Stores a value into memory (heap or stack)."""
857 ("mem", "memory dependency"),
858 ("ptr", "address to store to"),
859 ("value", "value to store"),
862 ("M", "memory result"),
863 ("X_regular", "control flow when no exception occurs"),
864 ("X_except", "control flow when exception occured"),
866 flags = [ "fragile", "uses_memory" ]
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"
873 type = "ir_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 : 0"
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 : 0"
889 type = "ir_cons_flags",
891 comment = "specifies alignment, volatility and pin state",
896 """returns the difference of its operands"""
900 """A symbolic constant.
902 - *symconst_type_size* The symbolic constant represents the size of a type.
903 The type of which the constant represents the size
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."""
916 flags = [ "constlike", "start_block" ]
924 comment = "entity whose address is returned",
927 attr_struct = "symconst_attr"
928 customSerializer = True
929 # constructor is written manually at the moment, because of the strange
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."""
945 """Builds a Tuple from single values.
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."""
959 """Returns an unknown (at compile- and runtime) value. It is a valid
960 optimisation to replace an Unknown by any other constant value."""
963 block = "get_irg_start_block(irg)"
964 flags = [ "start_block", "constlike", "dump_noblock" ]
968 def getOpList(namespace):
970 for t in namespace.values():
974 if issubclass(t, Op):
979 nodes = getOpList(globals())
980 nodes = sorted(nodes, lambda x,y: cmp(x.name, y.name))