gccint: RTL Template
1
1 17.4 RTL Template
1 =================
1
1 The RTL template is used to define which insns match the particular
1 pattern and how to find their operands. For named patterns, the RTL
1 template also says how to construct an insn from specified operands.
1
1 Construction involves substituting specified operands into a copy of
1 the template. Matching involves determining the values that serve as
1 the operands in the insn being matched. Both of these activities are
1 controlled by special expression types that direct matching and
1 substitution of the operands.
1
1 '(match_operand:M N PREDICATE CONSTRAINT)'
1 This expression is a placeholder for operand number N of the insn.
1 When constructing an insn, operand number N will be substituted at
1 this point. When matching an insn, whatever appears at this
1 position in the insn will be taken as operand number N; but it must
1 satisfy PREDICATE or this instruction pattern will not match at
1 all.
1
1 Operand numbers must be chosen consecutively counting from zero in
1 each instruction pattern. There may be only one 'match_operand'
1 expression in the pattern for each operand number. Usually
1 operands are numbered in the order of appearance in 'match_operand'
1 expressions. In the case of a 'define_expand', any operand numbers
1 used only in 'match_dup' expressions have higher values than all
1 other operand numbers.
1
1 PREDICATE is a string that is the name of a function that accepts
11 two arguments, an expression and a machine mode. ⇒
Predicates. During matching, the function will be called with
1 the putative operand as the expression and M as the mode argument
1 (if M is not specified, 'VOIDmode' will be used, which normally
1 causes PREDICATE to accept any mode). If it returns zero, this
1 instruction pattern fails to match. PREDICATE may be an empty
1 string; then it means no test is to be done on the operand, so
1 anything which occurs in this position is valid.
1
1 Most of the time, PREDICATE will reject modes other than M--but not
1 always. For example, the predicate 'address_operand' uses M as the
1 mode of memory ref that the address should be valid for. Many
1 predicates accept 'const_int' nodes even though their mode is
1 'VOIDmode'.
1
1 CONSTRAINT controls reloading and the choice of the best register
1 class to use for a value, as explained later (⇒Constraints).
1 If the constraint would be an empty string, it can be omitted.
1
1 People are often unclear on the difference between the constraint
1 and the predicate. The predicate helps decide whether a given insn
1 matches the pattern. The constraint plays no role in this
1 decision; instead, it controls various decisions in the case of an
1 insn which does match.
1
1 '(match_scratch:M N CONSTRAINT)'
1 This expression is also a placeholder for operand number N and
1 indicates that operand must be a 'scratch' or 'reg' expression.
1
1 When matching patterns, this is equivalent to
1
1 (match_operand:M N "scratch_operand" CONSTRAINT)
1
1 but, when generating RTL, it produces a ('scratch':M) expression.
1
1 If the last few expressions in a 'parallel' are 'clobber'
1 expressions whose operands are either a hard register or
1 'match_scratch', the combiner can add or delete them when
1 necessary. ⇒Side Effects.
1
1 '(match_dup N)'
1 This expression is also a placeholder for operand number N. It is
1 used when the operand needs to appear more than once in the insn.
1
1 In construction, 'match_dup' acts just like 'match_operand': the
1 operand is substituted into the insn being constructed. But in
1 matching, 'match_dup' behaves differently. It assumes that operand
1 number N has already been determined by a 'match_operand' appearing
1 earlier in the recognition template, and it matches only an
1 identical-looking expression.
1
1 Note that 'match_dup' should not be used to tell the compiler that
1 a particular register is being used for two operands (example:
1 'add' that adds one register to another; the second register is
1 both an input operand and the output operand). Use a matching
1 constraint (⇒Simple Constraints) for those. 'match_dup' is
1 for the cases where one operand is used in two places in the
1 template, such as an instruction that computes both a quotient and
1 a remainder, where the opcode takes two input operands but the RTL
1 template has to refer to each of those twice; once for the quotient
1 pattern and once for the remainder pattern.
1
1 '(match_operator:M N PREDICATE [OPERANDS...])'
1 This pattern is a kind of placeholder for a variable RTL expression
1 code.
1
1 When constructing an insn, it stands for an RTL expression whose
1 expression code is taken from that of operand N, and whose operands
1 are constructed from the patterns OPERANDS.
1
1 When matching an expression, it matches an expression if the
1 function PREDICATE returns nonzero on that expression _and_ the
1 patterns OPERANDS match the operands of the expression.
1
1 Suppose that the function 'commutative_operator' is defined as
1 follows, to match any expression whose operator is one of the
1 commutative arithmetic operators of RTL and whose mode is MODE:
1
1 int
1 commutative_integer_operator (x, mode)
1 rtx x;
1 machine_mode mode;
1 {
1 enum rtx_code code = GET_CODE (x);
1 if (GET_MODE (x) != mode)
1 return 0;
1 return (GET_RTX_CLASS (code) == RTX_COMM_ARITH
1 || code == EQ || code == NE);
1 }
1
1 Then the following pattern will match any RTL expression consisting
1 of a commutative operator applied to two general operands:
1
1 (match_operator:SI 3 "commutative_operator"
1 [(match_operand:SI 1 "general_operand" "g")
1 (match_operand:SI 2 "general_operand" "g")])
1
1 Here the vector '[OPERANDS...]' contains two patterns because the
1 expressions to be matched all contain two operands.
1
1 When this pattern does match, the two operands of the commutative
1 operator are recorded as operands 1 and 2 of the insn. (This is
1 done by the two instances of 'match_operand'.) Operand 3 of the
1 insn will be the entire commutative expression: use 'GET_CODE
1 (operands[3])' to see which commutative operator was used.
1
1 The machine mode M of 'match_operator' works like that of
1 'match_operand': it is passed as the second argument to the
1 predicate function, and that function is solely responsible for
1 deciding whether the expression to be matched "has" that mode.
1
1 When constructing an insn, argument 3 of the gen-function will
1 specify the operation (i.e. the expression code) for the expression
1 to be made. It should be an RTL expression, whose expression code
1 is copied into a new expression whose operands are arguments 1 and
1 2 of the gen-function. The subexpressions of argument 3 are not
1 used; only its expression code matters.
1
1 When 'match_operator' is used in a pattern for matching an insn, it
1 usually best if the operand number of the 'match_operator' is
1 higher than that of the actual operands of the insn. This improves
1 register allocation because the register allocator often looks at
1 operands 1 and 2 of insns to see if it can do register tying.
1
1 There is no way to specify constraints in 'match_operator'. The
1 operand of the insn which corresponds to the 'match_operator' never
1 has any constraints because it is never reloaded as a whole.
1 However, if parts of its OPERANDS are matched by 'match_operand'
1 patterns, those parts may have constraints of their own.
1
1 '(match_op_dup:M N[OPERANDS...])'
1 Like 'match_dup', except that it applies to operators instead of
1 operands. When constructing an insn, operand number N will be
1 substituted at this point. But in matching, 'match_op_dup' behaves
1 differently. It assumes that operand number N has already been
1 determined by a 'match_operator' appearing earlier in the
1 recognition template, and it matches only an identical-looking
1 expression.
1
1 '(match_parallel N PREDICATE [SUBPAT...])'
1 This pattern is a placeholder for an insn that consists of a
1 'parallel' expression with a variable number of elements. This
1 expression should only appear at the top level of an insn pattern.
1
1 When constructing an insn, operand number N will be substituted at
1 this point. When matching an insn, it matches if the body of the
1 insn is a 'parallel' expression with at least as many elements as
1 the vector of SUBPAT expressions in the 'match_parallel', if each
1 SUBPAT matches the corresponding element of the 'parallel', _and_
1 the function PREDICATE returns nonzero on the 'parallel' that is
1 the body of the insn. It is the responsibility of the predicate to
1 validate elements of the 'parallel' beyond those listed in the
1 'match_parallel'.
1
1 A typical use of 'match_parallel' is to match load and store
1 multiple expressions, which can contain a variable number of
1 elements in a 'parallel'. For example,
1
1 (define_insn ""
1 [(match_parallel 0 "load_multiple_operation"
1 [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
1 (match_operand:SI 2 "memory_operand" "m"))
1 (use (reg:SI 179))
1 (clobber (reg:SI 179))])]
1 ""
1 "loadm 0,0,%1,%2")
1
1 This example comes from 'a29k.md'. The function
1 'load_multiple_operation' is defined in 'a29k.c' and checks that
1 subsequent elements in the 'parallel' are the same as the 'set' in
1 the pattern, except that they are referencing subsequent registers
1 and memory locations.
1
1 An insn that matches this pattern might look like:
1
1 (parallel
1 [(set (reg:SI 20) (mem:SI (reg:SI 100)))
1 (use (reg:SI 179))
1 (clobber (reg:SI 179))
1 (set (reg:SI 21)
1 (mem:SI (plus:SI (reg:SI 100)
1 (const_int 4))))
1 (set (reg:SI 22)
1 (mem:SI (plus:SI (reg:SI 100)
1 (const_int 8))))])
1
1 '(match_par_dup N [SUBPAT...])'
1 Like 'match_op_dup', but for 'match_parallel' instead of
1 'match_operator'.
1