Don't reserve R31 on PPC64 unless the frame pointer is needed
[oota-llvm.git] / lib / Target / PowerPC / PPCRegisterInfo.cpp
1 //===-- PPCRegisterInfo.cpp - PowerPC Register Information ----------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the PowerPC implementation of the TargetRegisterInfo
11 // class.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #define DEBUG_TYPE "reginfo"
16 #include "PPCRegisterInfo.h"
17 #include "PPC.h"
18 #include "PPCFrameLowering.h"
19 #include "PPCInstrBuilder.h"
20 #include "PPCMachineFunctionInfo.h"
21 #include "PPCSubtarget.h"
22 #include "llvm/ADT/BitVector.h"
23 #include "llvm/ADT/STLExtras.h"
24 #include "llvm/CodeGen/MachineFrameInfo.h"
25 #include "llvm/CodeGen/MachineFunction.h"
26 #include "llvm/CodeGen/MachineInstrBuilder.h"
27 #include "llvm/CodeGen/MachineModuleInfo.h"
28 #include "llvm/CodeGen/MachineRegisterInfo.h"
29 #include "llvm/CodeGen/RegisterScavenging.h"
30 #include "llvm/CodeGen/ValueTypes.h"
31 #include "llvm/IR/CallingConv.h"
32 #include "llvm/IR/Constants.h"
33 #include "llvm/IR/Function.h"
34 #include "llvm/IR/Type.h"
35 #include "llvm/Support/CommandLine.h"
36 #include "llvm/Support/Debug.h"
37 #include "llvm/Support/ErrorHandling.h"
38 #include "llvm/Support/MathExtras.h"
39 #include "llvm/Support/raw_ostream.h"
40 #include "llvm/Target/TargetFrameLowering.h"
41 #include "llvm/Target/TargetInstrInfo.h"
42 #include "llvm/Target/TargetMachine.h"
43 #include "llvm/Target/TargetOptions.h"
44 #include <cstdlib>
45
46 #define GET_REGINFO_TARGET_DESC
47 #include "PPCGenRegisterInfo.inc"
48
49 using namespace llvm;
50
51 PPCRegisterInfo::PPCRegisterInfo(const PPCSubtarget &ST,
52                                  const TargetInstrInfo &tii)
53   : PPCGenRegisterInfo(ST.isPPC64() ? PPC::LR8 : PPC::LR,
54                        ST.isPPC64() ? 0 : 1,
55                        ST.isPPC64() ? 0 : 1),
56     Subtarget(ST), TII(tii) {
57   ImmToIdxMap[PPC::LD]   = PPC::LDX;    ImmToIdxMap[PPC::STD]  = PPC::STDX;
58   ImmToIdxMap[PPC::LBZ]  = PPC::LBZX;   ImmToIdxMap[PPC::STB]  = PPC::STBX;
59   ImmToIdxMap[PPC::LHZ]  = PPC::LHZX;   ImmToIdxMap[PPC::LHA]  = PPC::LHAX;
60   ImmToIdxMap[PPC::LWZ]  = PPC::LWZX;   ImmToIdxMap[PPC::LWA]  = PPC::LWAX;
61   ImmToIdxMap[PPC::LFS]  = PPC::LFSX;   ImmToIdxMap[PPC::LFD]  = PPC::LFDX;
62   ImmToIdxMap[PPC::STH]  = PPC::STHX;   ImmToIdxMap[PPC::STW]  = PPC::STWX;
63   ImmToIdxMap[PPC::STFS] = PPC::STFSX;  ImmToIdxMap[PPC::STFD] = PPC::STFDX;
64   ImmToIdxMap[PPC::ADDI] = PPC::ADD4;
65
66   // 64-bit
67   ImmToIdxMap[PPC::LHA8] = PPC::LHAX8; ImmToIdxMap[PPC::LBZ8] = PPC::LBZX8;
68   ImmToIdxMap[PPC::LHZ8] = PPC::LHZX8; ImmToIdxMap[PPC::LWZ8] = PPC::LWZX8;
69   ImmToIdxMap[PPC::STB8] = PPC::STBX8; ImmToIdxMap[PPC::STH8] = PPC::STHX8;
70   ImmToIdxMap[PPC::STW8] = PPC::STWX8; ImmToIdxMap[PPC::STDU] = PPC::STDUX;
71   ImmToIdxMap[PPC::ADDI8] = PPC::ADD8; ImmToIdxMap[PPC::STD_32] = PPC::STDX_32;
72 }
73
74 /// getPointerRegClass - Return the register class to use to hold pointers.
75 /// This is used for addressing modes.
76 const TargetRegisterClass *
77 PPCRegisterInfo::getPointerRegClass(const MachineFunction &MF, unsigned Kind)
78                                                                        const {
79   if (Subtarget.isPPC64())
80     return &PPC::G8RCRegClass;
81   return &PPC::GPRCRegClass;
82 }
83
84 const uint16_t*
85 PPCRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const {
86   if (Subtarget.isDarwinABI())
87     return Subtarget.isPPC64() ? CSR_Darwin64_SaveList :
88                                  CSR_Darwin32_SaveList;
89
90   return Subtarget.isPPC64() ? CSR_SVR464_SaveList : CSR_SVR432_SaveList;
91 }
92
93 const uint32_t*
94 PPCRegisterInfo::getCallPreservedMask(CallingConv::ID CC) const {
95   if (Subtarget.isDarwinABI())
96     return Subtarget.isPPC64() ? CSR_Darwin64_RegMask :
97                                  CSR_Darwin32_RegMask;
98
99   return Subtarget.isPPC64() ? CSR_SVR464_RegMask : CSR_SVR432_RegMask;
100 }
101
102 BitVector PPCRegisterInfo::getReservedRegs(const MachineFunction &MF) const {
103   BitVector Reserved(getNumRegs());
104   const PPCFrameLowering *PPCFI =
105     static_cast<const PPCFrameLowering*>(MF.getTarget().getFrameLowering());
106
107   Reserved.set(PPC::R0);
108   Reserved.set(PPC::R1);
109   Reserved.set(PPC::LR);
110   Reserved.set(PPC::LR8);
111   Reserved.set(PPC::RM);
112
113   // The SVR4 ABI reserves r2 and r13
114   if (Subtarget.isSVR4ABI()) {
115     Reserved.set(PPC::R2);  // System-reserved register
116     Reserved.set(PPC::R13); // Small Data Area pointer register
117   }
118   
119   // On PPC64, r13 is the thread pointer. Never allocate this register.
120   if (Subtarget.isPPC64()) {
121     Reserved.set(PPC::R13);
122
123     Reserved.set(PPC::X0);
124     Reserved.set(PPC::X1);
125     Reserved.set(PPC::X13);
126
127     if (PPCFI->needsFP(MF))
128       Reserved.set(PPC::X31);
129
130     // The 64-bit SVR4 ABI reserves r2 for the TOC pointer.
131     if (Subtarget.isSVR4ABI()) {
132       Reserved.set(PPC::X2);
133     }
134   }
135
136   if (PPCFI->needsFP(MF))
137     Reserved.set(PPC::R31);
138
139   return Reserved;
140 }
141
142 unsigned
143 PPCRegisterInfo::getRegPressureLimit(const TargetRegisterClass *RC,
144                                          MachineFunction &MF) const {
145   const TargetFrameLowering *TFI = MF.getTarget().getFrameLowering();
146   const unsigned DefaultSafety = 1;
147
148   switch (RC->getID()) {
149   default:
150     return 0;
151   case PPC::G8RCRegClassID:
152   case PPC::GPRCRegClassID: {
153     unsigned FP = TFI->hasFP(MF) ? 1 : 0;
154     return 32 - FP - DefaultSafety;
155   }
156   case PPC::F8RCRegClassID:
157   case PPC::F4RCRegClassID:
158   case PPC::VRRCRegClassID:
159     return 32 - DefaultSafety;
160   case PPC::CRRCRegClassID:
161     return 8 - DefaultSafety;
162   }
163 }
164
165 //===----------------------------------------------------------------------===//
166 // Stack Frame Processing methods
167 //===----------------------------------------------------------------------===//
168
169 /// lowerDynamicAlloc - Generate the code for allocating an object in the
170 /// current frame.  The sequence of code with be in the general form
171 ///
172 ///   addi   R0, SP, \#frameSize ; get the address of the previous frame
173 ///   stwxu  R0, SP, Rnegsize   ; add and update the SP with the negated size
174 ///   addi   Rnew, SP, \#maxCalFrameSize ; get the top of the allocation
175 ///
176 void PPCRegisterInfo::lowerDynamicAlloc(MachineBasicBlock::iterator II,
177                                         int SPAdj, RegScavenger *RS) const {
178   // Get the instruction.
179   MachineInstr &MI = *II;
180   // Get the instruction's basic block.
181   MachineBasicBlock &MBB = *MI.getParent();
182   // Get the basic block's function.
183   MachineFunction &MF = *MBB.getParent();
184   // Get the frame info.
185   MachineFrameInfo *MFI = MF.getFrameInfo();
186   // Determine whether 64-bit pointers are used.
187   bool LP64 = Subtarget.isPPC64();
188   DebugLoc dl = MI.getDebugLoc();
189
190   // Get the maximum call stack size.
191   unsigned maxCallFrameSize = MFI->getMaxCallFrameSize();
192   // Get the total frame size.
193   unsigned FrameSize = MFI->getStackSize();
194   
195   // Get stack alignments.
196   unsigned TargetAlign = MF.getTarget().getFrameLowering()->getStackAlignment();
197   unsigned MaxAlign = MFI->getMaxAlignment();
198   if (MaxAlign > TargetAlign)
199     report_fatal_error("Dynamic alloca with large aligns not supported");
200
201   // Determine the previous frame's address.  If FrameSize can't be
202   // represented as 16 bits or we need special alignment, then we load the
203   // previous frame's address from 0(SP).  Why not do an addis of the hi? 
204   // Because R0 is our only safe tmp register and addi/addis treat R0 as zero. 
205   // Constructing the constant and adding would take 3 instructions. 
206   // Fortunately, a frame greater than 32K is rare.
207   const TargetRegisterClass *G8RC = &PPC::G8RCRegClass;
208   const TargetRegisterClass *GPRC = &PPC::GPRCRegClass;
209   unsigned Reg = MF.getRegInfo().createVirtualRegister(LP64 ? G8RC : GPRC);
210   
211   if (MaxAlign < TargetAlign && isInt<16>(FrameSize)) {
212     BuildMI(MBB, II, dl, TII.get(PPC::ADDI), Reg)
213       .addReg(PPC::R31)
214       .addImm(FrameSize);
215   } else if (LP64) {
216     BuildMI(MBB, II, dl, TII.get(PPC::LD), Reg)
217       .addImm(0)
218       .addReg(PPC::X1);
219   } else {
220     BuildMI(MBB, II, dl, TII.get(PPC::LWZ), Reg)
221       .addImm(0)
222       .addReg(PPC::R1);
223   }
224   
225   // Grow the stack and update the stack pointer link, then determine the
226   // address of new allocated space.
227   if (LP64) {
228     BuildMI(MBB, II, dl, TII.get(PPC::STDUX), PPC::X1)
229       .addReg(Reg, RegState::Kill)
230       .addReg(PPC::X1)
231       .addReg(MI.getOperand(1).getReg());
232     if (!MI.getOperand(1).isKill())
233       BuildMI(MBB, II, dl, TII.get(PPC::ADDI8), MI.getOperand(0).getReg())
234         .addReg(PPC::X1)
235         .addImm(maxCallFrameSize);
236     else
237       // Implicitly kill the register.
238       BuildMI(MBB, II, dl, TII.get(PPC::ADDI8), MI.getOperand(0).getReg())
239         .addReg(PPC::X1)
240         .addImm(maxCallFrameSize)
241         .addReg(MI.getOperand(1).getReg(), RegState::ImplicitKill);
242   } else {
243     BuildMI(MBB, II, dl, TII.get(PPC::STWUX), PPC::R1)
244       .addReg(Reg, RegState::Kill)
245       .addReg(PPC::R1)
246       .addReg(MI.getOperand(1).getReg());
247
248     if (!MI.getOperand(1).isKill())
249       BuildMI(MBB, II, dl, TII.get(PPC::ADDI), MI.getOperand(0).getReg())
250         .addReg(PPC::R1)
251         .addImm(maxCallFrameSize);
252     else
253       // Implicitly kill the register.
254       BuildMI(MBB, II, dl, TII.get(PPC::ADDI), MI.getOperand(0).getReg())
255         .addReg(PPC::R1)
256         .addImm(maxCallFrameSize)
257         .addReg(MI.getOperand(1).getReg(), RegState::ImplicitKill);
258   }
259   
260   // Discard the DYNALLOC instruction.
261   MBB.erase(II);
262 }
263
264 /// lowerCRSpilling - Generate the code for spilling a CR register. Instead of
265 /// reserving a whole register (R0), we scrounge for one here. This generates
266 /// code like this:
267 ///
268 ///   mfcr rA                  ; Move the conditional register into GPR rA.
269 ///   rlwinm rA, rA, SB, 0, 31 ; Shift the bits left so they are in CR0's slot.
270 ///   stw rA, FI               ; Store rA to the frame.
271 ///
272 void PPCRegisterInfo::lowerCRSpilling(MachineBasicBlock::iterator II,
273                                       unsigned FrameIndex, int SPAdj,
274                                       RegScavenger *RS) const {
275   // Get the instruction.
276   MachineInstr &MI = *II;       // ; SPILL_CR <SrcReg>, <offset>
277   // Get the instruction's basic block.
278   MachineBasicBlock &MBB = *MI.getParent();
279   DebugLoc dl = MI.getDebugLoc();
280
281   // FIXME: Once LLVM supports creating virtual registers here, or the register
282   // scavenger can return multiple registers, stop using reserved registers
283   // here.
284   (void) SPAdj;
285   (void) RS;
286
287   bool LP64 = Subtarget.isPPC64();
288   unsigned Reg = LP64 ? PPC::X0 : PPC::R0;
289   unsigned SrcReg = MI.getOperand(0).getReg();
290
291   // We need to store the CR in the low 4-bits of the saved value. First, issue
292   // an MFCRpsued to save all of the CRBits and, if needed, kill the SrcReg.
293   BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::MFCR8pseud : PPC::MFCRpseud), Reg)
294           .addReg(SrcReg, getKillRegState(MI.getOperand(0).isKill()));
295     
296   // If the saved register wasn't CR0, shift the bits left so that they are in
297   // CR0's slot.
298   if (SrcReg != PPC::CR0)
299     // rlwinm rA, rA, ShiftBits, 0, 31.
300     BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::RLWINM8 : PPC::RLWINM), Reg)
301       .addReg(Reg, RegState::Kill)
302       .addImm(getPPCRegisterNumbering(SrcReg) * 4)
303       .addImm(0)
304       .addImm(31);
305
306   addFrameReference(BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::STW8 : PPC::STW))
307                     .addReg(Reg, getKillRegState(MI.getOperand(1).getImm())),
308                     FrameIndex);
309
310   // Discard the pseudo instruction.
311   MBB.erase(II);
312 }
313
314 void PPCRegisterInfo::lowerCRRestore(MachineBasicBlock::iterator II,
315                                       unsigned FrameIndex, int SPAdj,
316                                       RegScavenger *RS) const {
317   // Get the instruction.
318   MachineInstr &MI = *II;       // ; <DestReg> = RESTORE_CR <offset>
319   // Get the instruction's basic block.
320   MachineBasicBlock &MBB = *MI.getParent();
321   DebugLoc dl = MI.getDebugLoc();
322
323   // FIXME: Once LLVM supports creating virtual registers here, or the register
324   // scavenger can return multiple registers, stop using reserved registers
325   // here.
326   (void) SPAdj;
327   (void) RS;
328
329   bool LP64 = Subtarget.isPPC64();
330   unsigned Reg = LP64 ? PPC::X0 : PPC::R0;
331   unsigned DestReg = MI.getOperand(0).getReg();
332   assert(MI.definesRegister(DestReg) &&
333     "RESTORE_CR does not define its destination");
334
335   addFrameReference(BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::LWZ8 : PPC::LWZ),
336                               Reg), FrameIndex);
337
338   // If the reloaded register isn't CR0, shift the bits right so that they are
339   // in the right CR's slot.
340   if (DestReg != PPC::CR0) {
341     unsigned ShiftBits = getPPCRegisterNumbering(DestReg)*4;
342     // rlwinm r11, r11, 32-ShiftBits, 0, 31.
343     BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::RLWINM8 : PPC::RLWINM), Reg)
344              .addReg(Reg).addImm(32-ShiftBits).addImm(0)
345              .addImm(31);
346   }
347
348   BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::MTCRF8 : PPC::MTCRF), DestReg)
349              .addReg(Reg);
350
351   // Discard the pseudo instruction.
352   MBB.erase(II);
353 }
354
355 bool
356 PPCRegisterInfo::hasReservedSpillSlot(const MachineFunction &MF,
357                                       unsigned Reg, int &FrameIdx) const {
358
359   // For the nonvolatile condition registers (CR2, CR3, CR4) in an SVR4
360   // ABI, return true to prevent allocating an additional frame slot.
361   // For 64-bit, the CR save area is at SP+8; the value of FrameIdx = 0
362   // is arbitrary and will be subsequently ignored.  For 32-bit, we have
363   // previously created the stack slot if needed, so return its FrameIdx.
364   if (Subtarget.isSVR4ABI() && PPC::CR2 <= Reg && Reg <= PPC::CR4) {
365     if (Subtarget.isPPC64())
366       FrameIdx = 0;
367     else {
368       const PPCFunctionInfo *FI = MF.getInfo<PPCFunctionInfo>();
369       FrameIdx = FI->getCRSpillFrameIndex();
370     }
371     return true;
372   }
373   return false;
374 }
375
376 void
377 PPCRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
378                                      int SPAdj, unsigned FIOperandNum,
379                                      RegScavenger *RS) const {
380   assert(SPAdj == 0 && "Unexpected");
381
382   // Get the instruction.
383   MachineInstr &MI = *II;
384   // Get the instruction's basic block.
385   MachineBasicBlock &MBB = *MI.getParent();
386   // Get the basic block's function.
387   MachineFunction &MF = *MBB.getParent();
388   // Get the frame info.
389   MachineFrameInfo *MFI = MF.getFrameInfo();
390   const TargetFrameLowering *TFI = MF.getTarget().getFrameLowering();
391   DebugLoc dl = MI.getDebugLoc();
392
393   // Take into account whether it's an add or mem instruction
394   unsigned OffsetOperandNo = (FIOperandNum == 2) ? 1 : 2;
395   if (MI.isInlineAsm())
396     OffsetOperandNo = FIOperandNum-1;
397
398   // Get the frame index.
399   int FrameIndex = MI.getOperand(FIOperandNum).getIndex();
400
401   // Get the frame pointer save index.  Users of this index are primarily
402   // DYNALLOC instructions.
403   PPCFunctionInfo *FI = MF.getInfo<PPCFunctionInfo>();
404   int FPSI = FI->getFramePointerSaveIndex();
405   // Get the instruction opcode.
406   unsigned OpC = MI.getOpcode();
407   
408   // Special case for dynamic alloca.
409   if (FPSI && FrameIndex == FPSI &&
410       (OpC == PPC::DYNALLOC || OpC == PPC::DYNALLOC8)) {
411     lowerDynamicAlloc(II, SPAdj, RS);
412     return;
413   }
414
415   // Special case for pseudo-ops SPILL_CR and RESTORE_CR.
416   if (OpC == PPC::SPILL_CR) {
417     lowerCRSpilling(II, FrameIndex, SPAdj, RS);
418     return;
419   } else if (OpC == PPC::RESTORE_CR) {
420     lowerCRRestore(II, FrameIndex, SPAdj, RS);
421     return;
422   }
423
424   // Replace the FrameIndex with base register with GPR1 (SP) or GPR31 (FP).
425
426   bool is64Bit = Subtarget.isPPC64();
427   MI.getOperand(FIOperandNum).ChangeToRegister(TFI->hasFP(MF) ?
428                                               (is64Bit ? PPC::X31 : PPC::R31) :
429                                                 (is64Bit ? PPC::X1 : PPC::R1),
430                                               false);
431
432   // Figure out if the offset in the instruction is shifted right two bits. This
433   // is true for instructions like "STD", which the machine implicitly adds two
434   // low zeros to.
435   bool isIXAddr = false;
436   switch (OpC) {
437   case PPC::LWA:
438   case PPC::LD:
439   case PPC::STD:
440   case PPC::STD_32:
441     isIXAddr = true;
442     break;
443   }
444
445   bool noImmForm = false;
446   switch (OpC) {
447   case PPC::LVEBX:
448   case PPC::LVEHX:
449   case PPC::LVEWX:
450   case PPC::LVX:
451   case PPC::LVXL:
452   case PPC::LVSL:
453   case PPC::LVSR:
454   case PPC::STVEBX:
455   case PPC::STVEHX:
456   case PPC::STVEWX:
457   case PPC::STVX:
458   case PPC::STVXL:
459     noImmForm = true;
460     break;
461   }
462
463   // Now add the frame object offset to the offset from r1.
464   int Offset = MFI->getObjectOffset(FrameIndex);
465   if (!isIXAddr)
466     Offset += MI.getOperand(OffsetOperandNo).getImm();
467   else
468     Offset += MI.getOperand(OffsetOperandNo).getImm() << 2;
469
470   // If we're not using a Frame Pointer that has been set to the value of the
471   // SP before having the stack size subtracted from it, then add the stack size
472   // to Offset to get the correct offset.
473   // Naked functions have stack size 0, although getStackSize may not reflect that
474   // because we didn't call all the pieces that compute it for naked functions.
475   if (!MF.getFunction()->getAttributes().
476         hasAttribute(AttributeSet::FunctionIndex, Attribute::Naked))
477     Offset += MFI->getStackSize();
478
479   // If we can, encode the offset directly into the instruction.  If this is a
480   // normal PPC "ri" instruction, any 16-bit value can be safely encoded.  If
481   // this is a PPC64 "ix" instruction, only a 16-bit value with the low two bits
482   // clear can be encoded.  This is extremely uncommon, because normally you
483   // only "std" to a stack slot that is at least 4-byte aligned, but it can
484   // happen in invalid code.
485   if (OpC == PPC::DBG_VALUE || // DBG_VALUE is always Reg+Imm
486       (!noImmForm &&
487        isInt<16>(Offset) && (!isIXAddr || (Offset & 3) == 0))) {
488     if (isIXAddr)
489       Offset >>= 2;    // The actual encoded value has the low two bits zero.
490     MI.getOperand(OffsetOperandNo).ChangeToImmediate(Offset);
491     return;
492   }
493
494   // The offset doesn't fit into a single register, scavenge one to build the
495   // offset in.
496
497   const TargetRegisterClass *G8RC = &PPC::G8RCRegClass;
498   const TargetRegisterClass *GPRC = &PPC::GPRCRegClass;
499   unsigned SReg = MF.getRegInfo().createVirtualRegister(is64Bit ? G8RC : GPRC);
500
501   // Insert a set of rA with the full offset value before the ld, st, or add
502   BuildMI(MBB, II, dl, TII.get(is64Bit ? PPC::LIS8 : PPC::LIS), SReg)
503     .addImm(Offset >> 16);
504   BuildMI(MBB, II, dl, TII.get(is64Bit ? PPC::ORI8 : PPC::ORI), SReg)
505     .addReg(SReg, RegState::Kill)
506     .addImm(Offset);
507
508   // Convert into indexed form of the instruction:
509   // 
510   //   sth 0:rA, 1:imm 2:(rB) ==> sthx 0:rA, 2:rB, 1:r0
511   //   addi 0:rA 1:rB, 2, imm ==> add 0:rA, 1:rB, 2:r0
512   unsigned OperandBase;
513
514   if (noImmForm)
515     OperandBase = 1;
516   else if (OpC != TargetOpcode::INLINEASM) {
517     assert(ImmToIdxMap.count(OpC) &&
518            "No indexed form of load or store available!");
519     unsigned NewOpcode = ImmToIdxMap.find(OpC)->second;
520     MI.setDesc(TII.get(NewOpcode));
521     OperandBase = 1;
522   } else {
523     OperandBase = OffsetOperandNo;
524   }
525
526   unsigned StackReg = MI.getOperand(FIOperandNum).getReg();
527   MI.getOperand(OperandBase).ChangeToRegister(StackReg, false);
528   MI.getOperand(OperandBase + 1).ChangeToRegister(SReg, false, false, true);
529 }
530
531 unsigned PPCRegisterInfo::getFrameRegister(const MachineFunction &MF) const {
532   const TargetFrameLowering *TFI = MF.getTarget().getFrameLowering();
533
534   if (!Subtarget.isPPC64())
535     return TFI->hasFP(MF) ? PPC::R31 : PPC::R1;
536   else
537     return TFI->hasFP(MF) ? PPC::X31 : PPC::X1;
538 }
539
540 unsigned PPCRegisterInfo::getEHExceptionRegister() const {
541   return !Subtarget.isPPC64() ? PPC::R3 : PPC::X3;
542 }
543
544 unsigned PPCRegisterInfo::getEHHandlerRegister() const {
545   return !Subtarget.isPPC64() ? PPC::R4 : PPC::X4;
546 }