gccint: Defining Predicates
1
1 17.7.2 Defining Machine-Specific Predicates
1 -------------------------------------------
1
1 Many machines have requirements for their operands that cannot be
1 expressed precisely using the generic predicates. You can define
1 additional predicates using 'define_predicate' and
1 'define_special_predicate' expressions. These expressions have three
1 operands:
1
1 * The name of the predicate, as it will be referred to in
1 'match_operand' or 'match_operator' expressions.
1
1 * An RTL expression which evaluates to true if the predicate allows
1 the operand OP, false if it does not. This expression can only use
1 the following RTL codes:
1
1 'MATCH_OPERAND'
1 When written inside a predicate expression, a 'MATCH_OPERAND'
1 expression evaluates to true if the predicate it names would
1 allow OP. The operand number and constraint are ignored. Due
1 to limitations in 'genrecog', you can only refer to generic
1 predicates and predicates that have already been defined.
1
1 'MATCH_CODE'
1 This expression evaluates to true if OP or a specified
1 subexpression of OP has one of a given list of RTX codes.
1
1 The first operand of this expression is a string constant
1 containing a comma-separated list of RTX code names (in lower
1 case). These are the codes for which the 'MATCH_CODE' will be
1 true.
1
1 The second operand is a string constant which indicates what
1 subexpression of OP to examine. If it is absent or the empty
1 string, OP itself is examined. Otherwise, the string constant
1 must be a sequence of digits and/or lowercase letters. Each
1 character indicates a subexpression to extract from the
1 current expression; for the first character this is OP, for
1 the second and subsequent characters it is the result of the
1 previous character. A digit N extracts 'XEXP (E, N)'; a
1 letter L extracts 'XVECEXP (E, 0, N)' where N is the
1 alphabetic ordinal of L (0 for 'a', 1 for 'b', and so on).
1 The 'MATCH_CODE' then examines the RTX code of the
1 subexpression extracted by the complete string. It is not
1 possible to extract components of an 'rtvec' that is not at
1 position 0 within its RTX object.
1
1 'MATCH_TEST'
1 This expression has one operand, a string constant containing
1 a C expression. The predicate's arguments, OP and MODE, are
1 available with those names in the C expression. The
1 'MATCH_TEST' evaluates to true if the C expression evaluates
1 to a nonzero value. 'MATCH_TEST' expressions must not have
1 side effects.
1
1 'AND'
1 'IOR'
1 'NOT'
1 'IF_THEN_ELSE'
1 The basic 'MATCH_' expressions can be combined using these
1 logical operators, which have the semantics of the C operators
1 '&&', '||', '!', and '? :' respectively. As in Common Lisp,
1 you may give an 'AND' or 'IOR' expression an arbitrary number
1 of arguments; this has exactly the same effect as writing a
1 chain of two-argument 'AND' or 'IOR' expressions.
1
1 * An optional block of C code, which should execute 'return true' if
1 the predicate is found to match and 'return false' if it does not.
1 It must not have any side effects. The predicate arguments, OP and
1 MODE, are available with those names.
1
1 If a code block is present in a predicate definition, then the RTL
1 expression must evaluate to true _and_ the code block must execute
1 'return true' for the predicate to allow the operand. The RTL
1 expression is evaluated first; do not re-check anything in the code
1 block that was checked in the RTL expression.
1
1 The program 'genrecog' scans 'define_predicate' and
1 'define_special_predicate' expressions to determine which RTX codes are
1 possibly allowed. You should always make this explicit in the RTL
1 predicate expression, using 'MATCH_OPERAND' and 'MATCH_CODE'.
1
1 Here is an example of a simple predicate definition, from the IA64
1 machine description:
1
1 ;; True if OP is a 'SYMBOL_REF' which refers to the sdata section.
1 (define_predicate "small_addr_symbolic_operand"
1 (and (match_code "symbol_ref")
1 (match_test "SYMBOL_REF_SMALL_ADDR_P (op)")))
1
1 And here is another, showing the use of the C block.
1
1 ;; True if OP is a register operand that is (or could be) a GR reg.
1 (define_predicate "gr_register_operand"
1 (match_operand 0 "register_operand")
1 {
1 unsigned int regno;
1 if (GET_CODE (op) == SUBREG)
1 op = SUBREG_REG (op);
1
1 regno = REGNO (op);
1 return (regno >= FIRST_PSEUDO_REGISTER || GENERAL_REGNO_P (regno));
1 })
1
1 Predicates written with 'define_predicate' automatically include a test
1 that MODE is 'VOIDmode', or OP has the same mode as MODE, or OP is a
1 'CONST_INT' or 'CONST_DOUBLE'. They do _not_ check specifically for
1 integer 'CONST_DOUBLE', nor do they test that the value of either kind
1 of constant fits in the requested mode. This is because target-specific
1 predicates that take constants usually have to do more stringent value
1 checks anyway. If you need the exact same treatment of 'CONST_INT' or
1 'CONST_DOUBLE' that the generic predicates provide, use a
1 'MATCH_OPERAND' subexpression to call 'const_int_operand',
1 'const_double_operand', or 'immediate_operand'.
1
1 Predicates written with 'define_special_predicate' do not get any
1 automatic mode checks, and are treated as having special mode handling
1 by 'genrecog'.
1
1 The program 'genpreds' is responsible for generating code to test
1 predicates. It also writes a header file containing function
1 declarations for all machine-specific predicates. It is not necessary
1 to declare these predicates in 'CPU-protos.h'.
1