LLVM API Documentation
00001 //===-- PPCRegisterInfo.cpp - PowerPC Register Information ----------------===// 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 PowerPC implementation of the TargetRegisterInfo 00011 // class. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #include "PPCRegisterInfo.h" 00016 #include "PPC.h" 00017 #include "PPCFrameLowering.h" 00018 #include "PPCInstrBuilder.h" 00019 #include "PPCMachineFunctionInfo.h" 00020 #include "PPCSubtarget.h" 00021 #include "llvm/ADT/BitVector.h" 00022 #include "llvm/ADT/STLExtras.h" 00023 #include "llvm/CodeGen/MachineFrameInfo.h" 00024 #include "llvm/CodeGen/MachineFunction.h" 00025 #include "llvm/CodeGen/MachineInstrBuilder.h" 00026 #include "llvm/CodeGen/MachineModuleInfo.h" 00027 #include "llvm/CodeGen/MachineRegisterInfo.h" 00028 #include "llvm/CodeGen/RegisterScavenging.h" 00029 #include "llvm/IR/CallingConv.h" 00030 #include "llvm/IR/Constants.h" 00031 #include "llvm/IR/Function.h" 00032 #include "llvm/IR/Type.h" 00033 #include "llvm/Support/CommandLine.h" 00034 #include "llvm/Support/Debug.h" 00035 #include "llvm/Support/ErrorHandling.h" 00036 #include "llvm/Support/MathExtras.h" 00037 #include "llvm/Support/raw_ostream.h" 00038 #include "llvm/Target/TargetFrameLowering.h" 00039 #include "llvm/Target/TargetInstrInfo.h" 00040 #include "llvm/Target/TargetMachine.h" 00041 #include "llvm/Target/TargetOptions.h" 00042 #include <cstdlib> 00043 00044 using namespace llvm; 00045 00046 #define DEBUG_TYPE "reginfo" 00047 00048 #define GET_REGINFO_TARGET_DESC 00049 #include "PPCGenRegisterInfo.inc" 00050 00051 static cl::opt<bool> 00052 EnableBasePointer("ppc-use-base-pointer", cl::Hidden, cl::init(true), 00053 cl::desc("Enable use of a base pointer for complex stack frames")); 00054 00055 static cl::opt<bool> 00056 AlwaysBasePointer("ppc-always-use-base-pointer", cl::Hidden, cl::init(false), 00057 cl::desc("Force the use of a base pointer in every function")); 00058 00059 PPCRegisterInfo::PPCRegisterInfo(const PPCSubtarget &ST) 00060 : PPCGenRegisterInfo(ST.isPPC64() ? PPC::LR8 : PPC::LR, 00061 ST.isPPC64() ? 0 : 1, 00062 ST.isPPC64() ? 0 : 1), 00063 Subtarget(ST) { 00064 ImmToIdxMap[PPC::LD] = PPC::LDX; ImmToIdxMap[PPC::STD] = PPC::STDX; 00065 ImmToIdxMap[PPC::LBZ] = PPC::LBZX; ImmToIdxMap[PPC::STB] = PPC::STBX; 00066 ImmToIdxMap[PPC::LHZ] = PPC::LHZX; ImmToIdxMap[PPC::LHA] = PPC::LHAX; 00067 ImmToIdxMap[PPC::LWZ] = PPC::LWZX; ImmToIdxMap[PPC::LWA] = PPC::LWAX; 00068 ImmToIdxMap[PPC::LFS] = PPC::LFSX; ImmToIdxMap[PPC::LFD] = PPC::LFDX; 00069 ImmToIdxMap[PPC::STH] = PPC::STHX; ImmToIdxMap[PPC::STW] = PPC::STWX; 00070 ImmToIdxMap[PPC::STFS] = PPC::STFSX; ImmToIdxMap[PPC::STFD] = PPC::STFDX; 00071 ImmToIdxMap[PPC::ADDI] = PPC::ADD4; 00072 ImmToIdxMap[PPC::LWA_32] = PPC::LWAX_32; 00073 00074 // 64-bit 00075 ImmToIdxMap[PPC::LHA8] = PPC::LHAX8; ImmToIdxMap[PPC::LBZ8] = PPC::LBZX8; 00076 ImmToIdxMap[PPC::LHZ8] = PPC::LHZX8; ImmToIdxMap[PPC::LWZ8] = PPC::LWZX8; 00077 ImmToIdxMap[PPC::STB8] = PPC::STBX8; ImmToIdxMap[PPC::STH8] = PPC::STHX8; 00078 ImmToIdxMap[PPC::STW8] = PPC::STWX8; ImmToIdxMap[PPC::STDU] = PPC::STDUX; 00079 ImmToIdxMap[PPC::ADDI8] = PPC::ADD8; 00080 } 00081 00082 /// getPointerRegClass - Return the register class to use to hold pointers. 00083 /// This is used for addressing modes. 00084 const TargetRegisterClass * 00085 PPCRegisterInfo::getPointerRegClass(const MachineFunction &MF, unsigned Kind) 00086 const { 00087 // Note that PPCInstrInfo::FoldImmediate also directly uses this Kind value 00088 // when it checks for ZERO folding. 00089 if (Kind == 1) { 00090 if (Subtarget.isPPC64()) 00091 return &PPC::G8RC_NOX0RegClass; 00092 return &PPC::GPRC_NOR0RegClass; 00093 } 00094 00095 if (Subtarget.isPPC64()) 00096 return &PPC::G8RCRegClass; 00097 return &PPC::GPRCRegClass; 00098 } 00099 00100 const MCPhysReg* 00101 PPCRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const { 00102 if (Subtarget.isDarwinABI()) 00103 return Subtarget.isPPC64() ? (Subtarget.hasAltivec() ? 00104 CSR_Darwin64_Altivec_SaveList : 00105 CSR_Darwin64_SaveList) : 00106 (Subtarget.hasAltivec() ? 00107 CSR_Darwin32_Altivec_SaveList : 00108 CSR_Darwin32_SaveList); 00109 00110 return Subtarget.isPPC64() ? (Subtarget.hasAltivec() ? 00111 CSR_SVR464_Altivec_SaveList : 00112 CSR_SVR464_SaveList) : 00113 (Subtarget.hasAltivec() ? 00114 CSR_SVR432_Altivec_SaveList : 00115 CSR_SVR432_SaveList); 00116 } 00117 00118 const uint32_t* 00119 PPCRegisterInfo::getCallPreservedMask(CallingConv::ID CC) const { 00120 if (Subtarget.isDarwinABI()) 00121 return Subtarget.isPPC64() ? (Subtarget.hasAltivec() ? 00122 CSR_Darwin64_Altivec_RegMask : 00123 CSR_Darwin64_RegMask) : 00124 (Subtarget.hasAltivec() ? 00125 CSR_Darwin32_Altivec_RegMask : 00126 CSR_Darwin32_RegMask); 00127 00128 return Subtarget.isPPC64() ? (Subtarget.hasAltivec() ? 00129 CSR_SVR464_Altivec_RegMask : 00130 CSR_SVR464_RegMask) : 00131 (Subtarget.hasAltivec() ? 00132 CSR_SVR432_Altivec_RegMask : 00133 CSR_SVR432_RegMask); 00134 } 00135 00136 const uint32_t* 00137 PPCRegisterInfo::getNoPreservedMask() const { 00138 return CSR_NoRegs_RegMask; 00139 } 00140 00141 BitVector PPCRegisterInfo::getReservedRegs(const MachineFunction &MF) const { 00142 BitVector Reserved(getNumRegs()); 00143 const PPCFrameLowering *PPCFI = static_cast<const PPCFrameLowering *>( 00144 MF.getSubtarget().getFrameLowering()); 00145 00146 // The ZERO register is not really a register, but the representation of r0 00147 // when used in instructions that treat r0 as the constant 0. 00148 Reserved.set(PPC::ZERO); 00149 Reserved.set(PPC::ZERO8); 00150 00151 // The FP register is also not really a register, but is the representation 00152 // of the frame pointer register used by ISD::FRAMEADDR. 00153 Reserved.set(PPC::FP); 00154 Reserved.set(PPC::FP8); 00155 00156 // The BP register is also not really a register, but is the representation 00157 // of the base pointer register used by setjmp. 00158 Reserved.set(PPC::BP); 00159 Reserved.set(PPC::BP8); 00160 00161 // The counter registers must be reserved so that counter-based loops can 00162 // be correctly formed (and the mtctr instructions are not DCE'd). 00163 Reserved.set(PPC::CTR); 00164 Reserved.set(PPC::CTR8); 00165 00166 Reserved.set(PPC::R1); 00167 Reserved.set(PPC::LR); 00168 Reserved.set(PPC::LR8); 00169 Reserved.set(PPC::RM); 00170 00171 if (!Subtarget.isDarwinABI() || !Subtarget.hasAltivec()) 00172 Reserved.set(PPC::VRSAVE); 00173 00174 // The SVR4 ABI reserves r2 and r13 00175 if (Subtarget.isSVR4ABI()) { 00176 Reserved.set(PPC::R2); // System-reserved register 00177 Reserved.set(PPC::R13); // Small Data Area pointer register 00178 } 00179 00180 // On PPC64, r13 is the thread pointer. Never allocate this register. 00181 if (Subtarget.isPPC64()) { 00182 Reserved.set(PPC::R13); 00183 00184 Reserved.set(PPC::X1); 00185 Reserved.set(PPC::X13); 00186 00187 if (PPCFI->needsFP(MF)) 00188 Reserved.set(PPC::X31); 00189 00190 if (hasBasePointer(MF)) 00191 Reserved.set(PPC::X30); 00192 00193 // The 64-bit SVR4 ABI reserves r2 for the TOC pointer. 00194 if (Subtarget.isSVR4ABI()) { 00195 Reserved.set(PPC::X2); 00196 } 00197 } 00198 00199 if (PPCFI->needsFP(MF)) 00200 Reserved.set(PPC::R31); 00201 00202 if (hasBasePointer(MF)) { 00203 if (Subtarget.isSVR4ABI() && !Subtarget.isPPC64() && 00204 MF.getTarget().getRelocationModel() == Reloc::PIC_) 00205 Reserved.set(PPC::R29); 00206 else 00207 Reserved.set(PPC::R30); 00208 } 00209 00210 if (Subtarget.isSVR4ABI() && !Subtarget.isPPC64() && 00211 MF.getTarget().getRelocationModel() == Reloc::PIC_) 00212 Reserved.set(PPC::R30); 00213 00214 // Reserve Altivec registers when Altivec is unavailable. 00215 if (!Subtarget.hasAltivec()) 00216 for (TargetRegisterClass::iterator I = PPC::VRRCRegClass.begin(), 00217 IE = PPC::VRRCRegClass.end(); I != IE; ++I) 00218 Reserved.set(*I); 00219 00220 return Reserved; 00221 } 00222 00223 unsigned 00224 PPCRegisterInfo::getRegPressureLimit(const TargetRegisterClass *RC, 00225 MachineFunction &MF) const { 00226 const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering(); 00227 const unsigned DefaultSafety = 1; 00228 00229 switch (RC->getID()) { 00230 default: 00231 return 0; 00232 case PPC::G8RC_NOX0RegClassID: 00233 case PPC::GPRC_NOR0RegClassID: 00234 case PPC::G8RCRegClassID: 00235 case PPC::GPRCRegClassID: { 00236 unsigned FP = TFI->hasFP(MF) ? 1 : 0; 00237 return 32 - FP - DefaultSafety; 00238 } 00239 case PPC::F8RCRegClassID: 00240 case PPC::F4RCRegClassID: 00241 case PPC::VRRCRegClassID: 00242 case PPC::VFRCRegClassID: 00243 case PPC::VSLRCRegClassID: 00244 case PPC::VSHRCRegClassID: 00245 return 32 - DefaultSafety; 00246 case PPC::VSRCRegClassID: 00247 case PPC::VSFRCRegClassID: 00248 return 64 - DefaultSafety; 00249 case PPC::CRRCRegClassID: 00250 return 8 - DefaultSafety; 00251 } 00252 } 00253 00254 const TargetRegisterClass* 00255 PPCRegisterInfo::getLargestLegalSuperClass(const TargetRegisterClass *RC)const { 00256 if (Subtarget.hasVSX()) { 00257 // With VSX, we can inflate various sub-register classes to the full VSX 00258 // register set. 00259 00260 if (RC == &PPC::F8RCRegClass) 00261 return &PPC::VSFRCRegClass; 00262 else if (RC == &PPC::VRRCRegClass) 00263 return &PPC::VSRCRegClass; 00264 } 00265 00266 return TargetRegisterInfo::getLargestLegalSuperClass(RC); 00267 } 00268 00269 //===----------------------------------------------------------------------===// 00270 // Stack Frame Processing methods 00271 //===----------------------------------------------------------------------===// 00272 00273 /// lowerDynamicAlloc - Generate the code for allocating an object in the 00274 /// current frame. The sequence of code with be in the general form 00275 /// 00276 /// addi R0, SP, \#frameSize ; get the address of the previous frame 00277 /// stwxu R0, SP, Rnegsize ; add and update the SP with the negated size 00278 /// addi Rnew, SP, \#maxCalFrameSize ; get the top of the allocation 00279 /// 00280 void PPCRegisterInfo::lowerDynamicAlloc(MachineBasicBlock::iterator II) const { 00281 // Get the instruction. 00282 MachineInstr &MI = *II; 00283 // Get the instruction's basic block. 00284 MachineBasicBlock &MBB = *MI.getParent(); 00285 // Get the basic block's function. 00286 MachineFunction &MF = *MBB.getParent(); 00287 // Get the frame info. 00288 MachineFrameInfo *MFI = MF.getFrameInfo(); 00289 // Get the instruction info. 00290 const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo(); 00291 // Determine whether 64-bit pointers are used. 00292 bool LP64 = Subtarget.isPPC64(); 00293 DebugLoc dl = MI.getDebugLoc(); 00294 00295 // Get the maximum call stack size. 00296 unsigned maxCallFrameSize = MFI->getMaxCallFrameSize(); 00297 // Get the total frame size. 00298 unsigned FrameSize = MFI->getStackSize(); 00299 00300 // Get stack alignments. 00301 unsigned TargetAlign = MF.getTarget() 00302 .getSubtargetImpl() 00303 ->getFrameLowering() 00304 ->getStackAlignment(); 00305 unsigned MaxAlign = MFI->getMaxAlignment(); 00306 assert((maxCallFrameSize & (MaxAlign-1)) == 0 && 00307 "Maximum call-frame size not sufficiently aligned"); 00308 00309 // Determine the previous frame's address. If FrameSize can't be 00310 // represented as 16 bits or we need special alignment, then we load the 00311 // previous frame's address from 0(SP). Why not do an addis of the hi? 00312 // Because R0 is our only safe tmp register and addi/addis treat R0 as zero. 00313 // Constructing the constant and adding would take 3 instructions. 00314 // Fortunately, a frame greater than 32K is rare. 00315 const TargetRegisterClass *G8RC = &PPC::G8RCRegClass; 00316 const TargetRegisterClass *GPRC = &PPC::GPRCRegClass; 00317 unsigned Reg = MF.getRegInfo().createVirtualRegister(LP64 ? G8RC : GPRC); 00318 00319 if (MaxAlign < TargetAlign && isInt<16>(FrameSize)) { 00320 BuildMI(MBB, II, dl, TII.get(PPC::ADDI), Reg) 00321 .addReg(PPC::R31) 00322 .addImm(FrameSize); 00323 } else if (LP64) { 00324 BuildMI(MBB, II, dl, TII.get(PPC::LD), Reg) 00325 .addImm(0) 00326 .addReg(PPC::X1); 00327 } else { 00328 BuildMI(MBB, II, dl, TII.get(PPC::LWZ), Reg) 00329 .addImm(0) 00330 .addReg(PPC::R1); 00331 } 00332 00333 bool KillNegSizeReg = MI.getOperand(1).isKill(); 00334 unsigned NegSizeReg = MI.getOperand(1).getReg(); 00335 00336 // Grow the stack and update the stack pointer link, then determine the 00337 // address of new allocated space. 00338 if (LP64) { 00339 if (MaxAlign > TargetAlign) { 00340 unsigned UnalNegSizeReg = NegSizeReg; 00341 NegSizeReg = MF.getRegInfo().createVirtualRegister(G8RC); 00342 00343 // Unfortunately, there is no andi, only andi., and we can't insert that 00344 // here because we might clobber cr0 while it is live. 00345 BuildMI(MBB, II, dl, TII.get(PPC::LI8), NegSizeReg) 00346 .addImm(~(MaxAlign-1)); 00347 00348 unsigned NegSizeReg1 = NegSizeReg; 00349 NegSizeReg = MF.getRegInfo().createVirtualRegister(G8RC); 00350 BuildMI(MBB, II, dl, TII.get(PPC::AND8), NegSizeReg) 00351 .addReg(UnalNegSizeReg, getKillRegState(KillNegSizeReg)) 00352 .addReg(NegSizeReg1, RegState::Kill); 00353 KillNegSizeReg = true; 00354 } 00355 00356 BuildMI(MBB, II, dl, TII.get(PPC::STDUX), PPC::X1) 00357 .addReg(Reg, RegState::Kill) 00358 .addReg(PPC::X1) 00359 .addReg(NegSizeReg, getKillRegState(KillNegSizeReg)); 00360 BuildMI(MBB, II, dl, TII.get(PPC::ADDI8), MI.getOperand(0).getReg()) 00361 .addReg(PPC::X1) 00362 .addImm(maxCallFrameSize); 00363 } else { 00364 if (MaxAlign > TargetAlign) { 00365 unsigned UnalNegSizeReg = NegSizeReg; 00366 NegSizeReg = MF.getRegInfo().createVirtualRegister(GPRC); 00367 00368 // Unfortunately, there is no andi, only andi., and we can't insert that 00369 // here because we might clobber cr0 while it is live. 00370 BuildMI(MBB, II, dl, TII.get(PPC::LI), NegSizeReg) 00371 .addImm(~(MaxAlign-1)); 00372 00373 unsigned NegSizeReg1 = NegSizeReg; 00374 NegSizeReg = MF.getRegInfo().createVirtualRegister(GPRC); 00375 BuildMI(MBB, II, dl, TII.get(PPC::AND), NegSizeReg) 00376 .addReg(UnalNegSizeReg, getKillRegState(KillNegSizeReg)) 00377 .addReg(NegSizeReg1, RegState::Kill); 00378 KillNegSizeReg = true; 00379 } 00380 00381 BuildMI(MBB, II, dl, TII.get(PPC::STWUX), PPC::R1) 00382 .addReg(Reg, RegState::Kill) 00383 .addReg(PPC::R1) 00384 .addReg(NegSizeReg, getKillRegState(KillNegSizeReg)); 00385 BuildMI(MBB, II, dl, TII.get(PPC::ADDI), MI.getOperand(0).getReg()) 00386 .addReg(PPC::R1) 00387 .addImm(maxCallFrameSize); 00388 } 00389 00390 // Discard the DYNALLOC instruction. 00391 MBB.erase(II); 00392 } 00393 00394 /// lowerCRSpilling - Generate the code for spilling a CR register. Instead of 00395 /// reserving a whole register (R0), we scrounge for one here. This generates 00396 /// code like this: 00397 /// 00398 /// mfcr rA ; Move the conditional register into GPR rA. 00399 /// rlwinm rA, rA, SB, 0, 31 ; Shift the bits left so they are in CR0's slot. 00400 /// stw rA, FI ; Store rA to the frame. 00401 /// 00402 void PPCRegisterInfo::lowerCRSpilling(MachineBasicBlock::iterator II, 00403 unsigned FrameIndex) const { 00404 // Get the instruction. 00405 MachineInstr &MI = *II; // ; SPILL_CR <SrcReg>, <offset> 00406 // Get the instruction's basic block. 00407 MachineBasicBlock &MBB = *MI.getParent(); 00408 MachineFunction &MF = *MBB.getParent(); 00409 const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo(); 00410 DebugLoc dl = MI.getDebugLoc(); 00411 00412 bool LP64 = Subtarget.isPPC64(); 00413 const TargetRegisterClass *G8RC = &PPC::G8RCRegClass; 00414 const TargetRegisterClass *GPRC = &PPC::GPRCRegClass; 00415 00416 unsigned Reg = MF.getRegInfo().createVirtualRegister(LP64 ? G8RC : GPRC); 00417 unsigned SrcReg = MI.getOperand(0).getReg(); 00418 00419 // We need to store the CR in the low 4-bits of the saved value. First, issue 00420 // an MFOCRF to save all of the CRBits and, if needed, kill the SrcReg. 00421 BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::MFOCRF8 : PPC::MFOCRF), Reg) 00422 .addReg(SrcReg, getKillRegState(MI.getOperand(0).isKill())); 00423 00424 // If the saved register wasn't CR0, shift the bits left so that they are in 00425 // CR0's slot. 00426 if (SrcReg != PPC::CR0) { 00427 unsigned Reg1 = Reg; 00428 Reg = MF.getRegInfo().createVirtualRegister(LP64 ? G8RC : GPRC); 00429 00430 // rlwinm rA, rA, ShiftBits, 0, 31. 00431 BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::RLWINM8 : PPC::RLWINM), Reg) 00432 .addReg(Reg1, RegState::Kill) 00433 .addImm(getEncodingValue(SrcReg) * 4) 00434 .addImm(0) 00435 .addImm(31); 00436 } 00437 00438 addFrameReference(BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::STW8 : PPC::STW)) 00439 .addReg(Reg, RegState::Kill), 00440 FrameIndex); 00441 00442 // Discard the pseudo instruction. 00443 MBB.erase(II); 00444 } 00445 00446 void PPCRegisterInfo::lowerCRRestore(MachineBasicBlock::iterator II, 00447 unsigned FrameIndex) const { 00448 // Get the instruction. 00449 MachineInstr &MI = *II; // ; <DestReg> = RESTORE_CR <offset> 00450 // Get the instruction's basic block. 00451 MachineBasicBlock &MBB = *MI.getParent(); 00452 MachineFunction &MF = *MBB.getParent(); 00453 const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo(); 00454 DebugLoc dl = MI.getDebugLoc(); 00455 00456 bool LP64 = Subtarget.isPPC64(); 00457 const TargetRegisterClass *G8RC = &PPC::G8RCRegClass; 00458 const TargetRegisterClass *GPRC = &PPC::GPRCRegClass; 00459 00460 unsigned Reg = MF.getRegInfo().createVirtualRegister(LP64 ? G8RC : GPRC); 00461 unsigned DestReg = MI.getOperand(0).getReg(); 00462 assert(MI.definesRegister(DestReg) && 00463 "RESTORE_CR does not define its destination"); 00464 00465 addFrameReference(BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::LWZ8 : PPC::LWZ), 00466 Reg), FrameIndex); 00467 00468 // If the reloaded register isn't CR0, shift the bits right so that they are 00469 // in the right CR's slot. 00470 if (DestReg != PPC::CR0) { 00471 unsigned Reg1 = Reg; 00472 Reg = MF.getRegInfo().createVirtualRegister(LP64 ? G8RC : GPRC); 00473 00474 unsigned ShiftBits = getEncodingValue(DestReg)*4; 00475 // rlwinm r11, r11, 32-ShiftBits, 0, 31. 00476 BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::RLWINM8 : PPC::RLWINM), Reg) 00477 .addReg(Reg1, RegState::Kill).addImm(32-ShiftBits).addImm(0) 00478 .addImm(31); 00479 } 00480 00481 BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::MTOCRF8 : PPC::MTOCRF), DestReg) 00482 .addReg(Reg, RegState::Kill); 00483 00484 // Discard the pseudo instruction. 00485 MBB.erase(II); 00486 } 00487 00488 static unsigned getCRFromCRBit(unsigned SrcReg) { 00489 unsigned Reg = 0; 00490 if (SrcReg == PPC::CR0LT || SrcReg == PPC::CR0GT || 00491 SrcReg == PPC::CR0EQ || SrcReg == PPC::CR0UN) 00492 Reg = PPC::CR0; 00493 else if (SrcReg == PPC::CR1LT || SrcReg == PPC::CR1GT || 00494 SrcReg == PPC::CR1EQ || SrcReg == PPC::CR1UN) 00495 Reg = PPC::CR1; 00496 else if (SrcReg == PPC::CR2LT || SrcReg == PPC::CR2GT || 00497 SrcReg == PPC::CR2EQ || SrcReg == PPC::CR2UN) 00498 Reg = PPC::CR2; 00499 else if (SrcReg == PPC::CR3LT || SrcReg == PPC::CR3GT || 00500 SrcReg == PPC::CR3EQ || SrcReg == PPC::CR3UN) 00501 Reg = PPC::CR3; 00502 else if (SrcReg == PPC::CR4LT || SrcReg == PPC::CR4GT || 00503 SrcReg == PPC::CR4EQ || SrcReg == PPC::CR4UN) 00504 Reg = PPC::CR4; 00505 else if (SrcReg == PPC::CR5LT || SrcReg == PPC::CR5GT || 00506 SrcReg == PPC::CR5EQ || SrcReg == PPC::CR5UN) 00507 Reg = PPC::CR5; 00508 else if (SrcReg == PPC::CR6LT || SrcReg == PPC::CR6GT || 00509 SrcReg == PPC::CR6EQ || SrcReg == PPC::CR6UN) 00510 Reg = PPC::CR6; 00511 else if (SrcReg == PPC::CR7LT || SrcReg == PPC::CR7GT || 00512 SrcReg == PPC::CR7EQ || SrcReg == PPC::CR7UN) 00513 Reg = PPC::CR7; 00514 00515 assert(Reg != 0 && "Invalid CR bit register"); 00516 return Reg; 00517 } 00518 00519 void PPCRegisterInfo::lowerCRBitSpilling(MachineBasicBlock::iterator II, 00520 unsigned FrameIndex) const { 00521 // Get the instruction. 00522 MachineInstr &MI = *II; // ; SPILL_CRBIT <SrcReg>, <offset> 00523 // Get the instruction's basic block. 00524 MachineBasicBlock &MBB = *MI.getParent(); 00525 MachineFunction &MF = *MBB.getParent(); 00526 const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo(); 00527 DebugLoc dl = MI.getDebugLoc(); 00528 00529 bool LP64 = Subtarget.isPPC64(); 00530 const TargetRegisterClass *G8RC = &PPC::G8RCRegClass; 00531 const TargetRegisterClass *GPRC = &PPC::GPRCRegClass; 00532 00533 unsigned Reg = MF.getRegInfo().createVirtualRegister(LP64 ? G8RC : GPRC); 00534 unsigned SrcReg = MI.getOperand(0).getReg(); 00535 00536 BuildMI(MBB, II, dl, TII.get(TargetOpcode::KILL), 00537 getCRFromCRBit(SrcReg)) 00538 .addReg(SrcReg, getKillRegState(MI.getOperand(0).isKill())); 00539 00540 BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::MFOCRF8 : PPC::MFOCRF), Reg) 00541 .addReg(getCRFromCRBit(SrcReg)); 00542 00543 // If the saved register wasn't CR0LT, shift the bits left so that the bit to 00544 // store is the first one. Mask all but that bit. 00545 unsigned Reg1 = Reg; 00546 Reg = MF.getRegInfo().createVirtualRegister(LP64 ? G8RC : GPRC); 00547 00548 // rlwinm rA, rA, ShiftBits, 0, 0. 00549 BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::RLWINM8 : PPC::RLWINM), Reg) 00550 .addReg(Reg1, RegState::Kill) 00551 .addImm(getEncodingValue(SrcReg)) 00552 .addImm(0).addImm(0); 00553 00554 addFrameReference(BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::STW8 : PPC::STW)) 00555 .addReg(Reg, RegState::Kill), 00556 FrameIndex); 00557 00558 // Discard the pseudo instruction. 00559 MBB.erase(II); 00560 } 00561 00562 void PPCRegisterInfo::lowerCRBitRestore(MachineBasicBlock::iterator II, 00563 unsigned FrameIndex) const { 00564 // Get the instruction. 00565 MachineInstr &MI = *II; // ; <DestReg> = RESTORE_CRBIT <offset> 00566 // Get the instruction's basic block. 00567 MachineBasicBlock &MBB = *MI.getParent(); 00568 MachineFunction &MF = *MBB.getParent(); 00569 const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo(); 00570 DebugLoc dl = MI.getDebugLoc(); 00571 00572 bool LP64 = Subtarget.isPPC64(); 00573 const TargetRegisterClass *G8RC = &PPC::G8RCRegClass; 00574 const TargetRegisterClass *GPRC = &PPC::GPRCRegClass; 00575 00576 unsigned Reg = MF.getRegInfo().createVirtualRegister(LP64 ? G8RC : GPRC); 00577 unsigned DestReg = MI.getOperand(0).getReg(); 00578 assert(MI.definesRegister(DestReg) && 00579 "RESTORE_CRBIT does not define its destination"); 00580 00581 addFrameReference(BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::LWZ8 : PPC::LWZ), 00582 Reg), FrameIndex); 00583 00584 BuildMI(MBB, II, dl, TII.get(TargetOpcode::IMPLICIT_DEF), DestReg); 00585 00586 unsigned RegO = MF.getRegInfo().createVirtualRegister(LP64 ? G8RC : GPRC); 00587 BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::MFOCRF8 : PPC::MFOCRF), RegO) 00588 .addReg(getCRFromCRBit(DestReg)); 00589 00590 unsigned ShiftBits = getEncodingValue(DestReg); 00591 // rlwimi r11, r10, 32-ShiftBits, ..., ... 00592 BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::RLWIMI8 : PPC::RLWIMI), RegO) 00593 .addReg(RegO, RegState::Kill).addReg(Reg, RegState::Kill) 00594 .addImm(ShiftBits ? 32-ShiftBits : 0) 00595 .addImm(ShiftBits).addImm(ShiftBits); 00596 00597 BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::MTOCRF8 : PPC::MTOCRF), 00598 getCRFromCRBit(DestReg)) 00599 .addReg(RegO, RegState::Kill) 00600 // Make sure we have a use dependency all the way through this 00601 // sequence of instructions. We can't have the other bits in the CR 00602 // modified in between the mfocrf and the mtocrf. 00603 .addReg(getCRFromCRBit(DestReg), RegState::Implicit); 00604 00605 // Discard the pseudo instruction. 00606 MBB.erase(II); 00607 } 00608 00609 void PPCRegisterInfo::lowerVRSAVESpilling(MachineBasicBlock::iterator II, 00610 unsigned FrameIndex) const { 00611 // Get the instruction. 00612 MachineInstr &MI = *II; // ; SPILL_VRSAVE <SrcReg>, <offset> 00613 // Get the instruction's basic block. 00614 MachineBasicBlock &MBB = *MI.getParent(); 00615 MachineFunction &MF = *MBB.getParent(); 00616 const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo(); 00617 DebugLoc dl = MI.getDebugLoc(); 00618 00619 const TargetRegisterClass *GPRC = &PPC::GPRCRegClass; 00620 unsigned Reg = MF.getRegInfo().createVirtualRegister(GPRC); 00621 unsigned SrcReg = MI.getOperand(0).getReg(); 00622 00623 BuildMI(MBB, II, dl, TII.get(PPC::MFVRSAVEv), Reg) 00624 .addReg(SrcReg, getKillRegState(MI.getOperand(0).isKill())); 00625 00626 addFrameReference(BuildMI(MBB, II, dl, TII.get(PPC::STW)) 00627 .addReg(Reg, RegState::Kill), 00628 FrameIndex); 00629 00630 // Discard the pseudo instruction. 00631 MBB.erase(II); 00632 } 00633 00634 void PPCRegisterInfo::lowerVRSAVERestore(MachineBasicBlock::iterator II, 00635 unsigned FrameIndex) const { 00636 // Get the instruction. 00637 MachineInstr &MI = *II; // ; <DestReg> = RESTORE_VRSAVE <offset> 00638 // Get the instruction's basic block. 00639 MachineBasicBlock &MBB = *MI.getParent(); 00640 MachineFunction &MF = *MBB.getParent(); 00641 const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo(); 00642 DebugLoc dl = MI.getDebugLoc(); 00643 00644 const TargetRegisterClass *GPRC = &PPC::GPRCRegClass; 00645 unsigned Reg = MF.getRegInfo().createVirtualRegister(GPRC); 00646 unsigned DestReg = MI.getOperand(0).getReg(); 00647 assert(MI.definesRegister(DestReg) && 00648 "RESTORE_VRSAVE does not define its destination"); 00649 00650 addFrameReference(BuildMI(MBB, II, dl, TII.get(PPC::LWZ), 00651 Reg), FrameIndex); 00652 00653 BuildMI(MBB, II, dl, TII.get(PPC::MTVRSAVEv), DestReg) 00654 .addReg(Reg, RegState::Kill); 00655 00656 // Discard the pseudo instruction. 00657 MBB.erase(II); 00658 } 00659 00660 bool 00661 PPCRegisterInfo::hasReservedSpillSlot(const MachineFunction &MF, 00662 unsigned Reg, int &FrameIdx) const { 00663 00664 // For the nonvolatile condition registers (CR2, CR3, CR4) in an SVR4 00665 // ABI, return true to prevent allocating an additional frame slot. 00666 // For 64-bit, the CR save area is at SP+8; the value of FrameIdx = 0 00667 // is arbitrary and will be subsequently ignored. For 32-bit, we have 00668 // previously created the stack slot if needed, so return its FrameIdx. 00669 if (Subtarget.isSVR4ABI() && PPC::CR2 <= Reg && Reg <= PPC::CR4) { 00670 if (Subtarget.isPPC64()) 00671 FrameIdx = 0; 00672 else { 00673 const PPCFunctionInfo *FI = MF.getInfo<PPCFunctionInfo>(); 00674 FrameIdx = FI->getCRSpillFrameIndex(); 00675 } 00676 return true; 00677 } 00678 return false; 00679 } 00680 00681 // Figure out if the offset in the instruction must be a multiple of 4. 00682 // This is true for instructions like "STD". 00683 static bool usesIXAddr(const MachineInstr &MI) { 00684 unsigned OpC = MI.getOpcode(); 00685 00686 switch (OpC) { 00687 default: 00688 return false; 00689 case PPC::LWA: 00690 case PPC::LWA_32: 00691 case PPC::LD: 00692 case PPC::STD: 00693 return true; 00694 } 00695 } 00696 00697 // Return the OffsetOperandNo given the FIOperandNum (and the instruction). 00698 static unsigned getOffsetONFromFION(const MachineInstr &MI, 00699 unsigned FIOperandNum) { 00700 // Take into account whether it's an add or mem instruction 00701 unsigned OffsetOperandNo = (FIOperandNum == 2) ? 1 : 2; 00702 if (MI.isInlineAsm()) 00703 OffsetOperandNo = FIOperandNum-1; 00704 00705 return OffsetOperandNo; 00706 } 00707 00708 void 00709 PPCRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II, 00710 int SPAdj, unsigned FIOperandNum, 00711 RegScavenger *RS) const { 00712 assert(SPAdj == 0 && "Unexpected"); 00713 00714 // Get the instruction. 00715 MachineInstr &MI = *II; 00716 // Get the instruction's basic block. 00717 MachineBasicBlock &MBB = *MI.getParent(); 00718 // Get the basic block's function. 00719 MachineFunction &MF = *MBB.getParent(); 00720 // Get the instruction info. 00721 const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo(); 00722 // Get the frame info. 00723 MachineFrameInfo *MFI = MF.getFrameInfo(); 00724 DebugLoc dl = MI.getDebugLoc(); 00725 00726 unsigned OffsetOperandNo = getOffsetONFromFION(MI, FIOperandNum); 00727 00728 // Get the frame index. 00729 int FrameIndex = MI.getOperand(FIOperandNum).getIndex(); 00730 00731 // Get the frame pointer save index. Users of this index are primarily 00732 // DYNALLOC instructions. 00733 PPCFunctionInfo *FI = MF.getInfo<PPCFunctionInfo>(); 00734 int FPSI = FI->getFramePointerSaveIndex(); 00735 // Get the instruction opcode. 00736 unsigned OpC = MI.getOpcode(); 00737 00738 // Special case for dynamic alloca. 00739 if (FPSI && FrameIndex == FPSI && 00740 (OpC == PPC::DYNALLOC || OpC == PPC::DYNALLOC8)) { 00741 lowerDynamicAlloc(II); 00742 return; 00743 } 00744 00745 // Special case for pseudo-ops SPILL_CR and RESTORE_CR, etc. 00746 if (OpC == PPC::SPILL_CR) { 00747 lowerCRSpilling(II, FrameIndex); 00748 return; 00749 } else if (OpC == PPC::RESTORE_CR) { 00750 lowerCRRestore(II, FrameIndex); 00751 return; 00752 } else if (OpC == PPC::SPILL_CRBIT) { 00753 lowerCRBitSpilling(II, FrameIndex); 00754 return; 00755 } else if (OpC == PPC::RESTORE_CRBIT) { 00756 lowerCRBitRestore(II, FrameIndex); 00757 return; 00758 } else if (OpC == PPC::SPILL_VRSAVE) { 00759 lowerVRSAVESpilling(II, FrameIndex); 00760 return; 00761 } else if (OpC == PPC::RESTORE_VRSAVE) { 00762 lowerVRSAVERestore(II, FrameIndex); 00763 return; 00764 } 00765 00766 // Replace the FrameIndex with base register with GPR1 (SP) or GPR31 (FP). 00767 MI.getOperand(FIOperandNum).ChangeToRegister( 00768 FrameIndex < 0 ? getBaseRegister(MF) : getFrameRegister(MF), false); 00769 00770 // Figure out if the offset in the instruction is shifted right two bits. 00771 bool isIXAddr = usesIXAddr(MI); 00772 00773 // If the instruction is not present in ImmToIdxMap, then it has no immediate 00774 // form (and must be r+r). 00775 bool noImmForm = !MI.isInlineAsm() && !ImmToIdxMap.count(OpC); 00776 00777 // Now add the frame object offset to the offset from r1. 00778 int Offset = MFI->getObjectOffset(FrameIndex); 00779 Offset += MI.getOperand(OffsetOperandNo).getImm(); 00780 00781 // If we're not using a Frame Pointer that has been set to the value of the 00782 // SP before having the stack size subtracted from it, then add the stack size 00783 // to Offset to get the correct offset. 00784 // Naked functions have stack size 0, although getStackSize may not reflect that 00785 // because we didn't call all the pieces that compute it for naked functions. 00786 if (!MF.getFunction()->getAttributes(). 00787 hasAttribute(AttributeSet::FunctionIndex, Attribute::Naked)) { 00788 if (!(hasBasePointer(MF) && FrameIndex < 0)) 00789 Offset += MFI->getStackSize(); 00790 } 00791 00792 // If we can, encode the offset directly into the instruction. If this is a 00793 // normal PPC "ri" instruction, any 16-bit value can be safely encoded. If 00794 // this is a PPC64 "ix" instruction, only a 16-bit value with the low two bits 00795 // clear can be encoded. This is extremely uncommon, because normally you 00796 // only "std" to a stack slot that is at least 4-byte aligned, but it can 00797 // happen in invalid code. 00798 assert(OpC != PPC::DBG_VALUE && 00799 "This should be handle in a target independent way"); 00800 if (!noImmForm && isInt<16>(Offset) && (!isIXAddr || (Offset & 3) == 0)) { 00801 MI.getOperand(OffsetOperandNo).ChangeToImmediate(Offset); 00802 return; 00803 } 00804 00805 // The offset doesn't fit into a single register, scavenge one to build the 00806 // offset in. 00807 00808 bool is64Bit = Subtarget.isPPC64(); 00809 const TargetRegisterClass *G8RC = &PPC::G8RCRegClass; 00810 const TargetRegisterClass *GPRC = &PPC::GPRCRegClass; 00811 const TargetRegisterClass *RC = is64Bit ? G8RC : GPRC; 00812 unsigned SRegHi = MF.getRegInfo().createVirtualRegister(RC), 00813 SReg = MF.getRegInfo().createVirtualRegister(RC); 00814 00815 // Insert a set of rA with the full offset value before the ld, st, or add 00816 BuildMI(MBB, II, dl, TII.get(is64Bit ? PPC::LIS8 : PPC::LIS), SRegHi) 00817 .addImm(Offset >> 16); 00818 BuildMI(MBB, II, dl, TII.get(is64Bit ? PPC::ORI8 : PPC::ORI), SReg) 00819 .addReg(SRegHi, RegState::Kill) 00820 .addImm(Offset); 00821 00822 // Convert into indexed form of the instruction: 00823 // 00824 // sth 0:rA, 1:imm 2:(rB) ==> sthx 0:rA, 2:rB, 1:r0 00825 // addi 0:rA 1:rB, 2, imm ==> add 0:rA, 1:rB, 2:r0 00826 unsigned OperandBase; 00827 00828 if (noImmForm) 00829 OperandBase = 1; 00830 else if (OpC != TargetOpcode::INLINEASM) { 00831 assert(ImmToIdxMap.count(OpC) && 00832 "No indexed form of load or store available!"); 00833 unsigned NewOpcode = ImmToIdxMap.find(OpC)->second; 00834 MI.setDesc(TII.get(NewOpcode)); 00835 OperandBase = 1; 00836 } else { 00837 OperandBase = OffsetOperandNo; 00838 } 00839 00840 unsigned StackReg = MI.getOperand(FIOperandNum).getReg(); 00841 MI.getOperand(OperandBase).ChangeToRegister(StackReg, false); 00842 MI.getOperand(OperandBase + 1).ChangeToRegister(SReg, false, false, true); 00843 } 00844 00845 unsigned PPCRegisterInfo::getFrameRegister(const MachineFunction &MF) const { 00846 const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering(); 00847 00848 if (!Subtarget.isPPC64()) 00849 return TFI->hasFP(MF) ? PPC::R31 : PPC::R1; 00850 else 00851 return TFI->hasFP(MF) ? PPC::X31 : PPC::X1; 00852 } 00853 00854 unsigned PPCRegisterInfo::getBaseRegister(const MachineFunction &MF) const { 00855 if (!hasBasePointer(MF)) 00856 return getFrameRegister(MF); 00857 00858 if (Subtarget.isPPC64()) 00859 return PPC::X30; 00860 00861 if (Subtarget.isSVR4ABI() && 00862 MF.getTarget().getRelocationModel() == Reloc::PIC_) 00863 return PPC::R29; 00864 00865 return PPC::R30; 00866 } 00867 00868 bool PPCRegisterInfo::hasBasePointer(const MachineFunction &MF) const { 00869 if (!EnableBasePointer) 00870 return false; 00871 if (AlwaysBasePointer) 00872 return true; 00873 00874 // If we need to realign the stack, then the stack pointer can no longer 00875 // serve as an offset into the caller's stack space. As a result, we need a 00876 // base pointer. 00877 return needsStackRealignment(MF); 00878 } 00879 00880 bool PPCRegisterInfo::canRealignStack(const MachineFunction &MF) const { 00881 if (MF.getFunction()->hasFnAttribute("no-realign-stack")) 00882 return false; 00883 00884 return true; 00885 } 00886 00887 bool PPCRegisterInfo::needsStackRealignment(const MachineFunction &MF) const { 00888 const MachineFrameInfo *MFI = MF.getFrameInfo(); 00889 const Function *F = MF.getFunction(); 00890 unsigned StackAlign = MF.getTarget() 00891 .getSubtargetImpl() 00892 ->getFrameLowering() 00893 ->getStackAlignment(); 00894 bool requiresRealignment = 00895 ((MFI->getMaxAlignment() > StackAlign) || 00896 F->getAttributes().hasAttribute(AttributeSet::FunctionIndex, 00897 Attribute::StackAlignment)); 00898 00899 return requiresRealignment && canRealignStack(MF); 00900 } 00901 00902 /// Returns true if the instruction's frame index 00903 /// reference would be better served by a base register other than FP 00904 /// or SP. Used by LocalStackFrameAllocation to determine which frame index 00905 /// references it should create new base registers for. 00906 bool PPCRegisterInfo:: 00907 needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const { 00908 assert(Offset < 0 && "Local offset must be negative"); 00909 00910 // It's the load/store FI references that cause issues, as it can be difficult 00911 // to materialize the offset if it won't fit in the literal field. Estimate 00912 // based on the size of the local frame and some conservative assumptions 00913 // about the rest of the stack frame (note, this is pre-regalloc, so 00914 // we don't know everything for certain yet) whether this offset is likely 00915 // to be out of range of the immediate. Return true if so. 00916 00917 // We only generate virtual base registers for loads and stores that have 00918 // an r+i form. Return false for everything else. 00919 unsigned OpC = MI->getOpcode(); 00920 if (!ImmToIdxMap.count(OpC)) 00921 return false; 00922 00923 // Don't generate a new virtual base register just to add zero to it. 00924 if ((OpC == PPC::ADDI || OpC == PPC::ADDI8) && 00925 MI->getOperand(2).getImm() == 0) 00926 return false; 00927 00928 MachineBasicBlock &MBB = *MI->getParent(); 00929 MachineFunction &MF = *MBB.getParent(); 00930 00931 const PPCFrameLowering *PPCFI = static_cast<const PPCFrameLowering *>( 00932 MF.getSubtarget().getFrameLowering()); 00933 unsigned StackEst = 00934 PPCFI->determineFrameLayout(MF, false, true); 00935 00936 // If we likely don't need a stack frame, then we probably don't need a 00937 // virtual base register either. 00938 if (!StackEst) 00939 return false; 00940 00941 // Estimate an offset from the stack pointer. 00942 // The incoming offset is relating to the SP at the start of the function, 00943 // but when we access the local it'll be relative to the SP after local 00944 // allocation, so adjust our SP-relative offset by that allocation size. 00945 Offset += StackEst; 00946 00947 // The frame pointer will point to the end of the stack, so estimate the 00948 // offset as the difference between the object offset and the FP location. 00949 return !isFrameOffsetLegal(MI, Offset); 00950 } 00951 00952 /// Insert defining instruction(s) for BaseReg to 00953 /// be a pointer to FrameIdx at the beginning of the basic block. 00954 void PPCRegisterInfo:: 00955 materializeFrameBaseRegister(MachineBasicBlock *MBB, 00956 unsigned BaseReg, int FrameIdx, 00957 int64_t Offset) const { 00958 unsigned ADDriOpc = Subtarget.isPPC64() ? PPC::ADDI8 : PPC::ADDI; 00959 00960 MachineBasicBlock::iterator Ins = MBB->begin(); 00961 DebugLoc DL; // Defaults to "unknown" 00962 if (Ins != MBB->end()) 00963 DL = Ins->getDebugLoc(); 00964 00965 const MachineFunction &MF = *MBB->getParent(); 00966 const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo(); 00967 const MCInstrDesc &MCID = TII.get(ADDriOpc); 00968 MachineRegisterInfo &MRI = MBB->getParent()->getRegInfo(); 00969 MRI.constrainRegClass(BaseReg, TII.getRegClass(MCID, 0, this, MF)); 00970 00971 BuildMI(*MBB, Ins, DL, MCID, BaseReg) 00972 .addFrameIndex(FrameIdx).addImm(Offset); 00973 } 00974 00975 void PPCRegisterInfo::resolveFrameIndex(MachineInstr &MI, unsigned BaseReg, 00976 int64_t Offset) const { 00977 unsigned FIOperandNum = 0; 00978 while (!MI.getOperand(FIOperandNum).isFI()) { 00979 ++FIOperandNum; 00980 assert(FIOperandNum < MI.getNumOperands() && 00981 "Instr doesn't have FrameIndex operand!"); 00982 } 00983 00984 MI.getOperand(FIOperandNum).ChangeToRegister(BaseReg, false); 00985 unsigned OffsetOperandNo = getOffsetONFromFION(MI, FIOperandNum); 00986 Offset += MI.getOperand(OffsetOperandNo).getImm(); 00987 MI.getOperand(OffsetOperandNo).ChangeToImmediate(Offset); 00988 00989 MachineBasicBlock &MBB = *MI.getParent(); 00990 MachineFunction &MF = *MBB.getParent(); 00991 const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo(); 00992 const MCInstrDesc &MCID = MI.getDesc(); 00993 MachineRegisterInfo &MRI = MF.getRegInfo(); 00994 MRI.constrainRegClass(BaseReg, 00995 TII.getRegClass(MCID, FIOperandNum, this, MF)); 00996 } 00997 00998 bool PPCRegisterInfo::isFrameOffsetLegal(const MachineInstr *MI, 00999 int64_t Offset) const { 01000 unsigned FIOperandNum = 0; 01001 while (!MI->getOperand(FIOperandNum).isFI()) { 01002 ++FIOperandNum; 01003 assert(FIOperandNum < MI->getNumOperands() && 01004 "Instr doesn't have FrameIndex operand!"); 01005 } 01006 01007 unsigned OffsetOperandNo = getOffsetONFromFION(*MI, FIOperandNum); 01008 Offset += MI->getOperand(OffsetOperandNo).getImm(); 01009 01010 return MI->getOpcode() == PPC::DBG_VALUE || // DBG_VALUE is always Reg+Imm 01011 (isInt<16>(Offset) && (!usesIXAddr(*MI) || (Offset & 3) == 0)); 01012 } 01013