LLVM API Documentation
00001 //===- X86InstrInfo.h - X86 Instruction Information ------------*- C++ -*- ===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file contains the X86 implementation of the TargetInstrInfo class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef X86INSTRUCTIONINFO_H 00015 #define X86INSTRUCTIONINFO_H 00016 00017 #include "llvm/Target/TargetInstrInfo.h" 00018 #include "X86.h" 00019 #include "X86RegisterInfo.h" 00020 #include "llvm/ADT/DenseMap.h" 00021 #include "llvm/Target/TargetRegisterInfo.h" 00022 00023 namespace llvm { 00024 class X86RegisterInfo; 00025 class X86TargetMachine; 00026 00027 namespace X86 { 00028 // X86 specific condition code. These correspond to X86_*_COND in 00029 // X86InstrInfo.td. They must be kept in synch. 00030 enum CondCode { 00031 COND_A = 0, 00032 COND_AE = 1, 00033 COND_B = 2, 00034 COND_BE = 3, 00035 COND_E = 4, 00036 COND_G = 5, 00037 COND_GE = 6, 00038 COND_L = 7, 00039 COND_LE = 8, 00040 COND_NE = 9, 00041 COND_NO = 10, 00042 COND_NP = 11, 00043 COND_NS = 12, 00044 COND_O = 13, 00045 COND_P = 14, 00046 COND_S = 15, 00047 00048 // Artificial condition codes. These are used by AnalyzeBranch 00049 // to indicate a block terminated with two conditional branches to 00050 // the same location. This occurs in code using FCMP_OEQ or FCMP_UNE, 00051 // which can't be represented on x86 with a single condition. These 00052 // are never used in MachineInstrs. 00053 COND_NE_OR_P, 00054 COND_NP_OR_E, 00055 00056 COND_INVALID 00057 }; 00058 00059 // Turn condition code into conditional branch opcode. 00060 unsigned GetCondBranchFromCond(CondCode CC); 00061 00062 /// GetOppositeBranchCondition - Return the inverse of the specified cond, 00063 /// e.g. turning COND_E to COND_NE. 00064 CondCode GetOppositeBranchCondition(X86::CondCode CC); 00065 00066 } 00067 00068 /// X86II - This namespace holds all of the target specific flags that 00069 /// instruction info tracks. 00070 /// 00071 namespace X86II { 00072 /// Target Operand Flag enum. 00073 enum TOF { 00074 //===------------------------------------------------------------------===// 00075 // X86 Specific MachineOperand flags. 00076 00077 MO_NO_FLAG = 0, 00078 00079 /// MO_GOT_ABSOLUTE_ADDRESS - On a symbol operand, this represents a 00080 /// relocation of: 00081 /// SYMBOL_LABEL + [. - PICBASELABEL] 00082 MO_GOT_ABSOLUTE_ADDRESS = 1, 00083 00084 /// MO_PIC_BASE_OFFSET - On a symbol operand this indicates that the 00085 /// immediate should get the value of the symbol minus the PIC base label: 00086 /// SYMBOL_LABEL - PICBASELABEL 00087 MO_PIC_BASE_OFFSET = 2, 00088 00089 /// MO_GOT - On a symbol operand this indicates that the immediate is the 00090 /// offset to the GOT entry for the symbol name from the base of the GOT. 00091 /// 00092 /// See the X86-64 ELF ABI supplement for more details. 00093 /// SYMBOL_LABEL @GOT 00094 MO_GOT = 3, 00095 00096 /// MO_GOTOFF - On a symbol operand this indicates that the immediate is 00097 /// the offset to the location of the symbol name from the base of the GOT. 00098 /// 00099 /// See the X86-64 ELF ABI supplement for more details. 00100 /// SYMBOL_LABEL @GOTOFF 00101 MO_GOTOFF = 4, 00102 00103 /// MO_GOTPCREL - On a symbol operand this indicates that the immediate is 00104 /// offset to the GOT entry for the symbol name from the current code 00105 /// location. 00106 /// 00107 /// See the X86-64 ELF ABI supplement for more details. 00108 /// SYMBOL_LABEL @GOTPCREL 00109 MO_GOTPCREL = 5, 00110 00111 /// MO_PLT - On a symbol operand this indicates that the immediate is 00112 /// offset to the PLT entry of symbol name from the current code location. 00113 /// 00114 /// See the X86-64 ELF ABI supplement for more details. 00115 /// SYMBOL_LABEL @PLT 00116 MO_PLT = 6, 00117 00118 /// MO_TLSGD - On a symbol operand this indicates that the immediate is 00119 /// some TLS offset. 00120 /// 00121 /// See 'ELF Handling for Thread-Local Storage' for more details. 00122 /// SYMBOL_LABEL @TLSGD 00123 MO_TLSGD = 7, 00124 00125 /// MO_GOTTPOFF - On a symbol operand this indicates that the immediate is 00126 /// some TLS offset. 00127 /// 00128 /// See 'ELF Handling for Thread-Local Storage' for more details. 00129 /// SYMBOL_LABEL @GOTTPOFF 00130 MO_GOTTPOFF = 8, 00131 00132 /// MO_INDNTPOFF - On a symbol operand this indicates that the immediate is 00133 /// some TLS offset. 00134 /// 00135 /// See 'ELF Handling for Thread-Local Storage' for more details. 00136 /// SYMBOL_LABEL @INDNTPOFF 00137 MO_INDNTPOFF = 9, 00138 00139 /// MO_TPOFF - On a symbol operand this indicates that the immediate is 00140 /// some TLS offset. 00141 /// 00142 /// See 'ELF Handling for Thread-Local Storage' for more details. 00143 /// SYMBOL_LABEL @TPOFF 00144 MO_TPOFF = 10, 00145 00146 /// MO_NTPOFF - On a symbol operand this indicates that the immediate is 00147 /// some TLS offset. 00148 /// 00149 /// See 'ELF Handling for Thread-Local Storage' for more details. 00150 /// SYMBOL_LABEL @NTPOFF 00151 MO_NTPOFF = 11, 00152 00153 /// MO_DLLIMPORT - On a symbol operand "FOO", this indicates that the 00154 /// reference is actually to the "__imp_FOO" symbol. This is used for 00155 /// dllimport linkage on windows. 00156 MO_DLLIMPORT = 12, 00157 00158 /// MO_DARWIN_STUB - On a symbol operand "FOO", this indicates that the 00159 /// reference is actually to the "FOO$stub" symbol. This is used for calls 00160 /// and jumps to external functions on Tiger and before. 00161 MO_DARWIN_STUB = 13, 00162 00163 /// MO_DARWIN_NONLAZY - On a symbol operand "FOO", this indicates that the 00164 /// reference is actually to the "FOO$non_lazy_ptr" symbol, which is a 00165 /// non-PIC-base-relative reference to a non-hidden dyld lazy pointer stub. 00166 MO_DARWIN_NONLAZY = 14, 00167 00168 /// MO_DARWIN_NONLAZY_PIC_BASE - On a symbol operand "FOO", this indicates 00169 /// that the reference is actually to "FOO$non_lazy_ptr - PICBASE", which is 00170 /// a PIC-base-relative reference to a non-hidden dyld lazy pointer stub. 00171 MO_DARWIN_NONLAZY_PIC_BASE = 15, 00172 00173 /// MO_DARWIN_HIDDEN_NONLAZY - On a symbol operand "FOO", this indicates 00174 /// that the reference is actually to the "FOO$non_lazy_ptr" symbol, which 00175 /// is a non-PIC-base-relative reference to a hidden dyld lazy pointer stub. 00176 MO_DARWIN_HIDDEN_NONLAZY = 16, 00177 00178 /// MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE - On a symbol operand "FOO", this 00179 /// indicates that the reference is actually to "FOO$non_lazy_ptr -PICBASE", 00180 /// which is a PIC-base-relative reference to a hidden dyld lazy pointer 00181 /// stub. 00182 MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE = 17 00183 }; 00184 } 00185 00186 /// isGlobalStubReference - Return true if the specified TargetFlag operand is 00187 /// a reference to a stub for a global, not the global itself. 00188 inline static bool isGlobalStubReference(unsigned char TargetFlag) { 00189 switch (TargetFlag) { 00190 case X86II::MO_DLLIMPORT: // dllimport stub. 00191 case X86II::MO_GOTPCREL: // rip-relative GOT reference. 00192 case X86II::MO_GOT: // normal GOT reference. 00193 case X86II::MO_DARWIN_NONLAZY_PIC_BASE: // Normal $non_lazy_ptr ref. 00194 case X86II::MO_DARWIN_NONLAZY: // Normal $non_lazy_ptr ref. 00195 case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE: // Hidden $non_lazy_ptr ref. 00196 case X86II::MO_DARWIN_HIDDEN_NONLAZY: // Hidden $non_lazy_ptr ref. 00197 return true; 00198 default: 00199 return false; 00200 } 00201 } 00202 00203 /// isGlobalRelativeToPICBase - Return true if the specified global value 00204 /// reference is relative to a 32-bit PIC base (X86ISD::GlobalBaseReg). If this 00205 /// is true, the addressing mode has the PIC base register added in (e.g. EBX). 00206 inline static bool isGlobalRelativeToPICBase(unsigned char TargetFlag) { 00207 switch (TargetFlag) { 00208 case X86II::MO_GOTOFF: // isPICStyleGOT: local global. 00209 case X86II::MO_GOT: // isPICStyleGOT: other global. 00210 case X86II::MO_PIC_BASE_OFFSET: // Darwin local global. 00211 case X86II::MO_DARWIN_NONLAZY_PIC_BASE: // Darwin/32 external global. 00212 case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE: // Darwin/32 hidden global. 00213 return true; 00214 default: 00215 return false; 00216 } 00217 } 00218 00219 /// X86II - This namespace holds all of the target specific flags that 00220 /// instruction info tracks. 00221 /// 00222 namespace X86II { 00223 enum { 00224 //===------------------------------------------------------------------===// 00225 // Instruction encodings. These are the standard/most common forms for X86 00226 // instructions. 00227 // 00228 00229 // PseudoFrm - This represents an instruction that is a pseudo instruction 00230 // or one that has not been implemented yet. It is illegal to code generate 00231 // it, but tolerated for intermediate implementation stages. 00232 Pseudo = 0, 00233 00234 /// Raw - This form is for instructions that don't have any operands, so 00235 /// they are just a fixed opcode value, like 'leave'. 00236 RawFrm = 1, 00237 00238 /// AddRegFrm - This form is used for instructions like 'push r32' that have 00239 /// their one register operand added to their opcode. 00240 AddRegFrm = 2, 00241 00242 /// MRMDestReg - This form is used for instructions that use the Mod/RM byte 00243 /// to specify a destination, which in this case is a register. 00244 /// 00245 MRMDestReg = 3, 00246 00247 /// MRMDestMem - This form is used for instructions that use the Mod/RM byte 00248 /// to specify a destination, which in this case is memory. 00249 /// 00250 MRMDestMem = 4, 00251 00252 /// MRMSrcReg - This form is used for instructions that use the Mod/RM byte 00253 /// to specify a source, which in this case is a register. 00254 /// 00255 MRMSrcReg = 5, 00256 00257 /// MRMSrcMem - This form is used for instructions that use the Mod/RM byte 00258 /// to specify a source, which in this case is memory. 00259 /// 00260 MRMSrcMem = 6, 00261 00262 /// MRM[0-7][rm] - These forms are used to represent instructions that use 00263 /// a Mod/RM byte, and use the middle field to hold extended opcode 00264 /// information. In the intel manual these are represented as /0, /1, ... 00265 /// 00266 00267 // First, instructions that operate on a register r/m operand... 00268 MRM0r = 16, MRM1r = 17, MRM2r = 18, MRM3r = 19, // Format /0 /1 /2 /3 00269 MRM4r = 20, MRM5r = 21, MRM6r = 22, MRM7r = 23, // Format /4 /5 /6 /7 00270 00271 // Next, instructions that operate on a memory r/m operand... 00272 MRM0m = 24, MRM1m = 25, MRM2m = 26, MRM3m = 27, // Format /0 /1 /2 /3 00273 MRM4m = 28, MRM5m = 29, MRM6m = 30, MRM7m = 31, // Format /4 /5 /6 /7 00274 00275 // MRMInitReg - This form is used for instructions whose source and 00276 // destinations are the same register. 00277 MRMInitReg = 32, 00278 00279 FormMask = 63, 00280 00281 //===------------------------------------------------------------------===// 00282 // Actual flags... 00283 00284 // OpSize - Set if this instruction requires an operand size prefix (0x66), 00285 // which most often indicates that the instruction operates on 16 bit data 00286 // instead of 32 bit data. 00287 OpSize = 1 << 6, 00288 00289 // AsSize - Set if this instruction requires an operand size prefix (0x67), 00290 // which most often indicates that the instruction address 16 bit address 00291 // instead of 32 bit address (or 32 bit address in 64 bit mode). 00292 AdSize = 1 << 7, 00293 00294 //===------------------------------------------------------------------===// 00295 // Op0Mask - There are several prefix bytes that are used to form two byte 00296 // opcodes. These are currently 0x0F, 0xF3, and 0xD8-0xDF. This mask is 00297 // used to obtain the setting of this field. If no bits in this field is 00298 // set, there is no prefix byte for obtaining a multibyte opcode. 00299 // 00300 Op0Shift = 8, 00301 Op0Mask = 0xF << Op0Shift, 00302 00303 // TB - TwoByte - Set if this instruction has a two byte opcode, which 00304 // starts with a 0x0F byte before the real opcode. 00305 TB = 1 << Op0Shift, 00306 00307 // REP - The 0xF3 prefix byte indicating repetition of the following 00308 // instruction. 00309 REP = 2 << Op0Shift, 00310 00311 // D8-DF - These escape opcodes are used by the floating point unit. These 00312 // values must remain sequential. 00313 D8 = 3 << Op0Shift, D9 = 4 << Op0Shift, 00314 DA = 5 << Op0Shift, DB = 6 << Op0Shift, 00315 DC = 7 << Op0Shift, DD = 8 << Op0Shift, 00316 DE = 9 << Op0Shift, DF = 10 << Op0Shift, 00317 00318 // XS, XD - These prefix codes are for single and double precision scalar 00319 // floating point operations performed in the SSE registers. 00320 XD = 11 << Op0Shift, XS = 12 << Op0Shift, 00321 00322 // T8, TA - Prefix after the 0x0F prefix. 00323 T8 = 13 << Op0Shift, TA = 14 << Op0Shift, 00324 00325 // TF - Prefix before and after 0x0F 00326 TF = 15 << Op0Shift, 00327 00328 //===------------------------------------------------------------------===// 00329 // REX_W - REX prefixes are instruction prefixes used in 64-bit mode. 00330 // They are used to specify GPRs and SSE registers, 64-bit operand size, 00331 // etc. We only cares about REX.W and REX.R bits and only the former is 00332 // statically determined. 00333 // 00334 REXShift = 12, 00335 REX_W = 1 << REXShift, 00336 00337 //===------------------------------------------------------------------===// 00338 // This three-bit field describes the size of an immediate operand. Zero is 00339 // unused so that we can tell if we forgot to set a value. 00340 ImmShift = 13, 00341 ImmMask = 7 << ImmShift, 00342 Imm8 = 1 << ImmShift, 00343 Imm16 = 2 << ImmShift, 00344 Imm32 = 3 << ImmShift, 00345 Imm64 = 4 << ImmShift, 00346 00347 //===------------------------------------------------------------------===// 00348 // FP Instruction Classification... Zero is non-fp instruction. 00349 00350 // FPTypeMask - Mask for all of the FP types... 00351 FPTypeShift = 16, 00352 FPTypeMask = 7 << FPTypeShift, 00353 00354 // NotFP - The default, set for instructions that do not use FP registers. 00355 NotFP = 0 << FPTypeShift, 00356 00357 // ZeroArgFP - 0 arg FP instruction which implicitly pushes ST(0), f.e. fld0 00358 ZeroArgFP = 1 << FPTypeShift, 00359 00360 // OneArgFP - 1 arg FP instructions which implicitly read ST(0), such as fst 00361 OneArgFP = 2 << FPTypeShift, 00362 00363 // OneArgFPRW - 1 arg FP instruction which implicitly read ST(0) and write a 00364 // result back to ST(0). For example, fcos, fsqrt, etc. 00365 // 00366 OneArgFPRW = 3 << FPTypeShift, 00367 00368 // TwoArgFP - 2 arg FP instructions which implicitly read ST(0), and an 00369 // explicit argument, storing the result to either ST(0) or the implicit 00370 // argument. For example: fadd, fsub, fmul, etc... 00371 TwoArgFP = 4 << FPTypeShift, 00372 00373 // CompareFP - 2 arg FP instructions which implicitly read ST(0) and an 00374 // explicit argument, but have no destination. Example: fucom, fucomi, ... 00375 CompareFP = 5 << FPTypeShift, 00376 00377 // CondMovFP - "2 operand" floating point conditional move instructions. 00378 CondMovFP = 6 << FPTypeShift, 00379 00380 // SpecialFP - Special instruction forms. Dispatch by opcode explicitly. 00381 SpecialFP = 7 << FPTypeShift, 00382 00383 // Lock prefix 00384 LOCKShift = 19, 00385 LOCK = 1 << LOCKShift, 00386 00387 // Segment override prefixes. Currently we just need ability to address 00388 // stuff in gs and fs segments. 00389 SegOvrShift = 20, 00390 SegOvrMask = 3 << SegOvrShift, 00391 FS = 1 << SegOvrShift, 00392 GS = 2 << SegOvrShift, 00393 00394 // Bits 22 -> 23 are unused 00395 OpcodeShift = 24, 00396 OpcodeMask = 0xFF << OpcodeShift 00397 }; 00398 } 00399 00400 const int X86AddrNumOperands = 5; 00401 00402 inline static bool isScale(const MachineOperand &MO) { 00403 return MO.isImm() && 00404 (MO.getImm() == 1 || MO.getImm() == 2 || 00405 MO.getImm() == 4 || MO.getImm() == 8); 00406 } 00407 00408 inline static bool isLeaMem(const MachineInstr *MI, unsigned Op) { 00409 if (MI->getOperand(Op).isFI()) return true; 00410 return Op+4 <= MI->getNumOperands() && 00411 MI->getOperand(Op ).isReg() && isScale(MI->getOperand(Op+1)) && 00412 MI->getOperand(Op+2).isReg() && 00413 (MI->getOperand(Op+3).isImm() || 00414 MI->getOperand(Op+3).isGlobal() || 00415 MI->getOperand(Op+3).isCPI() || 00416 MI->getOperand(Op+3).isJTI()); 00417 } 00418 00419 inline static bool isMem(const MachineInstr *MI, unsigned Op) { 00420 if (MI->getOperand(Op).isFI()) return true; 00421 return Op+5 <= MI->getNumOperands() && 00422 MI->getOperand(Op+4).isReg() && 00423 isLeaMem(MI, Op); 00424 } 00425 00426 class X86InstrInfo : public TargetInstrInfoImpl { 00427 X86TargetMachine &TM; 00428 const X86RegisterInfo RI; 00429 00430 /// RegOp2MemOpTable2Addr, RegOp2MemOpTable0, RegOp2MemOpTable1, 00431 /// RegOp2MemOpTable2 - Load / store folding opcode maps. 00432 /// 00433 DenseMap<unsigned*, std::pair<unsigned,unsigned> > RegOp2MemOpTable2Addr; 00434 DenseMap<unsigned*, std::pair<unsigned,unsigned> > RegOp2MemOpTable0; 00435 DenseMap<unsigned*, std::pair<unsigned,unsigned> > RegOp2MemOpTable1; 00436 DenseMap<unsigned*, std::pair<unsigned,unsigned> > RegOp2MemOpTable2; 00437 00438 /// MemOp2RegOpTable - Load / store unfolding opcode map. 00439 /// 00440 DenseMap<unsigned*, std::pair<unsigned, unsigned> > MemOp2RegOpTable; 00441 00442 public: 00443 explicit X86InstrInfo(X86TargetMachine &tm); 00444 00445 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As 00446 /// such, whenever a client has an instance of instruction info, it should 00447 /// always be able to get register info as well (through this method). 00448 /// 00449 virtual const X86RegisterInfo &getRegisterInfo() const { return RI; } 00450 00451 /// Return true if the instruction is a register to register move and return 00452 /// the source and dest operands and their sub-register indices by reference. 00453 virtual bool isMoveInstr(const MachineInstr &MI, 00454 unsigned &SrcReg, unsigned &DstReg, 00455 unsigned &SrcSubIdx, unsigned &DstSubIdx) const; 00456 00457 unsigned isLoadFromStackSlot(const MachineInstr *MI, int &FrameIndex) const; 00458 unsigned isStoreToStackSlot(const MachineInstr *MI, int &FrameIndex) const; 00459 00460 bool isReallyTriviallyReMaterializable(const MachineInstr *MI) const; 00461 void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, 00462 unsigned DestReg, unsigned SubIdx, 00463 const MachineInstr *Orig) const; 00464 00465 bool isInvariantLoad(const MachineInstr *MI) const; 00466 00467 /// convertToThreeAddress - This method must be implemented by targets that 00468 /// set the M_CONVERTIBLE_TO_3_ADDR flag. When this flag is set, the target 00469 /// may be able to convert a two-address instruction into a true 00470 /// three-address instruction on demand. This allows the X86 target (for 00471 /// example) to convert ADD and SHL instructions into LEA instructions if they 00472 /// would require register copies due to two-addressness. 00473 /// 00474 /// This method returns a null pointer if the transformation cannot be 00475 /// performed, otherwise it returns the new instruction. 00476 /// 00477 virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI, 00478 MachineBasicBlock::iterator &MBBI, 00479 LiveVariables *LV) const; 00480 00481 /// commuteInstruction - We have a few instructions that must be hacked on to 00482 /// commute them. 00483 /// 00484 virtual MachineInstr *commuteInstruction(MachineInstr *MI, bool NewMI) const; 00485 00486 // Branch analysis. 00487 virtual bool isUnpredicatedTerminator(const MachineInstr* MI) const; 00488 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, 00489 MachineBasicBlock *&FBB, 00490 SmallVectorImpl<MachineOperand> &Cond, 00491 bool AllowModify) const; 00492 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const; 00493 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, 00494 MachineBasicBlock *FBB, 00495 const SmallVectorImpl<MachineOperand> &Cond) const; 00496 virtual bool copyRegToReg(MachineBasicBlock &MBB, 00497 MachineBasicBlock::iterator MI, 00498 unsigned DestReg, unsigned SrcReg, 00499 const TargetRegisterClass *DestRC, 00500 const TargetRegisterClass *SrcRC) const; 00501 virtual void storeRegToStackSlot(MachineBasicBlock &MBB, 00502 MachineBasicBlock::iterator MI, 00503 unsigned SrcReg, bool isKill, int FrameIndex, 00504 const TargetRegisterClass *RC) const; 00505 00506 virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill, 00507 SmallVectorImpl<MachineOperand> &Addr, 00508 const TargetRegisterClass *RC, 00509 SmallVectorImpl<MachineInstr*> &NewMIs) const; 00510 00511 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB, 00512 MachineBasicBlock::iterator MI, 00513 unsigned DestReg, int FrameIndex, 00514 const TargetRegisterClass *RC) const; 00515 00516 virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg, 00517 SmallVectorImpl<MachineOperand> &Addr, 00518 const TargetRegisterClass *RC, 00519 SmallVectorImpl<MachineInstr*> &NewMIs) const; 00520 00521 virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, 00522 MachineBasicBlock::iterator MI, 00523 const std::vector<CalleeSavedInfo> &CSI) const; 00524 00525 virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, 00526 MachineBasicBlock::iterator MI, 00527 const std::vector<CalleeSavedInfo> &CSI) const; 00528 00529 /// foldMemoryOperand - If this target supports it, fold a load or store of 00530 /// the specified stack slot into the specified machine instruction for the 00531 /// specified operand(s). If this is possible, the target should perform the 00532 /// folding and return true, otherwise it should return false. If it folds 00533 /// the instruction, it is likely that the MachineInstruction the iterator 00534 /// references has been changed. 00535 virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF, 00536 MachineInstr* MI, 00537 const SmallVectorImpl<unsigned> &Ops, 00538 int FrameIndex) const; 00539 00540 /// foldMemoryOperand - Same as the previous version except it allows folding 00541 /// of any load and store from / to any address, not just from a specific 00542 /// stack slot. 00543 virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF, 00544 MachineInstr* MI, 00545 const SmallVectorImpl<unsigned> &Ops, 00546 MachineInstr* LoadMI) const; 00547 00548 /// canFoldMemoryOperand - Returns true if the specified load / store is 00549 /// folding is possible. 00550 virtual bool canFoldMemoryOperand(const MachineInstr*, 00551 const SmallVectorImpl<unsigned> &) const; 00552 00553 /// unfoldMemoryOperand - Separate a single instruction which folded a load or 00554 /// a store or a load and a store into two or more instruction. If this is 00555 /// possible, returns true as well as the new instructions by reference. 00556 virtual bool unfoldMemoryOperand(MachineFunction &MF, MachineInstr *MI, 00557 unsigned Reg, bool UnfoldLoad, bool UnfoldStore, 00558 SmallVectorImpl<MachineInstr*> &NewMIs) const; 00559 00560 virtual bool unfoldMemoryOperand(SelectionDAG &DAG, SDNode *N, 00561 SmallVectorImpl<SDNode*> &NewNodes) const; 00562 00563 /// getOpcodeAfterMemoryUnfold - Returns the opcode of the would be new 00564 /// instruction after load / store are unfolded from an instruction of the 00565 /// specified opcode. It returns zero if the specified unfolding is not 00566 /// possible. 00567 virtual unsigned getOpcodeAfterMemoryUnfold(unsigned Opc, 00568 bool UnfoldLoad, bool UnfoldStore) const; 00569 00570 virtual bool BlockHasNoFallThrough(const MachineBasicBlock &MBB) const; 00571 virtual 00572 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const; 00573 00574 /// isSafeToMoveRegClassDefs - Return true if it's safe to move a machine 00575 /// instruction that defines the specified register class. 00576 bool isSafeToMoveRegClassDefs(const TargetRegisterClass *RC) const; 00577 00578 // getBaseOpcodeFor - This function returns the "base" X86 opcode for the 00579 // specified machine instruction. 00580 // 00581 unsigned char getBaseOpcodeFor(const TargetInstrDesc *TID) const { 00582 return TID->TSFlags >> X86II::OpcodeShift; 00583 } 00584 unsigned char getBaseOpcodeFor(unsigned Opcode) const { 00585 return getBaseOpcodeFor(&get(Opcode)); 00586 } 00587 00588 static bool isX86_64NonExtLowByteReg(unsigned reg) { 00589 return (reg == X86::SPL || reg == X86::BPL || 00590 reg == X86::SIL || reg == X86::DIL); 00591 } 00592 00593 static unsigned sizeOfImm(const TargetInstrDesc *Desc); 00594 static bool isX86_64ExtendedReg(const MachineOperand &MO); 00595 static unsigned determineREX(const MachineInstr &MI); 00596 00597 /// GetInstSize - Returns the size of the specified MachineInstr. 00598 /// 00599 virtual unsigned GetInstSizeInBytes(const MachineInstr *MI) const; 00600 00601 /// getGlobalBaseReg - Return a virtual register initialized with the 00602 /// the global base register value. Output instructions required to 00603 /// initialize the register in the function entry block, if necessary. 00604 /// 00605 unsigned getGlobalBaseReg(MachineFunction *MF) const; 00606 00607 private: 00608 MachineInstr* foldMemoryOperandImpl(MachineFunction &MF, 00609 MachineInstr* MI, 00610 unsigned OpNum, 00611 const SmallVectorImpl<MachineOperand> &MOs, 00612 unsigned Alignment) const; 00613 }; 00614 00615 } // End llvm namespace 00616 00617 #endif