gccint: Define Constraints

1 
1 17.8.7 Defining Machine-Specific Constraints
1 --------------------------------------------
1 
1 Machine-specific constraints fall into two categories: register and
1 non-register constraints.  Within the latter category, constraints which
1 allow subsets of all possible memory or address operands should be
1 specially marked, to give 'reload' more information.
1 
1  Machine-specific constraints can be given names of arbitrary length,
1 but they must be entirely composed of letters, digits, underscores
1 ('_'), and angle brackets ('< >').  Like C identifiers, they must begin
1 with a letter or underscore.
1 
1  In order to avoid ambiguity in operand constraint strings, no
1 constraint can have a name that begins with any other constraint's name.
1 For example, if 'x' is defined as a constraint name, 'xy' may not be,
1 and vice versa.  As a consequence of this rule, no constraint may begin
1 with one of the generic constraint letters: 'E F V X g i m n o p r s'.
1 
11  Register constraints correspond directly to register classes.  ⇒
 Register Classes.  There is thus not much flexibility in their
1 definitions.
1 
1  -- MD Expression: define_register_constraint name regclass docstring
1      All three arguments are string constants.  NAME is the name of the
1      constraint, as it will appear in 'match_operand' expressions.  If
1      NAME is a multi-letter constraint its length shall be the same for
1      all constraints starting with the same letter.  REGCLASS can be
11      either the name of the corresponding register class (⇒Register
      Classes), or a C expression which evaluates to the appropriate
1      register class.  If it is an expression, it must have no side
1      effects, and it cannot look at the operand.  The usual use of
1      expressions is to map some register constraints to 'NO_REGS' when
1      the register class is not available on a given subarchitecture.
1 
1      DOCSTRING is a sentence documenting the meaning of the constraint.
1      Docstrings are explained further below.
1 
1  Non-register constraints are more like predicates: the constraint
1 definition gives a boolean expression which indicates whether the
1 constraint matches.
1 
1  -- MD Expression: define_constraint name docstring exp
1      The NAME and DOCSTRING arguments are the same as for
1      'define_register_constraint', but note that the docstring comes
1      immediately after the name for these expressions.  EXP is an RTL
1      expression, obeying the same rules as the RTL expressions in
1      predicate definitions.  ⇒Defining Predicates, for details.
1      If it evaluates true, the constraint matches; if it evaluates
1      false, it doesn't.  Constraint expressions should indicate which
1      RTL codes they might match, just like predicate expressions.
1 
1      'match_test' C expressions have access to the following variables:
1 
1      OP
1           The RTL object defining the operand.
1      MODE
1           The machine mode of OP.
1      IVAL
1           'INTVAL (OP)', if OP is a 'const_int'.
1      HVAL
1           'CONST_DOUBLE_HIGH (OP)', if OP is an integer 'const_double'.
1      LVAL
1           'CONST_DOUBLE_LOW (OP)', if OP is an integer 'const_double'.
1      RVAL
1           'CONST_DOUBLE_REAL_VALUE (OP)', if OP is a floating-point
1           'const_double'.
1 
1      The *VAL variables should only be used once another piece of the
1      expression has verified that OP is the appropriate kind of RTL
1      object.
1 
1  Most non-register constraints should be defined with
1 'define_constraint'.  The remaining two definition expressions are only
1 appropriate for constraints that should be handled specially by 'reload'
1 if they fail to match.
1 
1  -- MD Expression: define_memory_constraint name docstring exp
1      Use this expression for constraints that match a subset of all
1      memory operands: that is, 'reload' can make them match by
1      converting the operand to the form '(mem (reg X))', where X is a
1      base register (from the register class specified by
1      'BASE_REG_CLASS', ⇒Register Classes).
1 
1      For example, on the S/390, some instructions do not accept
1      arbitrary memory references, but only those that do not make use of
1      an index register.  The constraint letter 'Q' is defined to
1      represent a memory address of this type.  If 'Q' is defined with
1      'define_memory_constraint', a 'Q' constraint can handle any memory
1      operand, because 'reload' knows it can simply copy the memory
1      address into a base register if required.  This is analogous to the
1      way an 'o' constraint can handle any memory operand.
1 
1      The syntax and semantics are otherwise identical to
1      'define_constraint'.
1 
1  -- MD Expression: define_special_memory_constraint name docstring exp
1      Use this expression for constraints that match a subset of all
1      memory operands: that is, 'reload' can not make them match by
1      reloading the address as it is described for
1      'define_memory_constraint' or such address reload is undesirable
1      with the performance point of view.
1 
1      For example, 'define_special_memory_constraint' can be useful if
1      specifically aligned memory is necessary or desirable for some insn
1      operand.
1 
1      The syntax and semantics are otherwise identical to
1      'define_constraint'.
1 
1  -- MD Expression: define_address_constraint name docstring exp
1      Use this expression for constraints that match a subset of all
1      address operands: that is, 'reload' can make the constraint match
1      by converting the operand to the form '(reg X)', again with X a
1      base register.
1 
1      Constraints defined with 'define_address_constraint' can only be
1      used with the 'address_operand' predicate, or machine-specific
1      predicates that work the same way.  They are treated analogously to
1      the generic 'p' constraint.
1 
1      The syntax and semantics are otherwise identical to
1      'define_constraint'.
1 
1  For historical reasons, names beginning with the letters 'G H' are
1 reserved for constraints that match only 'const_double's, and names
1 beginning with the letters 'I J K L M N O P' are reserved for
1 constraints that match only 'const_int's.  This may change in the
1 future.  For the time being, constraints with these names must be
1 written in a stylized form, so that 'genpreds' can tell you did it
1 correctly:
1 
1      (define_constraint "[GHIJKLMNOP]..."
1        "DOC..."
1        (and (match_code "const_int")  ; 'const_double' for G/H
1             CONDITION...))            ; usually a 'match_test'
1 
1  It is fine to use names beginning with other letters for constraints
1 that match 'const_double's or 'const_int's.
1 
1  Each docstring in a constraint definition should be one or more
1 complete sentences, marked up in Texinfo format.  _They are currently
1 unused._  In the future they will be copied into the GCC manual, in
1 ⇒Machine Constraints, replacing the hand-maintained tables
1 currently found in that section.  Also, in the future the compiler may
1 use this to give more helpful diagnostics when poor choice of 'asm'
1 constraints causes a reload failure.
1 
1  If you put the pseudo-Texinfo directive '@internal' at the beginning of
1 a docstring, then (in the future) it will appear only in the internals
1 manual's version of the machine-specific constraint tables.  Use this
1 for constraints that should not appear in 'asm' statements.
1