📄 md.texi
字号:
will 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}.@refillA typical use of @code{match_parallel} is to match load and storemultiple expressions, which can contains a variable number of elementsin a @code{parallel}. For example,@example(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 exampleThis example comes from @file{a29k.md}. The function@code{load_multiple_operations} 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:@example(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 example@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}.@findex address@item (address (match_operand:@var{m} @var{n} "address_operand" ""))This complex of expressions is a placeholder for an operand number@var{n} in a ``load address'' instruction: an operand which specifiesa memory location in the usual way, but for which the actual operandvalue used is the address of the location, not the contents of thelocation.@code{address} expressions never appear in RTL code, only in machinedescriptions. And they are used only in machine descriptions that donot use the operand constraint feature. When operand constraints arein use, the letter @samp{p} in the constraint serves this purpose.@var{m} is the machine mode of the @emph{memory location beingaddressed}, not the machine mode of the address itself. That mode isalways the same on a given target machine (it is @code{Pmode}, whichnormally is @code{SImode}), so there is no point in mentioning it;thus, no machine mode is written in the @code{address} expression. Ifsome day support is added for machines in which addresses of differentkinds of objects appear differently or are used differently (such asthe PDP-10), different formats would perhaps need different machinemodes and these modes might be written in the @code{address}expression.@end table@node Output Template, Output Statement, RTL Template, Machine Desc@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.@node Output Statement, Constraints, Output Template, Machine Desc@section C Statements for Generating 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:@example(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 example@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{\}.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}for registers and @samp{clrmem} for memory locations. Here is howa pattern could use @code{which_alternative} to choose between them:@example(define_insn "" [(set (match_operand:SI 0 "general_operand" "=r,m") (const_int 0))] "" "* return (which_alternative == 0 ? \"clrreg %0\" : \"clrmem %0\"); ")@end exampleThe 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{@@}:@example(define_insn "" [(set (match_operand:SI 0 "general_operand" "=r,m") (const_int 0))] "" "@@ clrreg %0 clrmem %0")@end example@node Constraints, Standard Names, Output Statement, Machine Desc@section Operand Constraints@cindex operand constraints@cindex constraintsEach @code{match_operand} in an instruction pattern can specify aconstraint for the type of operands allowed. Constraints can say whetheran operand may be in a register, and which kinds of register; whether theoperand can be a memory reference, and which kinds of address; whether theoperand may be an immediate constant, and which possible values it mayhave. Constraints can also require two operands to match.@menu* Simple Constraints:: Basic use of constraints.* Multi-Alternative:: When an insn has two alternative constraint-patterns.* Class Preferences:: Constraints guide which hard register to put things in.* Modifiers:: More precise control over effects of constraints.* No Constraints:: Describing a clean machine without constraints.@end menu
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -