1 # Firm node specifications
2 # The comments are in (standard python) restructured text format and are used
3 # to generate documentation.
4 from spec_util import abstract, op
11 """Unary nodes have exactly 1 input"""
22 """Binary nodes have exactly 2 inputs"""
25 ( "left", "first operand" ),
26 ( "right", "second operand" ),
33 """returns the sum of its operands"""
34 flags = [ "commutative" ]
38 """allocates a block of memory.
39 It can be specified whether the memory should be allocated to the stack
41 Allocates memory for one or more objects (depending on value on count input).
44 ("mem", "memory dependency" ),
45 ("count", "number of objects to allocate" ),
48 ("M", "memory result"),
49 ("res", "pointer to newly allocated memory"),
50 ("X_regular", "control flow when no exception occurs"),
51 ("X_except", "control flow when exception occured"),
57 comment = "type of the objects to allocate",
61 type = "ir_where_alloc",
62 comment = "whether to allocate the variable on the stack or heap",
65 flags = [ "fragile", "uses_memory" ]
68 pinned_init = "op_pin_state_pinned"
69 attr_struct = "alloc_attr"
73 """utiliy node used to "hold" nodes in a graph that might possibly not be
74 reachable by other means or which should be reachable immediately without
75 searching through the graph.
76 Each firm-graph contains exactly one anchor node whose address is always
77 known. All other well-known graph-nodes like Start, End, NoMem, Bad, ...
78 are found by looking at the respective Anchor operand."""
81 flags = [ "dump_noblock" ]
83 attr_struct = "irg_attr"
87 customSerializer = True
91 """returns the result of a bitwise and operation of its operands"""
92 flags = [ "commutative" ]
96 """executes assembler fragments of the target machine.
98 The node contains a template for an assembler snippet. The compiler will
99 replace occurences of %0 to %9 with input/output registers,
100 %% with a single % char. Some backends allow additional specifiers (for
101 example %w3, %l3, %h3 on x86 to get a 16bit, 8hit low, 8bit high part
103 After the replacements the text is emitted into the final assembly.
105 The clobber list contains names of registers which have an undefined value
106 after the assembler instruction is executed; it may also contain 'memory'
107 or 'cc' if global state/memory changes or the condition code registers
108 (some backends implicitely set cc, memory clobbers on all ASM statements).
110 Example (an i386 instruction)::
112 ASM(text="btsl %1, %0",
113 input_constraints = ["=m", "r"],
116 As there are no output, the %0 references the first input which is just an
117 address which the asm operation writes to. %1 references to an input which
118 is passed as a register. The condition code register has an unknown value
119 after the instruction.
121 (This format is inspired by the gcc extended asm syntax)
125 flags = [ "keep", "uses_memory" ]
127 pinned_init = "op_pin_state_pinned"
128 attr_struct = "asm_attr"
130 customSerializer = True
132 ("mem", "memory dependency"),
136 name = "input_constraints",
137 type = "ir_asm_constraint*",
138 comment = "input constraints",
141 name = "n_output_constraints",
144 comment = "number of output constraints",
147 name = "output_constraints",
148 type = "ir_asm_constraint*",
149 comment = "output constraints",
155 comment = "number of clobbered registers/memory",
160 comment = "list of clobbered registers/memory",
165 comment = "assembler text",
168 # constructor is written manually at the moment, because of the clobbers+
169 # constraints arrays needing special handling (2 arguments for 1 attribute)
174 """Bad nodes indicate invalid input, which is values which should never be
177 The typical use case for the Bad node is removing unreachable code.
178 Frontends should set the current_block to Bad when it is clear that
179 following code must be unreachable (ie. after a goto or return statement).
180 Optimisations also set block predecessors to Bad when it becomes clear,
181 that a control flow edge can never be executed.
183 The gigo optimisations ensures that nodes with Bad as their block, get
184 replaced by Bad themselves. Nodes with at least 1 Bad input get exchanged
185 with Bad too. Exception to this rule are Block, Phi, Tuple and End node;
186 This is because removing inputs from a Block is hairy operation (requiring,
187 Phis to be shortened too for example). So instead of removing block inputs
188 they are set to Bad, and the actual removal is left to the control flow
189 optimisation phase. Block, Phi, Tuple with only Bad inputs however are
190 replaced by Bad right away."""
191 flags = [ "start_block", "dump_noblock" ]
194 block = "get_irg_start_block(irg)"
195 attr_struct = "bad_attr"
197 res->attr.bad.irg.irg = irg;
202 """Internal node which is temporary set to nodes which are already removed
208 customSerializer = True # this has no serializer
219 attr_struct = "block_attr"
224 comment = "entity representing this block",
228 customSerializer = True
231 res->attr.block.irg.irg = irg;
232 res->attr.block.backedge = new_backedge_arr(irg->obst, arity);
233 set_Block_matured(res, 1);
235 /* Create and initialize array for Phi-node construction. */
236 if (irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_CONSTRUCTION)) {
237 res->attr.block.graph_arr = NEW_ARR_D(ir_node *, irg->obst, irg->n_loc);
238 memset(res->attr.block.graph_arr, 0, irg->n_loc * sizeof(ir_node*));
244 """Returns the borrow bit from and implied subtractions of its 2 operands"""
249 """Performs a bounds-check: if lower <= index < upper then return index,
250 otherwise throw an exception."""
252 ("mem", "memory dependency"),
253 ("index", "value to test"),
254 ("lower", "lower bound (inclusive)"),
255 ("upper", "upper bound (exclusive)"),
258 ("M", "memory result"),
259 ("res", "the checked index"),
260 ("X_regular", "control flow when no exception occurs"),
261 ("X_except", "control flow when exception occured"),
263 flags = [ "fragile", "highlevel" ]
265 pinned_init = "op_pin_state_pinned"
266 throws_init = "false"
267 attr_struct = "bound_attr"
271 """performs a backend-specific builtin."""
273 ("mem", "memory dependency"),
277 ("M", "memory result"),
278 # results follow here
280 flags = [ "uses_memory" ]
283 type = "ir_builtin_kind",
285 comment = "kind of builtin",
290 comment = "method type for the builtin call",
294 pinned_init = "op_pin_state_pinned"
295 attr_struct = "builtin_attr"
297 assert((get_unknown_type() == type) || is_Method_type(type));
302 """Calls other code. Control flow is transfered to ptr, additional
303 operands are passed to the called code. Called code usually performs a
304 return operation. The operands of this return operation are the result
307 ("mem", "memory dependency"),
308 ("ptr", "pointer to called code"),
312 ("M", "memory result"),
313 ("T_result", "tuple containing all results"),
314 ("X_regular", "control flow when no exception occurs"),
315 ("X_except", "control flow when exception occured"),
317 flags = [ "fragile", "uses_memory" ]
322 comment = "type of the call (usually type of the called procedure)",
325 attr_struct = "call_attr"
327 pinned_init = "op_pin_state_pinned"
328 throws_init = "false"
330 assert((get_unknown_type() == type) || is_Method_type(type));
335 """Computes the value of the carry-bit that would result when adding the 2
337 flags = [ "commutative" ]
341 """perform a high-level type cast"""
342 mode = "get_irn_mode(irn_op)"
343 flags = [ "highlevel" ]
348 comment = "target type of the case",
351 attr_struct = "cast_attr"
352 init = "assert(is_atomic_type(type));"
356 """Compares its two operands and checks whether a specified
357 relation (like less or equal) is fulfilled."""
362 type = "ir_relation",
364 comment = "Comparison relation"
367 attr_struct = "cmp_attr"
371 """Conditionally change control flow."""
373 ("selector", "condition parameter"),
376 ("false", "control flow if operand is \"false\""),
377 ("true", "control flow if operand is \"true\""),
379 flags = [ "cfopcode", "forking" ]
384 type = "cond_jmp_predicate",
385 init = "COND_JMP_PRED_NONE",
386 comment = "can indicate the most likely jump",
389 attr_struct = "cond_attr"
393 """Change control flow. The destination is choosen based on an integer input value which is looked up in a table.
395 Backends can implement this efficiently using a jump table."""
397 ("selector", "input selector"),
400 ("default", "control flow if no other case matches"),
402 flags = [ "cfopcode", "forking" ]
408 comment = "number of outputs (including pn_Switch_default)",
412 type = "ir_switch_table*",
413 comment = "table describing mapping from input values to Proj numbers",
416 attr_struct = "switch_attr"
417 attrs_name = "switcha"
421 """Specifies constraints for a value. This allows explicit representation
422 of path-sensitive properties. (Example: This value is always >= 0 on 1
423 if-branch then all users within that branch are rerouted to a confirm-node
424 specifying this property).
426 A constraint is specified for the relation between value and bound.
427 value is always returned.
428 Note that this node does NOT check or assert the constraint, it merely
431 ("value", "value to express a constraint for"),
432 ("bound", "value to compare against"),
434 mode = "get_irn_mode(irn_value)"
435 flags = [ "highlevel" ]
440 type = "ir_relation",
441 comment = "relation of value to bound",
444 attr_struct = "confirm_attr"
448 """Returns a constant value."""
449 flags = [ "constlike", "start_block" ]
450 block = "get_irg_start_block(irg)"
451 mode = "get_tarval_mode(tarval)"
458 comment = "constant value (a tarval object)",
461 attr_struct = "const_attr"
466 """Converts values between modes"""
471 """Copies a block of memory with statically known size/type."""
473 ("mem", "memory dependency"),
474 ("dst", "destination address"),
475 ("src", "source address"),
478 ("M", "memory result"),
479 ("X_regular", "control flow when no exception occurs"),
480 ("X_except", "control flow when exception occured"),
482 flags = [ "fragile", "uses_memory" ]
487 comment = "type of copied data",
490 attr_struct = "copyb_attr"
492 pinned_init = "op_pin_state_pinned"
493 throws_init = "false"
497 """returns the quotient of its 2 operands"""
499 ("mem", "memory dependency"),
500 ("left", "first operand"),
501 ("right", "second operand"),
504 ("M", "memory result"),
505 ("res", "result of computation"),
506 ("X_regular", "control flow when no exception occurs"),
507 ("X_except", "control flow when exception occured"),
509 flags = [ "fragile", "uses_memory" ]
514 comment = "mode of the result value",
517 name = "no_remainder",
522 attr_struct = "div_attr"
524 throws_init = "false"
526 arity_override = "oparity_binary"
530 """A placeholder value. This is used when constructing cyclic graphs where
531 you have cases where not all predecessors of a phi-node are known. Dummy
532 nodes are used for the unknown predecessors and replaced later."""
534 flags = [ "cfopcode", "start_block", "constlike", "dump_noblock" ]
537 block = "get_irg_start_block(irg)"
541 """Last node of a graph. It references nodes in endless loops (so called
546 flags = [ "cfopcode" ]
548 block = "get_irg_end_block(irg)"
553 """returns the result of a bitwise exclusive or operation of its operands.
555 This is also known as the Xor operation."""
556 flags = [ "commutative" ]
560 """Frees a block of memory previously allocated by an Alloc node"""
562 ("mem", "memory dependency" ),
563 ("ptr", "pointer to the object to free"),
564 ("count", "number of objects to allocate" ),
567 flags = [ "uses_memory" ]
573 comment = "type of the allocated variable",
577 type = "ir_where_alloc",
578 comment = "whether allocation was on the stack or heap",
581 attr_struct = "free_attr"
585 """Returns its operand unchanged.
587 This is mainly used when exchanging nodes. Usually you shouldn't see Id
588 nodes since the getters/setters for node inputs skip them automatically."""
590 ("pred", "the value which is returned unchanged")
597 """Jumps to the code in its argument. The code has to be in the same
598 function and the the destination must be one of the blocks reachable
599 by the tuple results"""
603 ("target", "target address of the jump"),
605 flags = [ "cfopcode", "forking", "keep", "unknown_jump" ]
609 """Tests whether an object is an instance of a class-type"""
611 ("store", "memory dependency"),
612 ("obj", "pointer to object being queried")
615 ("M", "memory result"),
616 ("res", "checked object pointer"),
617 ("X_regular", "control flow when no exception occurs"),
618 ("X_except", "control flow when exception occured"),
620 flags = [ "highlevel" ]
625 comment = "type to check ptr for",
628 attr_struct = "io_attr"
630 pinned_init = "op_pin_state_floats"
634 """Jumps to the block connected through the out-value"""
638 flags = [ "cfopcode" ]
642 """Loads a value from memory (heap or stack)."""
644 ("mem", "memory dependency"),
645 ("ptr", "address to load from"),
648 ("M", "memory result"),
649 ("res", "result of load operation"),
650 ("X_regular", "control flow when no exception occurs"),
651 ("X_except", "control flow when exception occured"),
653 flags = [ "fragile", "uses_memory" ]
659 comment = "mode of the value to be loaded",
662 type = "ir_volatility",
664 comment = "volatile loads are a visible side-effect and may not be optimized",
665 init = "flags & cons_volatile ? volatility_is_volatile : volatility_non_volatile",
666 to_flags = "%s == volatility_is_volatile ? cons_volatile : cons_none"
671 comment = "pointers to unaligned loads don't need to respect the load-mode/type alignments",
672 init = "flags & cons_unaligned ? align_non_aligned : align_is_aligned",
673 to_flags = "%s == align_non_aligned ? cons_unaligned : cons_none"
676 attr_struct = "load_attr"
679 type = "ir_cons_flags",
681 comment = "specifies alignment, volatility and pin state",
684 pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
685 throws_init = "(flags & cons_throws_exception) != 0"
689 """returns the additive inverse of its operand"""
694 """returns the remainder of its operands from an implied division.
698 * mod(5,3) produces 2
699 * mod(5,-3) produces 2
700 * mod(-5,3) produces -2
701 * mod(-5,-3) produces -2
704 ("mem", "memory dependency"),
705 ("left", "first operand"),
706 ("right", "second operand"),
709 ("M", "memory result"),
710 ("res", "result of computation"),
711 ("X_regular", "control flow when no exception occurs"),
712 ("X_except", "control flow when exception occured"),
714 flags = [ "fragile", "uses_memory" ]
719 comment = "mode of the result",
722 attr_struct = "mod_attr"
724 throws_init = "false"
726 arity_override = "oparity_binary"
729 """returns the product of its operands"""
730 flags = [ "commutative" ]
733 """returns the upper word of the product of its operands (the part which
734 would not fit into the result mode of a normal Mul anymore)"""
735 flags = [ "commutative" ]
739 """returns the false or true operand depending on the value of the sel
742 ("sel", "value making the output selection"),
743 ("false", "selected if sel input is false"),
744 ("true", "selected if sel input is true"),
751 """Placeholder node for cases where you don't need any memory input"""
753 flags = [ "dump_noblock" ]
756 block = "get_irg_start_block(irg)"
761 """returns the bitwise complement of a value. Works for boolean values, too."""
766 """returns the result of a bitwise or operation of its operands"""
767 flags = [ "commutative" ]
771 """Choose a value based on control flow. A phi node has 1 input for each
772 predecessor of its block. If a block is entered from its nth predecessor
773 all phi nodes produce their nth input as result."""
777 attr_struct = "phi_attr"
779 res->attr.phi.u.backedge = new_backedge_arr(irg->obst, arity);'''
781 /* Memory Phis in endless loops must be kept alive.
782 As we can't distinguish these easily we keep all of them alive. */
783 if (is_Phi(res) && mode == mode_M)
784 add_End_keepalive(get_irg_end(irg), res);'''
785 customSerializer = True
789 """Pin the value of the node node in the current block. No users of the Pin
790 node can float above the Block of the Pin. The node cannot float behind
791 this block. Often used to Pin the NoMem node."""
793 ("op", "value which is pinned"),
795 mode = "get_irn_mode(irn_op)"
796 flags = [ "highlevel" ]
801 """returns an entry of a tuple value"""
803 ("pred", "the tuple value from which a part is extracted"),
809 block = "get_nodes_block(irn_pred)"
810 graph = "get_irn_irg(irn_pred)"
815 comment = "number of tuple component to be extracted",
818 attr_struct = "proj_attr"
822 """Raises an exception. Unconditional change of control flow. Writes an
823 explicit Except variable to memory to pass it to the exception handler.
824 Must be lowered to a Call to a runtime check function."""
826 ("mem", "memory dependency"),
827 ("exo_ptr", "pointer to exception object to be thrown"),
830 ("M", "memory result"),
831 ("X", "control flow to exception handler"),
833 flags = [ "highlevel", "cfopcode" ]
838 """Returns from the current function. Takes memory and return values as
841 ("mem", "memory dependency"),
845 flags = [ "cfopcode" ]
849 """Returns its first operand bits rotated left by the amount in the 2nd
855 """Computes the address of a entity of a compound type given the base
856 address of an instance of the compound type.
858 Optimisations assume that a Sel node can only produce a NULL pointer if the
859 ptr input was NULL."""
861 ("mem", "memory dependency"),
862 ("ptr", "pointer to object to select from"),
866 mode = "is_Method_type(get_entity_type(entity)) ? mode_P_code : mode_P_data"
872 comment = "entity which is selected",
875 attr_struct = "sel_attr"
879 """Returns its first operands bits shifted left by the amount of the 2nd
881 The right input (shift amount) must be an unsigned integer value.
882 If the result mode has modulo_shift!=0, then the effective shift amount is
883 the right input modulo this modulo_shift amount."""
888 """Returns its first operands bits shifted right by the amount of the 2nd
889 operand. No special handling for the sign bit is performed (zero extension).
890 The right input (shift amount) must be an unsigned integer value.
891 If the result mode has modulo_shift!=0, then the effective shift amount is
892 the right input modulo this modulo_shift amount."""
897 """Returns its first operands bits shifted right by the amount of the 2nd
898 operand. The leftmost bit (usually the sign bit) stays the same
900 The right input (shift amount) must be an unsigned integer value.
901 If the result mode has modulo_shift!=0, then the effective shift amount is
902 the right input modulo this modulo_shift amount."""
907 """The first node of a graph. Execution starts with this node."""
909 ("X_initial_exec", "control flow"),
910 ("M", "initial memory"),
911 ("P_frame_base", "frame base pointer"),
912 ("T_args", "function arguments")
916 flags = [ "cfopcode" ]
919 block = "get_irg_start_block(irg)"
923 """Stores a value into memory (heap or stack)."""
925 ("mem", "memory dependency"),
926 ("ptr", "address to store to"),
927 ("value", "value to store"),
930 ("M", "memory result"),
931 ("X_regular", "control flow when no exception occurs"),
932 ("X_except", "control flow when exception occured"),
934 flags = [ "fragile", "uses_memory" ]
936 attr_struct = "store_attr"
937 pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
938 throws_init = "(flags & cons_throws_exception) != 0"
941 type = "ir_volatility",
943 comment = "volatile stores are a visible side-effect and may not be optimized",
944 init = "flags & cons_volatile ? volatility_is_volatile : volatility_non_volatile",
945 to_flags = "%s == volatility_is_volatile ? cons_volatile : cons_none"
950 comment = "pointers to unaligned stores don't need to respect the load-mode/type alignments",
951 init = "flags & cons_unaligned ? align_non_aligned : align_is_aligned",
952 to_flags = "%s == align_non_aligned ? cons_unaligned : cons_none"
957 type = "ir_cons_flags",
959 comment = "specifies alignment, volatility and pin state",
965 """returns the difference of its operands"""
970 """A symbolic constant.
972 - *symconst_type_size* The symbolic constant represents the size of a type.
973 The type of which the constant represents the size
975 - *symconst_type_align* The symbolic constant represents the alignment of a
976 type. The type of which the constant represents the
977 size is given explicitly.
978 - *symconst_addr_ent* The symbolic constant represents the address of an
979 entity (variable or method). The variable is given
980 explicitly by a firm entity.
981 - *symconst_ofs_ent* The symbolic constant represents the offset of an
982 entity in its owner type.
983 - *symconst_enum_const* The symbolic constant is a enumeration constant of
984 an enumeration type."""
986 flags = [ "constlike", "start_block" ]
994 comment = "entity whose address is returned",
997 attr_struct = "symconst_attr"
998 customSerializer = True
999 # constructor is written manually at the moment, because of the strange
1001 noconstructor = True
1005 """The Sync operation unifies several partial memory blocks. These blocks
1006 have to be pairwise disjunct or the values in common locations have to
1007 be identical. This operation allows to specify all operations that
1008 eventually need several partial memory blocks as input with a single
1009 entrance by unifying the memories with a preceding Sync operation."""
1017 """Builds a Tuple from single values.
1019 This is needed to implement optimizations that remove a node that produced
1020 a tuple. The node can be replaced by the Tuple operation so that the
1021 following Proj nodes have not to be changed. (They are hard to find due to
1022 the implementation with pointers in only one direction.) The Tuple node is
1023 smaller than any other node, so that a node can be changed into a Tuple by
1024 just changing its opcode and giving it a new in array."""
1032 """Returns an unknown (at compile- and runtime) value. It is a valid
1033 optimisation to replace an Unknown by any other constant value."""
1036 block = "get_irg_start_block(irg)"
1037 flags = [ "start_block", "constlike", "dump_noblock" ]