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 ("res", "pointer to newly allocated memory"),
43 ("X_regular", "control flow when no exception occurs"),
44 ("X_except", "control flow when exception occured"),
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" ]
61 pinned_init = "op_pin_state_pinned"
62 attr_struct = "alloc_attr"
65 """utiliy node used to "hold" nodes in a graph that might possibly not be
66 reachable by other means or which should be reachable immediately without
67 searching through the graph.
68 Each firm-graph contains exactly one anchor node whose address is always
69 known. All other well-known graph-nodes like Start, End, NoMem, Bad, ...
70 are found by looking at the respective Anchor operand."""
73 flags = [ "dump_noblock" ]
75 attr_struct = "irg_attr"
79 customSerializer = True
82 """returns the result of a bitwise and operation of its operands"""
83 flags = [ "commutative" ]
86 """executes assembler fragments of the target machine"""
89 flags = [ "keep", "uses_memory" ]
91 pinned_init = "op_pin_state_pinned"
92 attr_struct = "asm_attr"
94 customSerializer = True
97 name = "input_constraints",
98 type = "ir_asm_constraint*",
99 comment = "input constraints",
102 name = "n_output_constraints",
105 comment = "number of output constraints",
108 name = "output_constraints",
109 type = "ir_asm_constraint*",
110 comment = "output constraints",
116 comment = "number of clobbered registers/memory",
121 comment = "list of clobbered registers/memory",
126 comment = "assembler text",
129 # constructor is written manually at the moment, because of the clobbers+
130 # constraints arrays needing special handling (2 arguments for 1 attribute)
134 """Bad nodes indicate invalid input, which is values which should never be
137 The typical use case for the Bad node is removing unreachable code.
138 Frontends should set the current_block to Bad when it is clear that
139 following code must be unreachable (ie. after a goto or return statement).
140 Optimisations also set block predecessors to Bad when it becomes clear,
141 that a control flow edge can never be executed.
143 The gigo optimisations ensures that nodes with Bad as their block, get
144 replaced by Bad themselfes. Nodes with at least 1 Bad input get exchanged
145 with Bad too. Exception to this rule are Block, Phi, Tuple and End node;
146 This is because removing inputs from a Block is hairy operation (requiring,
147 Phis to be shortened too for example). So instead of removing block inputs
148 they are set to Bad, and the actual removal is left to the control flow
149 optimisation phase. Block, Phi, Tuple with only Bad inputs however are
150 replaced by Bad right away."""
151 flags = [ "start_block", "dump_noblock" ]
154 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"
182 comment = "entity representing this block",
186 customSerializer = True
189 res->attr.block.irg.irg = irg;
190 res->attr.block.backedge = new_backedge_arr(irg->obst, arity);
191 set_Block_matured(res, 1);
193 /* Create and initialize array for Phi-node construction. */
194 if (get_irg_phase_state(irg) == phase_building) {
195 res->attr.block.graph_arr = NEW_ARR_D(ir_node *, irg->obst, irg->n_loc);
196 memset(res->attr.block.graph_arr, 0, irg->n_loc * sizeof(ir_node*));
201 """Returns the borrow bit from and implied subtractions of its 2 operands"""
205 """Performs a bounds-check: if lower <= index < upper then return index,
206 otherwise throw an exception."""
208 ("mem", "memory dependency"),
209 ("index", "value to test"),
210 ("lower", "lower bound (inclusive)"),
211 ("upper", "upper bound (exclusive)"),
214 ("M", "memory result"),
215 ("res", "the checked index"),
216 ("X_regular", "control flow when no exception occurs"),
217 ("X_except", "control flow when exception occured"),
219 flags = [ "fragile", "highlevel" ]
221 pinned_init = "op_pin_state_pinned"
222 throws_init = "false"
223 attr_struct = "bound_attr"
226 """performs a backend-specific builtin."""
228 ("mem", "memory dependency"),
232 ("M", "memory result"),
233 # results follow here
235 flags = [ "uses_memory" ]
238 type = "ir_builtin_kind",
240 comment = "kind of builtin",
245 comment = "method type for the builtin call",
249 pinned_init = "op_pin_state_pinned"
250 attr_struct = "builtin_attr"
252 assert((get_unknown_type() == type) || is_Method_type(type));
256 """Calls other code. Control flow is transfered to ptr, additional
257 operands are passed to the called code. Called code usually performs a
258 return operation. The operands of this return operation are the result
261 ("mem", "memory dependency"),
262 ("ptr", "pointer to called code"),
266 ("M", "memory result"),
267 ("T_result", "tuple containing all results"),
268 ("X_regular", "control flow when no exception occurs"),
269 ("X_except", "control flow when exception occured"),
271 flags = [ "fragile", "uses_memory" ]
276 comment = "type of the call (usually type of the called procedure)",
279 attr_struct = "call_attr"
281 pinned_init = "op_pin_state_pinned"
282 throws_init = "false"
284 assert((get_unknown_type() == type) || is_Method_type(type));
288 """Computes the value of the carry-bit that would result when adding the 2
290 flags = [ "commutative" ]
293 """perform a high-level type cast"""
294 mode = "get_irn_mode(irn_op)"
295 flags = [ "highlevel" ]
300 comment = "target type of the case",
303 attr_struct = "cast_attr"
304 init = "assert(is_atomic_type(type));"
307 """Compares its two operands and checks whether a specified
308 relation (like less or equal) is fulfilled."""
313 type = "ir_relation",
315 comment = "Comparison relation"
318 attr_struct = "cmp_attr"
321 """Conditionally change control flow."""
323 ("selector", "condition parameter"),
326 ("false", "control flow if operand is \"false\""),
327 ("true", "control flow if operand is \"true\""),
329 flags = [ "cfopcode", "forking" ]
334 type = "cond_jmp_predicate",
335 init = "COND_JMP_PRED_NONE",
336 comment = "can indicate the most likely jump",
339 attr_struct = "cond_attr"
342 """Change control flow. The destination is choosen based on an integer input value which is looked up in a table.
344 Backends can implement this efficiently using a jump table."""
346 ("selector", "input selector"),
349 ("default", "control flow if no other case matches"),
351 flags = [ "cfopcode", "forking" ]
357 comment = "number of outputs (including pn_Switch_default)",
361 type = "ir_switch_table*",
362 comment = "table describing mapping from input values to Proj numbers",
365 attr_struct = "switch_attr"
366 attrs_name = "switcha"
369 """Specifies constraints for a value. This allows explicit representation
370 of path-sensitive properties. (Example: This value is always >= 0 on 1
371 if-branch then all users within that branch are rerouted to a confirm-node
372 specifying this property).
374 A constraint is specified for the relation between value and bound.
375 value is always returned.
376 Note that this node does NOT check or assert the constraint, it merely
379 ("value", "value to express a constraint for"),
380 ("bound", "value to compare against"),
382 mode = "get_irn_mode(irn_value)"
383 flags = [ "highlevel" ]
388 type = "ir_relation",
389 comment = "relation of value to bound",
392 attr_struct = "confirm_attr"
395 """Returns a constant value."""
396 flags = [ "constlike", "start_block" ]
397 block = "get_irg_start_block(irg)"
398 mode = "get_tarval_mode(tarval)"
405 comment = "constant value (a tarval object)",
408 attr_struct = "const_attr"
412 """Converts values between modes"""
419 comment = "force floating point to restrict precision even if backend computes in higher precision (deprecated)",
422 attr_struct = "conv_attr"
425 """Copies a block of memory"""
427 ("mem", "memory dependency"),
428 ("dst", "destination address"),
429 ("src", "source address"),
432 ("M", "memory result"),
433 ("X_regular", "control flow when no exception occurs"),
434 ("X_except", "control flow when exception occured"),
436 flags = [ "fragile", "uses_memory" ]
441 comment = "type of copied data",
444 attr_struct = "copyb_attr"
446 pinned_init = "op_pin_state_pinned"
447 throws_init = "false"
450 """returns the quotient of its 2 operands"""
452 ("mem", "memory dependency"),
453 ("left", "first operand"),
454 ("right", "second operand"),
457 ("M", "memory result"),
458 ("res", "result of computation"),
459 ("X_regular", "control flow when no exception occurs"),
460 ("X_except", "control flow when exception occured"),
462 flags = [ "fragile", "uses_memory" ]
467 comment = "mode of the result value",
470 name = "no_remainder",
475 attr_struct = "div_attr"
477 throws_init = "false"
479 arity_override = "oparity_binary"
482 """A placeholder value. This is used when constructing cyclic graphs where
483 you have cases where not all predecessors of a phi-node are known. Dummy
484 nodes are used for the unknown predecessors and replaced later."""
486 flags = [ "cfopcode", "start_block", "constlike", "dump_noblock" ]
489 block = "get_irg_start_block(irg)"
492 """Last node of a graph. It references nodes in endless loops (so called
497 flags = [ "cfopcode" ]
499 block = "get_irg_end_block(irg)"
501 customSerializer = True
504 """returns the result of a bitwise exclusive or operation of its operands"""
505 flags = [ "commutative" ]
508 """Frees a block of memory previously allocated by an Alloc node"""
510 ("mem", "memory dependency" ),
511 ("ptr", "pointer to the object to free"),
512 ("count", "number of objects to allocate" ),
515 flags = [ "uses_memory" ]
521 comment = "type of the allocated variable",
525 type = "ir_where_alloc",
526 comment = "whether allocation was on the stack or heap",
529 attr_struct = "free_attr"
532 """Returns its operand unchanged."""
534 ("pred", "the value which is returned unchanged")
540 """Jumps to the code in its argument. The code has to be in the same
541 function and the the destination must be one of the blocks reachable
542 by the tuple results"""
546 ("target", "target address of the jump"),
548 flags = [ "cfopcode", "forking", "keep", "unknown_jump" ]
551 """Tests whether an object is an instance of a class-type"""
553 ("store", "memory dependency"),
554 ("obj", "pointer to object being queried")
557 ("M", "memory result"),
558 ("res", "checked object pointer"),
559 ("X_regular", "control flow when no exception occurs"),
560 ("X_except", "control flow when exception occured"),
562 flags = [ "highlevel" ]
567 comment = "type to check ptr for",
570 attr_struct = "io_attr"
572 pinned_init = "op_pin_state_floats"
575 """Jumps to the block connected through the out-value"""
579 flags = [ "cfopcode" ]
582 """Loads a value from memory (heap or stack)."""
584 ("mem", "memory dependency"),
585 ("ptr", "address to load from"),
588 ("M", "memory result"),
589 ("res", "result of load operation"),
590 ("X_regular", "control flow when no exception occurs"),
591 ("X_except", "control flow when exception occured"),
593 flags = [ "fragile", "uses_memory" ]
599 comment = "mode of the value to be loaded",
602 type = "ir_volatility",
604 comment = "volatile loads are a visible side-effect and may not be optimized",
605 init = "flags & cons_volatile ? volatility_is_volatile : volatility_non_volatile",
610 comment = "pointers to unaligned loads don't need to respect the load-mode/type alignments",
611 init = "flags & cons_unaligned ? align_non_aligned : align_is_aligned",
614 attr_struct = "load_attr"
617 type = "ir_cons_flags",
619 comment = "specifies alignment, volatility and pin state",
622 pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
623 throws_init = "(flags & cons_throws_exception) != 0"
626 """returns the difference between its operands"""
630 """returns the remainder of its operands from an implied division.
634 * mod(5,3) produces 2
635 * mod(5,-3) produces 2
636 * mod(-5,3) produces -2
637 * mod(-5,-3) produces -2
640 ("mem", "memory dependency"),
641 ("left", "first operand"),
642 ("right", "second operand"),
645 ("M", "memory result"),
646 ("res", "result of computation"),
647 ("X_regular", "control flow when no exception occurs"),
648 ("X_except", "control flow when exception occured"),
650 flags = [ "fragile", "uses_memory" ]
655 comment = "mode of the result",
658 attr_struct = "mod_attr"
660 throws_init = "false"
662 arity_override = "oparity_binary"
665 """returns the product of its operands"""
666 flags = [ "commutative" ]
669 """returns the upper word of the product of its operands (the part which
670 would not fit into the result mode of a normal Mul anymore)"""
671 flags = [ "commutative" ]
674 """returns the false or true operand depending on the value of the sel
677 ("sel", "value making the output selection"),
678 ("false", "selected if sel input is false"),
679 ("true", "selected if sel input is true"),
685 """Placeholder node for cases where you don't need any memory input"""
687 flags = [ "dump_noblock", "dump_noinput" ]
690 block = "get_irg_start_block(irg)"
694 """returns the logical complement of a value. Works for integer values too.
695 If the input is false/zero then true/one is returned, otherwise false/zero
700 """returns the result of a bitwise or operation of its operands"""
701 flags = [ "commutative" ]
704 """Choose a value based on control flow. A phi node has 1 input for each
705 predecessor of its block. If a block is entered from its nth predecessor
706 all phi nodes produce their nth input as result."""
710 attr_struct = "phi_attr"
712 res->attr.phi.u.backedge = new_backedge_arr(irg->obst, arity);'''
714 /* Memory Phis in endless loops must be kept alive.
715 As we can't distinguish these easily we keep all of them alive. */
716 if (is_Phi(res) && mode == mode_M)
717 add_End_keepalive(get_irg_end(irg), res);'''
720 """Pin the value of the node node in the current block. No users of the Pin
721 node can float above the Block of the Pin. The node cannot float behind
722 this block. Often used to Pin the NoMem node."""
724 ("op", "value which is pinned"),
726 mode = "get_irn_mode(irn_op)"
727 flags = [ "highlevel" ]
731 """returns an entry of a tuple value"""
733 ("pred", "the tuple value from which a part is extracted"),
739 block = "get_nodes_block(irn_pred)"
740 graph = "get_irn_irg(irn_pred)"
741 customSerializer = True
746 comment = "number of tuple component to be extracted",
749 attr_struct = "proj_attr"
752 """Raises an exception. Unconditional change of control flow. Writes an
753 explicit Except variable to memory to pass it to the exception handler.
754 Must be lowered to a Call to a runtime check function."""
756 ("mem", "memory dependency"),
757 ("exo_ptr", "pointer to exception object to be thrown"),
760 ("M", "memory result"),
761 ("X", "control flow to exception handler"),
763 flags = [ "highlevel", "cfopcode" ]
767 """Returns from the current function. Takes memory and return values as
770 ("mem", "memory dependency"),
774 flags = [ "cfopcode" ]
778 """Returns its first operand bits rotated left by the amount in the 2nd
783 """Computes the address of a entity of a compound type given the base
784 address of an instance of the compound type."""
786 ("mem", "memory dependency"),
787 ("ptr", "pointer to object to select from"),
791 mode = "is_Method_type(get_entity_type(entity)) ? mode_P_code : mode_P_data"
797 comment = "entity which is selected",
800 attr_struct = "sel_attr"
803 """Returns its first operands bits shifted left by the amount of the 2nd
808 """Returns its first operands bits shifted right by the amount of the 2nd
809 operand. No special handling for the sign bit (zero extension)"""
813 """Returns its first operands bits shifted right by the amount of the 2nd
814 operand. The leftmost bit (usually the sign bit) stays the same
819 """The first node of a graph. Execution starts with this node."""
821 ("X_initial_exec", "control flow"),
822 ("M", "initial memory"),
823 ("P_frame_base", "frame base pointer"),
824 ("T_args", "function arguments")
828 flags = [ "cfopcode" ]
831 customSerializer = True
832 block = "get_irg_start_block(irg)"
835 """Stores a value into memory (heap or stack)."""
837 ("mem", "memory dependency"),
838 ("ptr", "address to store to"),
839 ("value", "value to store"),
842 ("M", "memory result"),
843 ("X_regular", "control flow when no exception occurs"),
844 ("X_except", "control flow when exception occured"),
846 flags = [ "fragile", "uses_memory" ]
848 attr_struct = "store_attr"
849 pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
850 throws_init = "(flags & cons_throws_exception) != 0"
853 type = "ir_volatility",
855 comment = "volatile stores are a visible side-effect and may not be optimized",
856 init = "flags & cons_volatile ? volatility_is_volatile : volatility_non_volatile",
861 comment = "pointers to unaligned stores don't need to respect the load-mode/type alignments",
862 init = "flags & cons_unaligned ? align_non_aligned : align_is_aligned",
867 type = "ir_cons_flags",
869 comment = "specifies alignment, volatility and pin state",
874 """returns the difference of its operands"""
878 """A symbolic constant.
880 - *symconst_type_tag* The symbolic constant represents a type tag. The
881 type the tag stands for is given explicitly.
882 - *symconst_type_size* The symbolic constant represents the size of a type.
883 The type of which the constant represents the size
885 - *symconst_type_align* The symbolic constant represents the alignment of a
886 type. The type of which the constant represents the
887 size is given explicitly.
888 - *symconst_addr_ent* The symbolic constant represents the address of an
889 entity (variable or method). The variable is given
890 explicitly by a firm entity.
891 - *symconst_ofs_ent* The symbolic constant represents the offset of an
892 entity in its owner type.
893 - *symconst_enum_const* The symbolic constant is a enumeration constant of
894 an enumeration type."""
896 flags = [ "constlike", "start_block" ]
904 comment = "entity whose address is returned",
907 attr_struct = "symconst_attr"
908 customSerializer = True
909 # constructor is written manually at the moment, because of the strange
914 """The Sync operation unifies several partial memory blocks. These blocks
915 have to be pairwise disjunct or the values in common locations have to
916 be identical. This operation allows to specify all operations that
917 eventually need several partial memory blocks as input with a single
918 entrance by unifying the memories with a preceding Sync operation."""
925 """Builds a Tuple from single values.
927 This is needed to implement optimizations that remove a node that produced
928 a tuple. The node can be replaced by the Tuple operation so that the
929 following Proj nodes have not to be changed. (They are hard to find due to
930 the implementation with pointers in only one direction.) The Tuple node is
931 smaller than any other node, so that a node can be changed into a Tuple by
932 just changing its opcode and giving it a new in array."""
936 flags = [ "labeled" ]
939 """Returns an unknown (at compile- and runtime) value. It is a valid
940 optimisation to replace an Unknown by any other constant value."""
943 block = "get_irg_start_block(irg)"
944 flags = [ "start_block", "constlike", "dump_noblock" ]
948 def getOpList(namespace):
950 for t in namespace.values():
954 if issubclass(t, Op):
959 nodes = getOpList(globals())
960 nodes = sorted(nodes, lambda x,y: cmp(x.name, y.name))