Previous:Defining Machine-Specific Constraints, Up:Operand Constraints [Contents][Index]
It is occasionally useful to test a constraint from C code rather thanimplicitly via the constraint string in amatch_operand. Thegenerated filetm_p.h declares a few interfaces for workingwith constraints. At present these are defined for all constraintsexceptg (which is equivalent togeneral_operand).
Some valid constraint names are not valid C identifiers, so there is amangling scheme for referring to them from C. Constraint names thatdo not contain angle brackets or underscores are left unchanged.Underscores are doubled, each ‘<’ is replaced with ‘_l’, andeach ‘>’ with ‘_g’. Here are some examples:
Original | Mangled |
| |
| |
| |
| |
| |
| |
Throughout this section, the variablec is either a constraintin the abstract sense, or a constant fromenum constraint_num;the variablem is a mangled constraint name (usually as part ofa larger identifier).
For each constraint exceptg, there is a correspondingenumeration constant: ‘CONSTRAINT_’ plus the mangled name of theconstraint. Functions that take anenum constraint_num as anargument expect one of these constants.
inline boolsatisfies_constraint_m(rtxexp) ¶For each non-register constraintm exceptg, there isone of these functions; it returnstrue ifexp satisfies theconstraint. These functions are only visible ifrtl.h was includedbeforetm_p.h.
boolconstraint_satisfied_p(rtxexp, enum constraint_numc) ¶Like thesatisfies_constraint_m functions, but theconstraint to test is given as an argument,c. Ifcspecifies a register constraint, this function will always returnfalse.
enum reg_classreg_class_for_constraint(enum constraint_numc) ¶Returns the register class associated withc. Ifc is nota register constraint, or those registers are not available for thecurrently selected subtarget, returnsNO_REGS.
Here is an example use ofsatisfies_constraint_m. Inpeephole optimizations (seeMachine-Specific Peephole Optimizers), operandconstraint strings are ignored, so if there are relevant constraints,they must be tested in the C condition. In the example, theoptimization is applied if operand 2 doesnot satisfy the‘K’ constraint. (This is a simplified version of a peepholedefinition from the i386 machine description.)
(define_peephole2 [(match_scratch:SI 3 "r") (set (match_operand:SI 0 "register_operand" "") (mult:SI (match_operand:SI 1 "memory_operand" "") (match_operand:SI 2 "immediate_operand" "")))] "!satisfies_constraint_K (operands[2])" [(set (match_dup 3) (match_dup 1)) (set (match_dup 0) (mult:SI (match_dup 3) (match_dup 2)))] "")
Previous:Defining Machine-Specific Constraints, Up:Operand Constraints [Contents][Index]