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 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."""
149 flags = [ "start_block", "dump_noblock" ]
152 block = "get_irg_start_block(irg)"
153 attr_struct = "bad_attr"
155 res->attr.bad.irg.irg = irg;
159 """Internal node which is temporary set to nodes which are already removed
165 customSerializer = True
174 flags = [ "labeled" ]
175 attr_struct = "block_attr"
176 customSerializer = True
179 res->attr.block.irg.irg = irg;
180 res->attr.block.backedge = new_backedge_arr(irg->obst, arity);
181 set_Block_matured(res, 1);
183 /* Create and initialize array for Phi-node construction. */
184 if (get_irg_phase_state(irg) == phase_building) {
185 res->attr.block.graph_arr = NEW_ARR_D(ir_node *, irg->obst, irg->n_loc);
186 memset(res->attr.block.graph_arr, 0, irg->n_loc * sizeof(ir_node*));
191 """Returns the borrow bit from and implied subtractions of its 2 operands"""
195 """Performs a bounds-check: if lower <= index < upper then return index,
196 otherwise throw an exception."""
198 ("mem", "memory dependency"),
199 ("index", "value to test"),
200 ("lower", "lower bound (inclusive)"),
201 ("upper", "upper bound (exclusive)"),
204 ("M", "memory result"),
205 ("X_regular", "control flow when no exception occurs"),
206 ("X_except", "control flow when exception occured"),
207 ("res", "the checked index"),
209 flags = [ "fragile", "highlevel" ]
211 pinned_init = "op_pin_state_pinned"
212 attr_struct = "bound_attr"
216 """performs a backend-specific builtin."""
218 ("mem", "memory dependency"),
222 ("M", "memory result"),
223 ("1_result", "first result"),
225 flags = [ "uses_memory" ]
228 type = "ir_builtin_kind",
230 comment = "kind of builtin",
235 comment = "method type for the builtin call",
239 pinned_init = "op_pin_state_pinned"
240 attr_struct = "builtin_attr"
242 assert((get_unknown_type() == type) || is_Method_type(type));
246 """Calls other code. Control flow is transfered to ptr, additional
247 operands are passed to the called code. Called code usually performs a
248 return operation. The operands of this return operation are the result
251 ("mem", "memory dependency"),
252 ("ptr", "pointer to called code"),
256 ("M", "memory result"),
257 ("X_regular", "control flow when no exception occurs"),
258 ("X_except", "control flow when exception occured"),
259 ("T_result", "tuple containing all results"),
261 flags = [ "fragile", "uses_memory" ]
266 comment = "type of the call (usually type of the called procedure)",
271 # the tail call attribute can only be set by analysis
275 attr_struct = "call_attr"
277 pinned_init = "op_pin_state_pinned"
279 assert((get_unknown_type() == type) || is_Method_type(type));
283 """Computes the value of the carry-bit that would result when adding the 2
285 flags = [ "commutative" ]
288 """perform a high-level type cast"""
289 mode = "get_irn_mode(irn_op)"
290 flags = [ "highlevel" ]
295 comment = "target type of the case",
298 attr_struct = "cast_attr"
299 init = "assert(is_atomic_type(type));"
302 """Compares its two operands and checks whether a specified
303 relation (like less or equal) is fulfilled."""
308 type = "ir_relation",
310 comment = "Comparison relation"
313 attr_struct = "cmp_attr"
316 """Conditionally change control flow. There are two versions of this node:
319 Input: A value of mode_b
320 Output: A tuple of two control flows. The first is taken if the input is
321 false, the second if it is true.
324 Input: A value of mode_Iu
325 Output: A tuple of n control flows. If the Cond's input is i, control flow
326 will proceed along output i. If the input is >= n control flow proceeds
327 along output def_proj.
330 ("selector", "condition parameter"),
333 ("false", "control flow if operand is \"false\""),
334 ("true", "control flow if operand is \"true\""),
336 flags = [ "cfopcode", "forking" ]
340 name = "default_proj",
343 comment = "Proj-number of default case for switch-Cond",
347 type = "cond_jmp_predicate",
348 init = "COND_JMP_PRED_NONE",
349 comment = "can indicate the most likely jump",
352 attr_struct = "cond_attr"
355 """Specifies constraints for a value. This allows explicit representation
356 of path-sensitive properties. (Example: This value is always >= 0 on 1
357 if-branch then all users within that branch are rerouted to a confirm-node
358 specifying this property).
360 A constraint is specified for the relation between value and bound.
361 value is always returned.
362 Note that this node does NOT check or assert the constraint, it merely
365 ("value", "value to express a constraint for"),
366 ("bound", "value to compare against"),
368 mode = "get_irn_mode(irn_value)"
369 flags = [ "highlevel" ]
374 type = "ir_relation",
375 comment = "relation of value to bound",
378 attr_struct = "confirm_attr"
379 attrs_name = "confirm"
382 """Returns a constant value."""
383 flags = [ "constlike", "start_block" ]
384 block = "get_irg_start_block(irg)"
385 mode = "get_tarval_mode(tarval)"
392 comment = "constant value (a tarval object)",
395 attr_struct = "const_attr"
399 """Converts values between modes"""
406 comment = "force floating point to restrict precision even if backend computes in higher precision (deprecated)",
409 attr_struct = "conv_attr"
413 """Copies a block of memory"""
415 ("mem", "memory dependency"),
416 ("dst", "destination address"),
417 ("src", "source address"),
420 ("M", "memory result"),
421 ("X_regular", "control flow when no exception occurs"),
422 ("X_except", "control flow when exception occured"),
424 flags = [ "fragile", "uses_memory" ]
429 comment = "type of copied data",
432 attr_struct = "copyb_attr"
435 pinned_init = "op_pin_state_pinned"
438 """returns the quotient of its 2 operands"""
440 ("mem", "memory dependency"),
441 ("left", "first operand"),
442 ("right", "second operand"),
445 ("M", "memory result"),
446 ("X_regular", "control flow when no exception occurs"),
447 ("X_except", "control flow when exception occured"),
448 ("res", "result of computation"),
450 flags = [ "fragile", "uses_memory" ]
456 comment = "mode of the result value",
459 name = "no_remainder",
464 attr_struct = "div_attr"
467 arity_override = "oparity_binary"
470 """A placeholder value. This is used when constructing cyclic graphs where
471 you have cases where not all predecessors of a phi-node are known. Dummy
472 nodes are used for the unknown predecessors and replaced later."""
474 flags = [ "cfopcode", "start_block", "constlike", "dump_noblock" ]
477 block = "get_irg_start_block(irg)"
480 """Last node of a graph. It references nodes in endless loops (so called
485 flags = [ "cfopcode" ]
487 block = "get_irg_end_block(irg)"
489 customSerializer = True
492 """returns the result of a bitwise exclusive or operation of its operands"""
493 flags = [ "commutative" ]
496 """Frees a block of memory previously allocated by an Alloc node"""
498 ("mem", "memory dependency" ),
499 ("ptr", "pointer to the object to free"),
500 ("size", "number of objects to allocate" ),
503 flags = [ "uses_memory" ]
509 comment = "type of the allocated variable",
513 type = "ir_where_alloc",
514 comment = "whether allocation was on the stack or heap",
517 attr_struct = "free_attr"
520 """Returns its operand unchanged."""
522 ("pred", "the value which is returned unchanged")
528 """Jumps to the code in its argument. The code has to be in the same
529 function and the the destination must be one of the blocks reachable
530 by the tuple results"""
534 ("target", "target address of the jump"),
536 flags = [ "cfopcode", "forking", "keep", "unknown_jump" ]
539 """Tests whether an object is an instance of a class-type"""
541 ("store", "memory dependency"),
542 ("obj", "pointer to object being queried")
545 ("M", "memory result"),
546 ("X_regular", "control flow when no exception occurs"),
547 ("X_except", "control flow when exception occured"),
548 ("res", "checked object pointer"),
550 flags = [ "highlevel" ]
555 comment = "type to check ptr for",
558 attr_struct = "io_attr"
560 pinned_init = "op_pin_state_floats"
563 """Jumps to the block connected through the out-value"""
567 flags = [ "cfopcode" ]
570 """Loads a value from memory (heap or stack)."""
572 ("mem", "memory dependency"),
573 ("ptr", "address to load from"),
576 ("M", "memory result"),
577 ("X_regular", "control flow when no exception occurs"),
578 ("X_except", "control flow when exception occured"),
579 ("res", "result of load operation"),
581 flags = [ "fragile", "uses_memory" ]
587 comment = "mode of the value to be loaded",
590 type = "ir_volatility",
592 comment = "volatile loads are a visible side-effect and may not be optimized",
593 init = "flags & cons_volatile ? volatility_is_volatile : volatility_non_volatile",
598 comment = "pointers to unaligned loads don't need to respect the load-mode/type alignments",
599 init = "flags & cons_unaligned ? align_non_aligned : align_is_aligned",
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"
613 """returns the difference between its operands"""
617 """returns the remainder of its operands from an implied division.
620 * mod(5,3) produces 2
621 * mod(5,-3) produces 2
622 * mod(-5,3) produces -2
623 * mod(-5,-3) produces -2
626 ("mem", "memory dependency"),
627 ("left", "first operand"),
628 ("right", "second operand"),
631 ("M", "memory result"),
632 ("X_regular", "control flow when no exception occurs"),
633 ("X_except", "control flow when exception occured"),
634 ("res", "result of computation"),
636 flags = [ "fragile", "uses_memory" ]
642 comment = "mode of the result",
645 attr_struct = "mod_attr"
648 arity_override = "oparity_binary"
651 """returns the product of its operands"""
652 flags = [ "commutative" ]
655 """returns the upper word of the product of its operands (the part which
656 would not fit into the result mode of a normal Mul anymore)"""
657 flags = [ "commutative" ]
660 """returns the false or true operand depending on the value of the sel
663 ("sel", "value making the output selection"),
664 ("false", "selected if sel input is false"),
665 ("true", "selected if sel input is true"),
671 """Placeholder node for cases where you don't need any memory input"""
673 flags = [ "dump_noblock", "dump_noinput" ]
676 block = "get_irg_start_block(irg)"
680 """returns the logical complement of a value. Works for integer values too.
681 If the input is false/zero then true/one is returned, otherwise false/zero
686 """returns the result of a bitwise or operation of its operands"""
687 flags = [ "commutative" ]
690 """Choose a value based on control flow. A phi node has 1 input for each
691 predecessor of its block. If a block is entered from its nth predecessor
692 all phi nodes produce their nth input as result."""
696 attr_struct = "phi_attr"
698 res->attr.phi.u.backedge = new_backedge_arr(irg->obst, arity);'''
700 /* Memory Phis in endless loops must be kept alive.
701 As we can't distinguish these easily we keep all of them alive. */
702 if (is_Phi(res) && mode == mode_M)
703 add_End_keepalive(get_irg_end(irg), res);'''
706 """Pin the value of the node node in the current block. No users of the Pin
707 node can float above the Block of the Pin. The node cannot float behind
708 this block. Often used to Pin the NoMem node."""
710 ("op", "value which is pinned"),
712 mode = "get_irn_mode(irn_op)"
713 flags = [ "highlevel" ]
717 """returns an entry of a tuple value"""
719 ("pred", "the tuple value from which a part is extracted"),
725 block = "get_nodes_block(irn_pred)"
726 graph = "get_irn_irg(irn_pred)"
727 customSerializer = True
732 comment = "number of tuple component to be extracted",
735 attr_struct = "proj_attr"
738 """Raises an exception. Unconditional change of control flow. Writes an
739 explicit Except variable to memory to pass it to the exception handler.
740 Must be lowered to a Call to a runtime check function."""
742 ("mem", "memory dependency"),
743 ("exo_ptr", "pointer to exception object to be thrown"),
746 ("M", "memory result"),
747 ("X", "control flow to exception handler"),
749 flags = [ "highlevel", "cfopcode" ]
753 """Returns from the current function. Takes memory and return values as
756 ("mem", "memory dependency"),
760 flags = [ "cfopcode" ]
764 """Returns its first operand bits rotated left by the amount in the 2nd
769 """Computes the address of a entity of a compound type given the base
770 address of an instance of the compound type."""
772 ("mem", "memory dependency"),
773 ("ptr", "pointer to object to select from"),
777 mode = "is_Method_type(get_entity_type(entity)) ? mode_P_code : mode_P_data"
783 comment = "entity which is selected",
786 attr_struct = "sel_attr"
789 """Returns its first operands bits shifted left by the amount of the 2nd
794 """Returns its first operands bits shifted right by the amount of the 2nd
795 operand. No special handling for the sign bit (zero extension)"""
799 """Returns its first operands bits shifted right by the amount of the 2nd
800 operand. The leftmost bit (usually the sign bit) stays the same
805 """The first node of a graph. Execution starts with this node."""
807 ("X_initial_exec", "control flow"),
808 ("M", "initial memory"),
809 ("P_frame_base", "frame base pointer"),
810 ("T_args", "function arguments")
814 flags = [ "cfopcode" ]
817 customSerializer = True
818 block = "get_irg_start_block(irg)"
821 """Stores a value into memory (heap or stack)."""
823 ("mem", "memory dependency"),
824 ("ptr", "address to store to"),
825 ("value", "value to store"),
828 ("M", "memory result"),
829 ("X_regular", "control flow when no exception occurs"),
830 ("X_except", "control flow when exception occured"),
832 flags = [ "fragile", "uses_memory" ]
834 attr_struct = "store_attr"
835 pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
838 type = "ir_volatility",
840 comment = "volatile stores are a visible side-effect and may not be optimized",
841 init = "flags & cons_volatile ? volatility_is_volatile : volatility_non_volatile",
846 comment = "pointers to unaligned stores don't need to respect the load-mode/type alignments",
847 init = "flags & cons_unaligned ? align_non_aligned : align_is_aligned",
852 type = "ir_cons_flags",
854 comment = "specifies alignment, volatility and pin state",
859 """returns the difference of its operands"""
863 """A symbolic constant.
865 - symconst_type_tag The symbolic constant represents a type tag. The
866 type the tag stands for is given explicitly.
867 - symconst_type_size The symbolic constant represents the size of a type.
868 The type of which the constant represents the size
870 - symconst_type_align The symbolic constant represents the alignment of a
871 type. The type of which the constant represents the
872 size is given explicitly.
873 - symconst_addr_ent The symbolic constant represents the address of an
874 entity (variable or method). The variable is given
875 explicitly by a firm entity.
876 - symconst_ofs_ent The symbolic constant represents the offset of an
877 entity in its owner type.
878 - symconst_enum_const The symbolic constant is a enumeration constant of
879 an enumeration type."""
881 flags = [ "constlike", "start_block" ]
889 comment = "entity whose address is returned",
892 attr_struct = "symconst_attr"
893 customSerializer = True
894 # constructor is written manually at the moment, because of the strange
899 """The Sync operation unifies several partial memory blocks. These blocks
900 have to be pairwise disjunct or the values in common locations have to
901 be identical. This operation allows to specify all operations that
902 eventually need several partial memory blocks as input with a single
903 entrance by unifying the memories with a preceding Sync operation."""
910 """Builds a Tuple from single values.
912 This is needed to implement optimizations that remove a node that produced
913 a tuple. The node can be replaced by the Tuple operation so that the
914 following Proj nodes have not to be changed. (They are hard to find due to
915 the implementation with pointers in only one direction.) The Tuple node is
916 smaller than any other node, so that a node can be changed into a Tuple by
917 just changing its opcode and giving it a new in array."""
921 flags = [ "labeled" ]
924 """Returns an unknown (at compile- and runtime) value. It is a valid
925 optimisation to replace an Unknown by any other constant value."""
928 block = "get_irg_start_block(irg)"
929 flags = [ "start_block", "constlike", "dump_noblock" ]
933 def getOpList(namespace):
935 for t in namespace.values():
939 if issubclass(t, Op):
944 nodes = getOpList(globals())
945 nodes = sorted(nodes, lambda x,y: cmp(x.name, y.name))