📄 md.texi
字号:
number @var{n} has already been determined by a @code{match_operand}appearing earlier in the recognition template, and it matches only anidentical-looking expression.Note that @code{match_dup} should not be used to tell the compiler thata particular register is being used for two operands (example:@code{add} that adds one register to another; the second register isboth an input operand and the output operand). Use a matchingconstraint (@pxref{Simple Constraints}) for those. @code{match_dup} is for the cases where oneoperand is used in two places in the template, such as an instructionthat computes both a quotient and a remainder, where the opcode takestwo input operands but the RTL template has to refer to each of thosetwice; once for the quotient pattern and once for the remainder pattern.@findex match_operator@item (match_operator:@var{m} @var{n} @var{predicate} [@var{operands}@dots{}])This pattern is a kind of placeholder for a variable RTL expressioncode.When constructing an insn, it stands for an RTL expression whoseexpression code is taken from that of operand @var{n}, and whoseoperands are constructed from the patterns @var{operands}.When matching an expression, it matches an expression if the function@var{predicate} returns nonzero on that expression @emph{and} thepatterns @var{operands} match the operands of the expression.Suppose that the function @code{commutative_operator} is defined asfollows, to match any expression whose operator is one of thecommutative arithmetic operators of RTL and whose mode is @var{mode}:@smallexampleintcommutative_integer_operator (x, mode) rtx x; enum machine_mode mode;@{ enum rtx_code code = GET_CODE (x); if (GET_MODE (x) != mode) return 0; return (GET_RTX_CLASS (code) == RTX_COMM_ARITH || code == EQ || code == NE);@}@end smallexampleThen the following pattern will match any RTL expression consistingof a commutative operator applied to two general operands:@smallexample(match_operator:SI 3 "commutative_operator" [(match_operand:SI 1 "general_operand" "g") (match_operand:SI 2 "general_operand" "g")])@end smallexampleHere the vector @code{[@var{operands}@dots{}]} contains two patternsbecause the expressions to be matched all contain two operands.When this pattern does match, the two operands of the commutativeoperator are recorded as operands 1 and 2 of the insn. (This is doneby the two instances of @code{match_operand}.) Operand 3 of the insnwill be the entire commutative expression: use @code{GET_CODE(operands[3])} to see which commutative operator was used.The machine mode @var{m} of @code{match_operator} works like that of@code{match_operand}: it is passed as the second argument to thepredicate function, and that function is solely responsible fordeciding whether the expression to be matched ``has'' that mode.When constructing an insn, argument 3 of the gen-function will specifythe operation (i.e.@: the expression code) for the expression to bemade. It should be an RTL expression, whose expression code is copiedinto a new expression whose operands are arguments 1 and 2 of thegen-function. The subexpressions of argument 3 are not used;only its expression code matters.When @code{match_operator} is used in a pattern for matching an insn,it usually best if the operand number of the @code{match_operator}is higher than that of the actual operands of the insn. This improvesregister allocation because the register allocator often looks atoperands 1 and 2 of insns to see if it can do register tying.There is no way to specify constraints in @code{match_operator}. Theoperand of the insn which corresponds to the @code{match_operator}never has any constraints because it is never reloaded as a whole.However, if parts of its @var{operands} are matched by@code{match_operand} patterns, those parts may have constraints oftheir own.@findex match_op_dup@item (match_op_dup:@var{m} @var{n}[@var{operands}@dots{}])Like @code{match_dup}, except that it applies to operators instead ofoperands. When constructing an insn, operand number @var{n} will besubstituted at this point. But in matching, @code{match_op_dup} behavesdifferently. It assumes that operand number @var{n} has already beendetermined by a @code{match_operator} appearing earlier in therecognition template, and it matches only an identical-lookingexpression.@findex match_parallel@item (match_parallel @var{n} @var{predicate} [@var{subpat}@dots{}])This pattern is a placeholder for an insn that consists of a@code{parallel} expression with a variable number of elements. Thisexpression should only appear at the top level of an insn pattern.When constructing an insn, operand number @var{n} will be substituted atthis point. When matching an insn, it matches if the body of the insnis a @code{parallel} expression with at least as many elements as thevector of @var{subpat} expressions in the @code{match_parallel}, if each@var{subpat} matches the corresponding element of the @code{parallel},@emph{and} the function @var{predicate} returns nonzero on the@code{parallel} that is the body of the insn. It is the responsibilityof the predicate to validate elements of the @code{parallel} beyondthose listed in the @code{match_parallel}.A typical use of @code{match_parallel} is to match load and storemultiple expressions, which can contain a variable number of elementsin a @code{parallel}. For example,@smallexample(define_insn "" [(match_parallel 0 "load_multiple_operation" [(set (match_operand:SI 1 "gpc_reg_operand" "=r") (match_operand:SI 2 "memory_operand" "m")) (use (reg:SI 179)) (clobber (reg:SI 179))])] "" "loadm 0,0,%1,%2")@end smallexampleThis example comes from @file{a29k.md}. The function@code{load_multiple_operation} is defined in @file{a29k.c} and checksthat subsequent elements in the @code{parallel} are the same as the@code{set} in the pattern, except that they are referencing subsequentregisters and memory locations.An insn that matches this pattern might look like:@smallexample(parallel [(set (reg:SI 20) (mem:SI (reg:SI 100))) (use (reg:SI 179)) (clobber (reg:SI 179)) (set (reg:SI 21) (mem:SI (plus:SI (reg:SI 100) (const_int 4)))) (set (reg:SI 22) (mem:SI (plus:SI (reg:SI 100) (const_int 8))))])@end smallexample@findex match_par_dup@item (match_par_dup @var{n} [@var{subpat}@dots{}])Like @code{match_op_dup}, but for @code{match_parallel} instead of@code{match_operator}.@end table@node Output Template@section Output Templates and Operand Substitution@cindex output templates@cindex operand substitution@cindex @samp{%} in template@cindex percent signThe @dfn{output template} is a string which specifies how to output theassembler code for an instruction pattern. Most of the template is afixed string which is output literally. The character @samp{%} is usedto specify where to substitute an operand; it can also be used toidentify places where different variants of the assembler requiredifferent syntax.In the simplest case, a @samp{%} followed by a digit @var{n} says to outputoperand @var{n} at that point in the string.@samp{%} followed by a letter and a digit says to output an operand in analternate fashion. Four letters have standard, built-in meanings describedbelow. The machine description macro @code{PRINT_OPERAND} can defineadditional letters with nonstandard meanings.@samp{%c@var{digit}} can be used to substitute an operand that is aconstant value without the syntax that normally indicates an immediateoperand.@samp{%n@var{digit}} is like @samp{%c@var{digit}} except that the value ofthe constant is negated before printing.@samp{%a@var{digit}} can be used to substitute an operand as if it were amemory reference, with the actual operand treated as the address. This maybe useful when outputting a ``load address'' instruction, because often theassembler syntax for such an instruction requires you to write the operandas if it were a memory reference.@samp{%l@var{digit}} is used to substitute a @code{label_ref} into a jumpinstruction.@samp{%=} outputs a number which is unique to each instruction in theentire compilation. This is useful for making local labels to bereferred to more than once in a single template that generates multipleassembler instructions.@samp{%} followed by a punctuation character specifies a substitution thatdoes not use an operand. Only one case is standard: @samp{%%} outputs a@samp{%} into the assembler code. Other nonstandard cases can bedefined in the @code{PRINT_OPERAND} macro. You must also definewhich punctuation characters are valid with the@code{PRINT_OPERAND_PUNCT_VALID_P} macro.@cindex \@cindex backslashThe template may generate multiple assembler instructions. Write the textfor the instructions, with @samp{\;} between them.@cindex matching operandsWhen the RTL contains two operands which are required by constraint to matcheach other, the output template must refer only to the lower-numbered operand.Matching operands are not always identical, and the rest of the compilerarranges to put the proper RTL expression for printing into the lower-numberedoperand.One use of nonstandard letters or punctuation following @samp{%} is todistinguish between different assembler languages for the same machine; forexample, Motorola syntax versus MIT syntax for the 68000. Motorola syntaxrequires periods in most opcode names, while MIT syntax does not. Forexample, the opcode @samp{movel} in MIT syntax is @samp{move.l} in Motorolasyntax. The same file of patterns is used for both kinds of output syntax,but the character sequence @samp{%.} is used in each place where Motorolasyntax wants a period. The @code{PRINT_OPERAND} macro for Motorola syntaxdefines the sequence to output a period; the macro for MIT syntax definesit to do nothing.@cindex @code{#} in templateAs a special case, a template consisting of the single character @code{#}instructs the compiler to first split the insn, and then output theresulting instructions separately. This helps eliminate redundancy in theoutput templates. If you have a @code{define_insn} that needs to emitmultiple assembler instructions, and there is an matching @code{define_split}already defined, then you can simply use @code{#} as the output templateinstead of writing an output template that emits the multiple assemblerinstructions.If the macro @code{ASSEMBLER_DIALECT} is defined, you can use constructof the form @samp{@{option0|option1|option2@}} in the templates. Thesedescribe multiple variants of assembler language syntax.@xref{Instruction Output}.@node Output Statement@section C Statements for Assembler Output@cindex output statements@cindex C statements for assembler output@cindex generating assembler outputOften a single fixed template string cannot produce correct and efficientassembler code for all the cases that are recognized by a singleinstruction pattern. For example, the opcodes may depend on the kinds ofoperands; or some unfortunate combinations of operands may require extramachine instructions.If the output control string starts with a @samp{@@}, then it is actuallya series of templates, each on a separate line. (Blank lines andleading spaces and tabs are ignored.) The templates correspond to thepattern's constraint alternatives (@pxref{Multi-Alternative}). For example,if a target machine has a two-address add instruction @samp{addr} to addinto a register and another @samp{addm} to add a register to memory, youmight write this pattern:@smallexample(define_insn "addsi3" [(set (match_operand:SI 0 "general_operand" "=r,m") (plus:SI (match_operand:SI 1 "general_operand" "0,0") (match_operand:SI 2 "general_operand" "g,r")))] "" "@@ addr %2,%0 addm %2,%0")@end smallexample@cindex @code{*} in template@cindex asterisk in templateIf the output control string starts with a @samp{*}, then it is not anoutput template but rather a piece of C program that should compute atemplate. It should execute a @code{return} statement to return thetemplate-string you want. Most such templates use C string literals, whichrequire doublequote characters to delimit them. To include thesedoublequote characters in the string, prefix each one with @samp{\}.If the output control string is written as a brace block instead of adouble-quoted string, it is automatically assumed to be C code. In thatcase, it is not necessary to put in a leading asterisk, or to escape thedoublequotes surrounding C string literals.The operands may be found in the array @code{operands}, whose C data typeis @code{rtx []}.It is very common to select different ways of generating assembler codebased on whether an immediate operand is within a certain range. Becareful when doing this, because the result of @code{INTVAL} is aninteger on the host machine. If the host machine has more bits in an@code{int} than the target machine has in the mode in which the constantwill be used, then some of the bits you get from @code{INTVAL} will besuperfluous. For proper results, you must carefully disregard thevalues of those bits.@findex output_asm_insnIt is possible to output an assembler instruction and then go on to outputor compute more of them, using the subroutine @code{output_asm_insn}. Thisreceives two arguments: a template-string and a vector of operands. Thevector may be @code{operands}, or it may be another array of @code{rtx}that you declare locally and initialize yourself.@findex which_alternativeWhen an insn pattern has multiple alternatives in its constraints, oftenthe appearance of the assembler code is determined mostly by which alternativewas matched. When this is so, the C code can test the variable@code{which_alternative}, which is the ordinal number of the alternativethat was actually satisfied (0 for the first, 1 for the second alternative,etc.).For example, suppose there are two opcodes for storing zero, @samp{clrreg}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -