gccint: C Constraint Interface
1
1 17.8.8 Testing constraints from C
1 ---------------------------------
1
1 It is occasionally useful to test a constraint from C code rather than
1 implicitly via the constraint string in a 'match_operand'. The
1 generated file 'tm_p.h' declares a few interfaces for working with
1 constraints. At present these are defined for all constraints except
1 'g' (which is equivalent to 'general_operand').
1
1 Some valid constraint names are not valid C identifiers, so there is a
1 mangling scheme for referring to them from C. Constraint names that do
1 not contain angle brackets or underscores are left unchanged.
1 Underscores are doubled, each '<' is replaced with '_l', and each '>'
1 with '_g'. Here are some examples:
1
1 *Original* *Mangled*
1 x x
1 P42x P42x
1 P4_x P4__x
1 P4>x P4_gx
1 P4>> P4_g_g
1 P4_g> P4__g_g
1
1 Throughout this section, the variable C is either a constraint in the
1 abstract sense, or a constant from 'enum constraint_num'; the variable M
1 is a mangled constraint name (usually as part of a larger identifier).
1
1 -- Enum: constraint_num
1 For each constraint except 'g', there is a corresponding
1 enumeration constant: 'CONSTRAINT_' plus the mangled name of the
1 constraint. Functions that take an 'enum constraint_num' as an
1 argument expect one of these constants.
1
1 -- Function: inline bool satisfies_constraint_M (rtx EXP)
1 For each non-register constraint M except 'g', there is one of
1 these functions; it returns 'true' if EXP satisfies the constraint.
1 These functions are only visible if 'rtl.h' was included before
1 'tm_p.h'.
1
1 -- Function: bool constraint_satisfied_p (rtx EXP, enum constraint_num
1 C)
1 Like the 'satisfies_constraint_M' functions, but the constraint to
1 test is given as an argument, C. If C specifies a register
1 constraint, this function will always return 'false'.
1
1 -- Function: enum reg_class reg_class_for_constraint (enum
1 constraint_num C)
1 Returns the register class associated with C. If C is not a
1 register constraint, or those registers are not available for the
1 currently selected subtarget, returns 'NO_REGS'.
1
1 Here is an example use of 'satisfies_constraint_M'. In peephole
1 optimizations (⇒Peephole Definitions), operand constraint strings
1 are ignored, so if there are relevant constraints, they must be tested
1 in the C condition. In the example, the optimization is applied if
1 operand 2 does _not_ satisfy the 'K' constraint. (This is a simplified
1 version of a peephole definition from the i386 machine description.)
1
1 (define_peephole2
1 [(match_scratch:SI 3 "r")
1 (set (match_operand:SI 0 "register_operand" "")
1 (mult:SI (match_operand:SI 1 "memory_operand" "")
1 (match_operand:SI 2 "immediate_operand" "")))]
1
1 "!satisfies_constraint_K (operands[2])"
1
1 [(set (match_dup 3) (match_dup 1))
1 (set (match_dup 0) (mult:SI (match_dup 3) (match_dup 2)))]
1
1 "")
1