📄 md.texi
字号:
for registers and @samp{clrmem} for memory locations. Here is howa pattern could use @code{which_alternative} to choose between them:@smallexample(define_insn "" [(set (match_operand:SI 0 "general_operand" "=r,m") (const_int 0))] "" @{ return (which_alternative == 0 ? "clrreg %0" : "clrmem %0"); @})@end smallexampleThe example above, where the assembler code to generate was@emph{solely} determined by the alternative, could also have been specifiedas follows, having the output control string start with a @samp{@@}:@smallexample@group(define_insn "" [(set (match_operand:SI 0 "general_operand" "=r,m") (const_int 0))] "" "@@ clrreg %0 clrmem %0")@end group@end smallexample@node Predicates@section Predicates@cindex predicates@cindex operand predicates@cindex operator predicatesA predicate determines whether a @code{match_operand} or@code{match_operator} expression matches, and therefore whether thesurrounding instruction pattern will be used for that combination ofoperands. GCC has a number of machine-independent predicates, and youcan define machine-specific predicates as needed. By convention,predicates used with @code{match_operand} have names that end in@samp{_operand}, and those used with @code{match_operator} have namesthat end in @samp{_operator}.All predicates are Boolean functions (in the mathematical sense) oftwo arguments: the RTL expression that is being considered at thatposition in the instruction pattern, and the machine mode that the@code{match_operand} or @code{match_operator} specifies. In thissection, the first argument is called @var{op} and the second argument@var{mode}. Predicates can be called from C as ordinary two-argumentfunctions; this can be useful in output templates or othermachine-specific code.Operand predicates can allow operands that are not actually acceptableto the hardware, as long as the constraints give reload the ability tofix them up (@pxref{Constraints}). However, GCC will usually generatebetter code if the predicates specify the requirements of the machineinstructions as closely as possible. Reload cannot fix up operandsthat must be constants (``immediate operands''); you must use apredicate that allows only constants, or else enforce the requirementin the extra condition.@cindex predicates and machine modes@cindex normal predicates@cindex special predicatesMost predicates handle their @var{mode} argument in a uniform manner.If @var{mode} is @code{VOIDmode} (unspecified), then @var{op} can haveany mode. If @var{mode} is anything else, then @var{op} must have thesame mode, unless @var{op} is a @code{CONST_INT} or integer@code{CONST_DOUBLE}. These RTL expressions always have@code{VOIDmode}, so it would be counterproductive to check that theirmode matches. Instead, predicates that accept @code{CONST_INT} and/orinteger @code{CONST_DOUBLE} check that the value stored in theconstant will fit in the requested mode.Predicates with this behavior are called @dfn{normal}.@command{genrecog} can optimize the instruction recognizer based onknowledge of how normal predicates treat modes. It can also diagnosecertain kinds of common errors in the use of normal predicates; forinstance, it is almost always an error to use a normal predicatewithout specifying a mode.Predicates that do something different with their @var{mode} argumentare called @dfn{special}. The generic predicates@code{address_operand} and @code{pmode_register_operand} are specialpredicates. @command{genrecog} does not do any optimizations ordiagnosis when special predicates are used.@menu* Machine-Independent Predicates:: Predicates available to all back ends.* Defining Predicates:: How to write machine-specific predicate functions.@end menu@node Machine-Independent Predicates@subsection Machine-Independent Predicates@cindex machine-independent predicates@cindex generic predicatesThese are the generic predicates available to all back ends. They aredefined in @file{recog.c}. The first category of predicates allowonly constant, or @dfn{immediate}, operands.@defun immediate_operandThis predicate allows any sort of constant that fits in @var{mode}.It is an appropriate choice for instructions that take operands thatmust be constant.@end defun@defun const_int_operandThis predicate allows any @code{CONST_INT} expression that fits in@var{mode}. It is an appropriate choice for an immediate operand thatdoes not allow a symbol or label.@end defun@defun const_double_operandThis predicate accepts any @code{CONST_DOUBLE} expression that hasexactly @var{mode}. If @var{mode} is @code{VOIDmode}, it will alsoaccept @code{CONST_INT}. It is intended for immediate floating pointconstants.@end defun@noindentThe second category of predicates allow only some kind of machineregister.@defun register_operandThis predicate allows any @code{REG} or @code{SUBREG} expression thatis valid for @var{mode}. It is often suitable for arithmeticinstruction operands on a RISC machine.@end defun@defun pmode_register_operandThis is a slight variant on @code{register_operand} which works arounda limitation in the machine-description reader.@smallexample(match_operand @var{n} "pmode_register_operand" @var{constraint})@end smallexample@noindentmeans exactly what@smallexample(match_operand:P @var{n} "register_operand" @var{constraint})@end smallexample@noindentwould mean, if the machine-description reader accepted @samp{:P}mode suffixes. Unfortunately, it cannot, because @code{Pmode} is analias for some other mode, and might vary with machine-specificoptions. @xref{Misc}.@end defun@defun scratch_operandThis predicate allows hard registers and @code{SCRATCH} expressions,but not pseudo-registers. It is used internally by @code{match_scratch};it should not be used directly.@end defun@noindentThe third category of predicates allow only some kind of memory reference.@defun memory_operandThis predicate allows any valid reference to a quantity of mode@var{mode} in memory, as determined by the weak form of@code{GO_IF_LEGITIMATE_ADDRESS} (@pxref{Addressing Modes}).@end defun@defun address_operandThis predicate is a little unusual; it allows any operand that is avalid expression for the @emph{address} of a quantity of mode@var{mode}, again determined by the weak form of@code{GO_IF_LEGITIMATE_ADDRESS}. To first order, if@samp{@w{(mem:@var{mode} (@var{exp}))}} is acceptable to@code{memory_operand}, then @var{exp} is acceptable to@code{address_operand}. Note that @var{exp} does not necessarily havethe mode @var{mode}.@end defun@defun indirect_operandThis is a stricter form of @code{memory_operand} which allows onlymemory references with a @code{general_operand} as the addressexpression. New uses of this predicate are discouraged, because@code{general_operand} is very permissive, so it's hard to tell whatan @code{indirect_operand} does or does not allow. If a target hasdifferent requirements for memory operands for different instructions,it is better to define target-specific predicates which enforce thehardware's requirements explicitly.@end defun@defun push_operandThis predicate allows a memory reference suitable for pushing a valueonto the stack. This will be a @code{MEM} which refers to@code{stack_pointer_rtx}, with a side-effect in its address expression(@pxref{Incdec}); which one is determined by the@code{STACK_PUSH_CODE} macro (@pxref{Frame Layout}).@end defun@defun pop_operandThis predicate allows a memory reference suitable for popping a valueoff the stack. Again, this will be a @code{MEM} referring to@code{stack_pointer_rtx}, with a side-effect in its addressexpression. However, this time @code{STACK_POP_CODE} is expected.@end defun@noindentThe fourth category of predicates allow some combination of the aboveoperands.@defun nonmemory_operandThis predicate allows any immediate or register operand valid for @var{mode}.@end defun@defun nonimmediate_operandThis predicate allows any register or memory operand valid for @var{mode}.@end defun@defun general_operandThis predicate allows any immediate, register, or memory operandvalid for @var{mode}.@end defun@noindentFinally, there is one generic operator predicate.@defun comparison_operatorThis predicate matches any expression which performs an arithmeticcomparison in @var{mode}; that is, @code{COMPARISON_P} is true for theexpression code.@end defun@node Defining Predicates@subsection Defining Machine-Specific Predicates@cindex defining predicates@findex define_predicate@findex define_special_predicateMany machines have requirements for their operands that cannot beexpressed precisely using the generic predicates. You can defineadditional predicates using @code{define_predicate} and@code{define_special_predicate} expressions. These expressions havethree operands:@itemize @bullet@itemThe name of the predicate, as it will be referred to in@code{match_operand} or @code{match_operator} expressions.@itemAn RTL expression which evaluates to true if the predicate allows theoperand @var{op}, false if it does not. This expression can only usethe following RTL codes:@table @code@item MATCH_OPERANDWhen written inside a predicate expression, a @code{MATCH_OPERAND}expression evaluates to true if the predicate it names would allow@var{op}. The operand number and constraint are ignored. Due tolimitations in @command{genrecog}, you can only refer to genericpredicates and predicates that have already been defined.@item MATCH_CODEThis expression evaluates to true if @var{op} or a specifiedsubexpression of @var{op} has one of a given list of RTX codes.The first operand of this expression is a string constant containing acomma-separated list of RTX code names (in lower case). These are thecodes for which the @code{MATCH_CODE} will be true.The second operand is a string constant which indicates whatsubexpression of @var{op} to examine. If it is absent or the emptystring, @var{op} itself is examined. Otherwise, the string constantmust be a sequence of digits and/or lowercase letters. Each characterindicates a subexpression to extract from the current expression; forthe first character this is @var{op}, for the second and subsequentcharacters it is the result of the previous character. A digit@var{n} extracts @samp{@w{XEXP (@var{e}, @var{n})}}; a letter @var{l}extracts @samp{@w{XVECEXP (@var{e}, 0, @var{n})}} where @var{n} is thealphabetic ordinal of @var{l} (0 for `a', 1 for 'b', and so on). The@code{MATCH_CODE} then examines the RTX code of the subexpressionextracted by the complete string. It is not possible to extractcomponents of an @code{rtvec} that is not at position 0 within its RTXobject.@item MATCH_TESTThis expression has one operand, a string constant containing a Cexpression. The predicate's arguments, @var{op} and @var{mode}, areavailable with those names in the C expression. The @code{MATCH_TEST}evaluates to true if the C expression evaluates to a nonzero value.@code{MATCH_TEST} expressions must not have side effects.@item AND@itemx IOR@itemx NOT@itemx IF_THEN_ELSEThe basic @samp{MATCH_} expressions can be combined using theselogical operators, which have the semantics of the C operators@samp{&&}, @samp{||}, @samp{!}, and @samp{@w{? :}} respectively. Asin Common Lisp, you may give an @code{AND} or @code{IOR} expression anarbitrary number of arguments; this has exactly the same effect aswriting a chain of two-argument @code{AND} or @code{IOR} expressions.@end table@itemAn optional block of C code, which should execute@samp{@w{return true}} if the predicate is found to match and@samp{@w{return false}} if it does not. It must not have any sideeffects. The predicate arguments, @var{op} and @var{mode}, areavailable with those names.If a code block is present in a predicate definition, then the RTLexpression must evaluate to true @emph{and} the code block mustexecute @samp{@w{return true}} for the predicate to allow the operand.The RTL expression is evaluated first; do not re-check anything in thecode block that was checked in the RTL expression.@end itemize
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -