gccint: Conditional Execution
1
1 17.20 Conditional Execution
1 ===========================
1
1 A number of architectures provide for some form of conditional
1 execution, or predication. The hallmark of this feature is the ability
1 to nullify most of the instructions in the instruction set. When the
1 instruction set is large and not entirely symmetric, it can be quite
1 tedious to describe these forms directly in the '.md' file. An
1 alternative is the 'define_cond_exec' template.
1
1 (define_cond_exec
1 [PREDICATE-PATTERN]
1 "CONDITION"
1 "OUTPUT-TEMPLATE"
1 "OPTIONAL-INSN-ATTRIBUES")
1
1 PREDICATE-PATTERN is the condition that must be true for the insn to be
1 executed at runtime and should match a relational operator. One can use
1 'match_operator' to match several relational operators at once. Any
1 'match_operand' operands must have no more than one alternative.
1
1 CONDITION is a C expression that must be true for the generated pattern
1 to match.
1
1 OUTPUT-TEMPLATE is a string similar to the 'define_insn' output
1 template (⇒Output Template), except that the '*' and '@' special
1 cases do not apply. This is only useful if the assembly text for the
1 predicate is a simple prefix to the main insn. In order to handle the
1 general case, there is a global variable 'current_insn_predicate' that
1 will contain the entire predicate if the current insn is predicated, and
1 will otherwise be 'NULL'.
1
1 OPTIONAL-INSN-ATTRIBUTES is an optional vector of attributes that gets
1 appended to the insn attributes of the produced cond_exec rtx. It can
1 be used to add some distinguishing attribute to cond_exec rtxs produced
1 that way. An example usage would be to use this attribute in
1 conjunction with attributes on the main pattern to disable particular
1 alternatives under certain conditions.
1
1 When 'define_cond_exec' is used, an implicit reference to the
1 'predicable' instruction attribute is made. ⇒Insn Attributes.
1 This attribute must be a boolean (i.e. have exactly two elements in its
1 LIST-OF-VALUES), with the possible values being 'no' and 'yes'. The
1 default and all uses in the insns must be a simple constant, not a
1 complex expressions. It may, however, depend on the alternative, by
1 using a comma-separated list of values. If that is the case, the port
11 should also define an 'enabled' attribute (⇒Disable Insn
Alternatives), which should also allow only 'no' and 'yes' as its
1 values.
1
1 For each 'define_insn' for which the 'predicable' attribute is true, a
1 new 'define_insn' pattern will be generated that matches a predicated
1 version of the instruction. For example,
1
1 (define_insn "addsi"
1 [(set (match_operand:SI 0 "register_operand" "r")
1 (plus:SI (match_operand:SI 1 "register_operand" "r")
1 (match_operand:SI 2 "register_operand" "r")))]
1 "TEST1"
1 "add %2,%1,%0")
1
1 (define_cond_exec
1 [(ne (match_operand:CC 0 "register_operand" "c")
1 (const_int 0))]
1 "TEST2"
1 "(%0)")
1
1 generates a new pattern
1
1 (define_insn ""
1 [(cond_exec
1 (ne (match_operand:CC 3 "register_operand" "c") (const_int 0))
1 (set (match_operand:SI 0 "register_operand" "r")
1 (plus:SI (match_operand:SI 1 "register_operand" "r")
1 (match_operand:SI 2 "register_operand" "r"))))]
1 "(TEST2) && (TEST1)"
1 "(%3) add %2,%1,%0")
1