⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 md.texi

📁 早期freebsd实现
💻 TEXI
📖 第 1 页 / 共 5 页
字号:
@samp{o} or @samp{m}, constant operands are not a problem.@itemIf the constraint permits a constant and a pseudo register used in an insnwas not allocated to a hard register and is equivalent to a constant,the register will be replaced with the constant.  If the predicate doesnot permit a constant and the insn is re-recognized for some reason, thecompiler will crash.  Thus the predicate must always recognize anyobjects allowed by the constraint.@end itemizeIf the operand's predicate can recognize registers, but the constraint doesnot permit them, it can make the compiler crash.  When this operand happensto be a register, the reload pass will be stymied, because it does not knowhow to copy a register temporarily into memory.@node Multi-Alternative, Class Preferences, Simple Constraints, Constraints@subsection Multiple Alternative Constraints@cindex multiple alternative constraintsSometimes a single instruction has multiple alternative sets of possibleoperands.  For example, on the 68000, a logical-or instruction can combineregister or an immediate value into memory, or it can combine any kind ofoperand into a register; but it cannot combine one memory location intoanother.These constraints are represented as multiple alternatives.  An alternativecan be described by a series of letters for each operand.  The overallconstraint for an operand is made from the letters for this operandfrom the first alternative, a comma, the letters for this operand fromthe second alternative, a comma, and so on until the last alternative.Here is how it is done for fullword logical-or on the 68000:@example(define_insn "iorsi3"  [(set (match_operand:SI 0 "general_operand" "=m,d")        (ior:SI (match_operand:SI 1 "general_operand" "%0,0")                (match_operand:SI 2 "general_operand" "dKs,dmKs")))]  @dots{})@end exampleThe first alternative has @samp{m} (memory) for operand 0, @samp{0} foroperand 1 (meaning it must match operand 0), and @samp{dKs} for operand2.  The second alternative has @samp{d} (data register) for operand 0,@samp{0} for operand 1, and @samp{dmKs} for operand 2.  The @samp{=} and@samp{%} in the constraints apply to all the alternatives; theirmeaning is explained in the next section (@pxref{Class Preferences}).If all the operands fit any one alternative, the instruction is valid.Otherwise, for each alternative, the compiler counts how many instructionsmust be added to copy the operands so that that alternative applies.The alternative requiring the least copying is chosen.  If two alternativesneed the same amount of copying, the one that comes first is chosen.These choices can be altered with the @samp{?} and @samp{!} characters:@table @code@cindex @samp{?} in constraint@cindex question mark@item ?Disparage slightly the alternative that the @samp{?} appears in,as a choice when no alternative applies exactly.  The compiler regardsthis alternative as one unit more costly for each @samp{?} that appearsin it.@cindex @samp{!} in constraint@cindex exclamation point@item !Disparage severely the alternative that the @samp{!} appears in.This alternative can still be used if it fits without reloading,but if reloading is needed, some other alternative will be used.@end tableWhen an insn pattern has multiple alternatives in its constraints, oftenthe appearance of the assembler code is determined mostly by whichalternative was matched.  When this is so, the C code for writing theassembler code can use the variable @code{which_alternative}, which isthe ordinal number of the alternative that was actually satisfied (0 forthe first, 1 for the second alternative, etc.).  @xref{Output Statement}.@node Class Preferences, Modifiers, Multi-Alternative, Constraints@subsection Register Class Preferences@cindex class preference constraints@cindex register class preference constraints@cindex voting between constraint alternativesThe operand constraints have another function: they enable the compilerto decide which kind of hardware register a pseudo register is bestallocated to.  The compiler examines the constraints that apply to theinsns that use the pseudo register, looking for the machine-dependentletters such as @samp{d} and @samp{a} that specify classes of registers.The pseudo register is put in whichever class gets the most ``votes''.The constraint letters @samp{g} and @samp{r} also vote: they vote infavor of a general register.  The machine description says which registersare considered general.Of course, on some machines all registers are equivalent, and no registerclasses are defined.  Then none of this complexity is relevant.@node Modifiers, No Constraints, Class Preferences, Constraints@subsection Constraint Modifier Characters@cindex modifiers in constraints@cindex constraint modifier characters@table @samp@cindex @samp{=} in constraint@item =Means that this operand is write-only for this instruction: the previousvalue is discarded and replaced by output data.@cindex @samp{+} in constraint@item +Means that this operand is both read and written by the instruction.When the compiler fixes up the operands to satisfy the constraints,it needs to know which operands are inputs to the instruction andwhich are outputs from it.  @samp{=} identifies an output; @samp{+}identifies an operand that is both input and output; all other operandsare assumed to be input only.@cindex @samp{&} in constraint@item &Means (in a particular alternative) that this operand is writtenbefore the instruction is finished using the input operands.Therefore, this operand may not lie in a register that is used as aninput operand or as part of any memory address.@samp{&} applies only to the alternative in which it is written.  Inconstraints with multiple alternatives, sometimes one alternativerequires @samp{&} while others do not.  See, for example, the@samp{movdf} insn of the 68000.@samp{&} does not obviate the need to write @samp{=}.@cindex @samp{%} in constraint@item %Declares the instruction to be commutative for this operand and thefollowing operand.  This means that the compiler may interchange thetwo operands if that is the cheapest way to make all operands fit theconstraints.  This is often used in patterns for addition instructionsthat really have only two operands: the result must go in one of thearguments.  Here for example, is how the 68000 halfword-addinstruction is defined:@example(define_insn "addhi3"  [(set (match_operand:HI 0 "general_operand" "=m,r")     (plus:HI (match_operand:HI 1 "general_operand" "%0,0")              (match_operand:HI 2 "general_operand" "di,g")))]  @dots{})@end example@cindex @samp{#} in constraint@item #Says that all following characters, up to the next comma, are to beignored as a constraint.  They are significant only for choosingregister preferences.@cindex @samp{*} in constraint@item *Says that the following character should be ignored when choosingregister preferences.  @samp{*} has no effect on the meaning of theconstraint as a constraint, and no effect on reloading.Here is an example: the 68000 has an instruction to sign-extend ahalfword in a data register, and can also sign-extend a value bycopying it into an address register.  While either kind of register isacceptable, the constraints on an address-register destination areless strict, so it is best if register allocation makes an addressregister its goal.  Therefore, @samp{*} is used so that the @samp{d}constraint letter (for data register) is ignored when computingregister preferences.@example(define_insn "extendhisi2"  [(set (match_operand:SI 0 "general_operand" "=*d,a")        (sign_extend:SI         (match_operand:HI 1 "general_operand" "0,g")))]  @dots{})@end example@end table@node No Constraints,, Modifiers, Constraints@subsection Not Using Constraints@cindex no constraints@cindex not using constraintsSome machines are so clean that operand constraints are not required.  Forexample, on the Vax, an operand valid in one context is valid in any othercontext.  On such a machine, every operand constraint would be @samp{g},excepting only operands of ``load address'' instructions which arewritten as if they referred to a memory location's contents but actualrefer to its address.  They would have constraint @samp{p}.@cindex empty constraintsFor such machines, instead of writing @samp{g} and @samp{p} for allthe constraints, you can choose to write a description with empty constraints.Then you write @samp{""} for the constraint in every @code{match_operand}.Address operands are identified by writing an @code{address} expressionaround the @code{match_operand}, not by their constraints.When the machine description has just empty constraints, certain partsof compilation are skipped, making the compiler faster.  However,few machines actually do not need constraints; all machine descriptionsnow in existence use constraints.@node Standard Names, Pattern Ordering, Constraints, Machine Desc@section Standard Names for Patterns Used in Generation@cindex standard pattern names@cindex pattern names@cindex names, patternHere is a table of the instruction names that are meaningful in the RTLgeneration pass of the compiler.  Giving one of these names to aninstruction pattern tells the RTL generation pass that it can use thepattern in to accomplish a certain task.@table @asis@cindex @code{mov@var{m}} instruction pattern@item @samp{mov@var{m}}Here @var{m} stands for a two-letter machine mode name, in lower case.This instruction pattern moves data with that machine mode from operand1 to operand 0.  For example, @samp{movsi} moves full-word data.If operand 0 is a @code{subreg} with mode @var{m} of a register whoseown mode is wider than @var{m}, the effect of this instruction isto store the specified value in the part of the register that correspondsto mode @var{m}.  The effect on the rest of the register is undefined.This class of patterns is special in several ways.  First of all, eachof these names @emph{must} be defined, because there is no other wayto copy a datum from one place to another.Second, these patterns are not used solely in the RTL generation pass.Even the reload pass can generate move insns to copy values from stackslots into temporary registers.  When it does so, one of the operands isa hard register and the other is an operand that can need to be reloadedinto a register.@findex force_regTherefore, when given such a pair of operands, the pattern must generateRTL which needs no reloading and needs no temporary registers---noregisters other than the operands.  For example, if you support thepattern with a @code{define_expand}, then in such a case the@code{define_expand} mustn't call @code{force_reg} or any other suchfunction which might generate new pseudo registers.This requirement exists even for subword modes on a RISC machine wherefetching those modes from memory normally requires several insns andsome temporary registers.  Look in @file{spur.md} to see how therequirement can be satisfied.@findex change_addressDuring reload a memory reference with an invalid address may be passedas an operand.  Such an address will be replaced with a valid addresslater in the reload pass.  In this case, nothing may be done with theaddress except to use it as it stands.  If it is copied, it will not bereplaced with a valid address.  No attempt should be made to make suchan address into a valid address and no routine (such as@code{change_address}) that will do so may be called.  Note that@code{general_operand} will fail when applied to such an address.@findex reload_in_progressThe global variable @code{reload_in_progress} (which must be explicitlydeclared if required) can be used to determine whether such specialhandling is required.The variety of operands that have reloads depends on the rest of themachine description, but typically on a RISC machine these can only bepseudo registers that did not get hard registers, while on othermachines explicit memory references will get optional reloads.If a scratch register is required to move an object to or from memory,it can be allocated using @code{gen_reg_rtx} prior to reload.  But thisis impossible during and after reload.  If there are cases needingscratch registers after reload, you must define@code{SECONDARY_INPUT_RELOAD_CLASS} and/or@code{SECONDARY_OUTPUT_RELOAD_CLASS} to detect them, and providepatterns @samp{reload_in@var{m}} or @samp{reload_out@var{m}} to handlethem.  @xref{Register Classes}.The constraints on a @samp{move@var{m}} must permit moving any hardregister to any other hard register provided that@code{HARD_REGNO_MODE_OK} permits mode @var{m} in both registers and@code{REGISTER_MOVE_COST} applied to their classes returns a value of 2.It is obligatory to support floating point @samp{move@var{m}}instructions into and out of any registers that can hold fixed pointvalues, because unions and structures (which have modes @code{SImode} or@code{DImode}) can be in those registers and they may have floatingpoint members.There may also be a need to support fixed point @samp{move@var{m}}instructions in and out of floating point registers.  Unfortunately, Ihave forgotten why this was so, and I don't know whether it is stilltrue.  If @code{HARD_REGNO_MODE_OK} rejects fixed point values infloating point registers, then the constraints of the fixed point@samp{move@var{m}} instructions must be designed to avoid ever trying toreload into a floating point register.@cindex @code{reload_in} instruction pattern@cindex @code{reload_out} instruction pattern@item @samp{reload_in@var{m}}@itemx @samp{reload_out@var{m}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -