LLVM API Documentation

MipsRegisterInfo.cpp

Go to the documentation of this file.
00001 //===- MipsRegisterInfo.cpp - MIPS Register 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 MIPS implementation of the TargetRegisterInfo class.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #define DEBUG_TYPE "mips-reg-info"
00015 
00016 #include "Mips.h"
00017 #include "MipsSubtarget.h"
00018 #include "MipsRegisterInfo.h"
00019 #include "MipsMachineFunction.h"
00020 #include "llvm/Constants.h"
00021 #include "llvm/Type.h"
00022 #include "llvm/Function.h"
00023 #include "llvm/CodeGen/ValueTypes.h"
00024 #include "llvm/CodeGen/MachineInstrBuilder.h"
00025 #include "llvm/CodeGen/MachineFunction.h"
00026 #include "llvm/CodeGen/MachineFrameInfo.h"
00027 #include "llvm/CodeGen/MachineLocation.h"
00028 #include "llvm/Target/TargetFrameInfo.h"
00029 #include "llvm/Target/TargetMachine.h"
00030 #include "llvm/Target/TargetOptions.h"
00031 #include "llvm/Target/TargetInstrInfo.h"
00032 #include "llvm/Support/CommandLine.h"
00033 #include "llvm/Support/Debug.h"
00034 #include "llvm/Support/ErrorHandling.h"
00035 #include "llvm/Support/raw_ostream.h"
00036 #include "llvm/ADT/BitVector.h"
00037 #include "llvm/ADT/STLExtras.h"
00038 
00039 using namespace llvm;
00040 
00041 MipsRegisterInfo::MipsRegisterInfo(const MipsSubtarget &ST, 
00042                                    const TargetInstrInfo &tii)
00043   : MipsGenRegisterInfo(Mips::ADJCALLSTACKDOWN, Mips::ADJCALLSTACKUP),
00044     Subtarget(ST), TII(tii) {}
00045 
00046 /// getRegisterNumbering - Given the enum value for some register, e.g.
00047 /// Mips::RA, return the number that it corresponds to (e.g. 31).
00048 unsigned MipsRegisterInfo::
00049 getRegisterNumbering(unsigned RegEnum) 
00050 {
00051   switch (RegEnum) {
00052     case Mips::ZERO : case Mips::F0 : case Mips::D0 : return 0;
00053     case Mips::AT   : case Mips::F1 : return 1;
00054     case Mips::V0   : case Mips::F2 : case Mips::D1 : return 2;
00055     case Mips::V1   : case Mips::F3 : return 3;
00056     case Mips::A0   : case Mips::F4 : case Mips::D2 : return 4;
00057     case Mips::A1   : case Mips::F5 : return 5;
00058     case Mips::A2   : case Mips::F6 : case Mips::D3 : return 6;
00059     case Mips::A3   : case Mips::F7 : return 7;
00060     case Mips::T0   : case Mips::F8 : case Mips::D4 : return 8;
00061     case Mips::T1   : case Mips::F9 : return 9;
00062     case Mips::T2   : case Mips::F10: case Mips::D5: return 10;
00063     case Mips::T3   : case Mips::F11: return 11;
00064     case Mips::T4   : case Mips::F12: case Mips::D6: return 12;
00065     case Mips::T5   : case Mips::F13: return 13;
00066     case Mips::T6   : case Mips::F14: case Mips::D7: return 14;
00067     case Mips::T7   : case Mips::F15: return 15;
00068     case Mips::T8   : case Mips::F16: case Mips::D8: return 16;
00069     case Mips::T9   : case Mips::F17: return 17;
00070     case Mips::S0   : case Mips::F18: case Mips::D9: return 18;
00071     case Mips::S1   : case Mips::F19: return 19;
00072     case Mips::S2   : case Mips::F20: case Mips::D10: return 20;
00073     case Mips::S3   : case Mips::F21: return 21;
00074     case Mips::S4   : case Mips::F22: case Mips::D11: return 22;
00075     case Mips::S5   : case Mips::F23: return 23;
00076     case Mips::S6   : case Mips::F24: case Mips::D12: return 24;
00077     case Mips::S7   : case Mips::F25: return 25;
00078     case Mips::K0   : case Mips::F26: case Mips::D13: return 26;
00079     case Mips::K1   : case Mips::F27: return 27;
00080     case Mips::GP   : case Mips::F28: case Mips::D14: return 28;
00081     case Mips::SP   : case Mips::F29: return 29;
00082     case Mips::FP   : case Mips::F30: case Mips::D15: return 30;
00083     case Mips::RA   : case Mips::F31: return 31;
00084     default: llvm_unreachable("Unknown register number!");
00085   }    
00086   return 0; // Not reached
00087 }
00088 
00089 unsigned MipsRegisterInfo::getPICCallReg() { return Mips::T9; }
00090 
00091 //===----------------------------------------------------------------------===//
00092 // Callee Saved Registers methods 
00093 //===----------------------------------------------------------------------===//
00094 
00095 /// Mips Callee Saved Registers
00096 const unsigned* MipsRegisterInfo::
00097 getCalleeSavedRegs(const MachineFunction *MF) const 
00098 {
00099   // Mips callee-save register range is $16-$23, $f20-$f30
00100   static const unsigned SingleFloatOnlyCalleeSavedRegs[] = {
00101     Mips::S0, Mips::S1, Mips::S2, Mips::S3, 
00102     Mips::S4, Mips::S5, Mips::S6, Mips::S7,
00103     Mips::F20, Mips::F21, Mips::F22, Mips::F23, Mips::F24, Mips::F25, 
00104     Mips::F26, Mips::F27, Mips::F28, Mips::F29, Mips::F30, 0
00105   };
00106 
00107   static const unsigned BitMode32CalleeSavedRegs[] = {
00108     Mips::S0, Mips::S1, Mips::S2, Mips::S3, 
00109     Mips::S4, Mips::S5, Mips::S6, Mips::S7,
00110     Mips::F20, Mips::F22, Mips::F24, Mips::F26, Mips::F28, Mips::F30, 
00111     Mips::D10, Mips::D11, Mips::D12, Mips::D13, Mips::D14, Mips::D15,0
00112   };
00113 
00114   if (Subtarget.isSingleFloat())
00115     return SingleFloatOnlyCalleeSavedRegs;
00116   else
00117     return BitMode32CalleeSavedRegs;
00118 }
00119 
00120 /// Mips Callee Saved Register Classes
00121 const TargetRegisterClass* const* 
00122 MipsRegisterInfo::getCalleeSavedRegClasses(const MachineFunction *MF) const 
00123 {
00124   static const TargetRegisterClass * const SingleFloatOnlyCalleeSavedRC[] = {
00125     &Mips::CPURegsRegClass, &Mips::CPURegsRegClass, &Mips::CPURegsRegClass, 
00126     &Mips::CPURegsRegClass, &Mips::CPURegsRegClass, &Mips::CPURegsRegClass,
00127     &Mips::CPURegsRegClass, &Mips::CPURegsRegClass,
00128     &Mips::FGR32RegClass, &Mips::FGR32RegClass, &Mips::FGR32RegClass, 
00129     &Mips::FGR32RegClass, &Mips::FGR32RegClass, &Mips::FGR32RegClass, 
00130     &Mips::FGR32RegClass, &Mips::FGR32RegClass, &Mips::FGR32RegClass, 
00131     &Mips::FGR32RegClass, &Mips::FGR32RegClass, 0
00132   };
00133 
00134   static const TargetRegisterClass * const BitMode32CalleeSavedRC[] = {
00135     &Mips::CPURegsRegClass, &Mips::CPURegsRegClass, &Mips::CPURegsRegClass, 
00136     &Mips::CPURegsRegClass, &Mips::CPURegsRegClass, &Mips::CPURegsRegClass,
00137     &Mips::CPURegsRegClass, &Mips::CPURegsRegClass,
00138     &Mips::FGR32RegClass, &Mips::FGR32RegClass, &Mips::FGR32RegClass, 
00139     &Mips::FGR32RegClass, &Mips::FGR32RegClass, &Mips::FGR32RegClass,
00140     &Mips::AFGR64RegClass, &Mips::AFGR64RegClass, &Mips::AFGR64RegClass, 
00141     &Mips::AFGR64RegClass, &Mips::AFGR64RegClass, &Mips::AFGR64RegClass, 0
00142   };
00143 
00144   if (Subtarget.isSingleFloat())
00145     return SingleFloatOnlyCalleeSavedRC;
00146   else
00147     return BitMode32CalleeSavedRC;
00148 }
00149 
00150 BitVector MipsRegisterInfo::
00151 getReservedRegs(const MachineFunction &MF) const
00152 {
00153   BitVector Reserved(getNumRegs());
00154   Reserved.set(Mips::ZERO);
00155   Reserved.set(Mips::AT);
00156   Reserved.set(Mips::K0);
00157   Reserved.set(Mips::K1);
00158   Reserved.set(Mips::GP);
00159   Reserved.set(Mips::SP);
00160   Reserved.set(Mips::FP);
00161   Reserved.set(Mips::RA);
00162 
00163   // SRV4 requires that odd register can't be used.
00164   if (!Subtarget.isSingleFloat())
00165     for (unsigned FReg=(Mips::F0)+1; FReg < Mips::F30; FReg+=2)
00166       Reserved.set(FReg);
00167   
00168   return Reserved;
00169 }
00170 
00171 //===----------------------------------------------------------------------===//
00172 //
00173 // Stack Frame Processing methods
00174 // +----------------------------+
00175 //
00176 // The stack is allocated decrementing the stack pointer on
00177 // the first instruction of a function prologue. Once decremented,
00178 // all stack referencesare are done thought a positive offset
00179 // from the stack/frame pointer, so the stack is considering
00180 // to grow up! Otherwise terrible hacks would have to be made
00181 // to get this stack ABI compliant :)
00182 //
00183 //  The stack frame required by the ABI (after call):
00184 //  Offset
00185 //
00186 //  0                 ----------
00187 //  4                 Args to pass 
00188 //  .                 saved $GP  (used in PIC)
00189 //  .                 Alloca allocations
00190 //  .                 Local Area
00191 //  .                 CPU "Callee Saved" Registers
00192 //  .                 saved FP
00193 //  .                 saved RA
00194 //  .                 FPU "Callee Saved" Registers
00195 //  StackSize         -----------
00196 //
00197 // Offset - offset from sp after stack allocation on function prologue
00198 //
00199 // The sp is the stack pointer subtracted/added from the stack size
00200 // at the Prologue/Epilogue
00201 //
00202 // References to the previous stack (to obtain arguments) are done
00203 // with offsets that exceeds the stack size: (stacksize+(4*(num_arg-1))
00204 //
00205 // Examples:
00206 // - reference to the actual stack frame
00207 //   for any local area var there is smt like : FI >= 0, StackOffset: 4
00208 //     sw REGX, 4(SP)
00209 //
00210 // - reference to previous stack frame
00211 //   suppose there's a load to the 5th arguments : FI < 0, StackOffset: 16.
00212 //   The emitted instruction will be something like:
00213 //     lw REGX, 16+StackSize(SP)
00214 //
00215 // Since the total stack size is unknown on LowerFormalArguments, all
00216 // stack references (ObjectOffset) created to reference the function 
00217 // arguments, are negative numbers. This way, on eliminateFrameIndex it's
00218 // possible to detect those references and the offsets are adjusted to
00219 // their real location.
00220 //
00221 //===----------------------------------------------------------------------===//
00222 
00223 void MipsRegisterInfo::adjustMipsStackFrame(MachineFunction &MF) const
00224 {
00225   MachineFrameInfo *MFI = MF.getFrameInfo();
00226   MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
00227   const std::vector<CalleeSavedInfo> &CSI = MFI->getCalleeSavedInfo();
00228   unsigned StackAlign = MF.getTarget().getFrameInfo()->getStackAlignment();
00229 
00230   // Min and Max CSI FrameIndex.
00231   int MinCSFI = -1, MaxCSFI = -1; 
00232 
00233   // See the description at MipsMachineFunction.h
00234   int TopCPUSavedRegOff = -1, TopFPUSavedRegOff = -1;
00235 
00236   // Replace the dummy '0' SPOffset by the negative offsets, as explained on 
00237   // LowerFormalArguments. Leaving '0' for while is necessary to avoid
00238   // the approach done by calculateFrameObjectOffsets to the stack frame.
00239   MipsFI->adjustLoadArgsFI(MFI);
00240   MipsFI->adjustStoreVarArgsFI(MFI); 
00241 
00242   // It happens that the default stack frame allocation order does not directly 
00243   // map to the convention used for mips. So we must fix it. We move the callee 
00244   // save register slots after the local variables area, as described in the
00245   // stack frame above.
00246   unsigned CalleeSavedAreaSize = 0;
00247   if (!CSI.empty()) {
00248     MinCSFI = CSI[0].getFrameIdx();
00249     MaxCSFI = CSI[CSI.size()-1].getFrameIdx();
00250   }
00251   for (unsigned i = 0, e = CSI.size(); i != e; ++i)
00252     CalleeSavedAreaSize += MFI->getObjectAlignment(CSI[i].getFrameIdx());
00253 
00254   // Adjust local variables. They should come on the stack right
00255   // after the arguments.
00256   int LastOffsetFI = -1;
00257   for (int i = 0, e = MFI->getObjectIndexEnd(); i != e; ++i) {
00258     if (i >= MinCSFI && i <= MaxCSFI)
00259       continue;
00260     if (MFI->isDeadObjectIndex(i))
00261       continue;
00262     unsigned Offset = MFI->getObjectOffset(i) - CalleeSavedAreaSize;
00263     if (LastOffsetFI == -1)
00264       LastOffsetFI = i;
00265     if (Offset > MFI->getObjectOffset(LastOffsetFI))
00266       LastOffsetFI = i;
00267     MFI->setObjectOffset(i, Offset);
00268   }
00269 
00270   // Adjust CPU Callee Saved Registers Area. Registers RA and FP must
00271   // be saved in this CPU Area there is the need. This whole Area must 
00272   // be aligned to the default Stack Alignment requirements.
00273   unsigned StackOffset = 0;
00274   unsigned RegSize = Subtarget.isGP32bit() ? 4 : 8;
00275 
00276   if (LastOffsetFI >= 0)
00277     StackOffset = MFI->getObjectOffset(LastOffsetFI)+ 
00278                   MFI->getObjectSize(LastOffsetFI);
00279   StackOffset = ((StackOffset+StackAlign-1)/StackAlign*StackAlign);
00280 
00281   for (unsigned i = 0, e = CSI.size(); i != e ; ++i) {
00282     if (CSI[i].getRegClass() != Mips::CPURegsRegisterClass)
00283       break;
00284     MFI->setObjectOffset(CSI[i].getFrameIdx(), StackOffset);
00285     TopCPUSavedRegOff = StackOffset;
00286     StackOffset += MFI->getObjectAlignment(CSI[i].getFrameIdx());
00287   }
00288 
00289   if (hasFP(MF)) {
00290     MFI->setObjectOffset(MFI->CreateStackObject(RegSize, RegSize), 
00291                          StackOffset);
00292     MipsFI->setFPStackOffset(StackOffset);
00293     TopCPUSavedRegOff = StackOffset;
00294     StackOffset += RegSize;
00295   }
00296 
00297   if (MFI->hasCalls()) {
00298     MFI->setObjectOffset(MFI->CreateStackObject(RegSize, RegSize), 
00299                          StackOffset);
00300     MipsFI->setRAStackOffset(StackOffset);
00301     TopCPUSavedRegOff = StackOffset;
00302     StackOffset += RegSize;
00303   }
00304   StackOffset = ((StackOffset+StackAlign-1)/StackAlign*StackAlign);
00305   
00306   // Adjust FPU Callee Saved Registers Area. This Area must be 
00307   // aligned to the default Stack Alignment requirements.
00308   for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
00309     if (CSI[i].getRegClass() == Mips::CPURegsRegisterClass)
00310       continue;
00311     MFI->setObjectOffset(CSI[i].getFrameIdx(), StackOffset);
00312     TopFPUSavedRegOff = StackOffset;
00313     StackOffset += MFI->getObjectAlignment(CSI[i].getFrameIdx());
00314   }
00315   StackOffset = ((StackOffset+StackAlign-1)/StackAlign*StackAlign);
00316 
00317   // Update frame info
00318   MFI->setStackSize(StackOffset);
00319 
00320   // Recalculate the final tops offset. The final values must be '0'
00321   // if there isn't a callee saved register for CPU or FPU, otherwise
00322   // a negative offset is needed.
00323   if (TopCPUSavedRegOff >= 0)
00324     MipsFI->setCPUTopSavedRegOff(TopCPUSavedRegOff-StackOffset);
00325 
00326   if (TopFPUSavedRegOff >= 0)
00327     MipsFI->setFPUTopSavedRegOff(TopFPUSavedRegOff-StackOffset);
00328 }
00329 
00330 // hasFP - Return true if the specified function should have a dedicated frame
00331 // pointer register.  This is true if the function has variable sized allocas or
00332 // if frame pointer elimination is disabled.
00333 bool MipsRegisterInfo::
00334 hasFP(const MachineFunction &MF) const {
00335   const MachineFrameInfo *MFI = MF.getFrameInfo();
00336   return NoFramePointerElim || MFI->hasVarSizedObjects();
00337 }
00338 
00339 // This function eliminate ADJCALLSTACKDOWN, 
00340 // ADJCALLSTACKUP pseudo instructions
00341 void MipsRegisterInfo::
00342 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
00343                               MachineBasicBlock::iterator I) const {
00344   // Simply discard ADJCALLSTACKDOWN, ADJCALLSTACKUP instructions.
00345   MBB.erase(I);
00346 }
00347 
00348 // FrameIndex represent objects inside a abstract stack.
00349 // We must replace FrameIndex with an stack/frame pointer
00350 // direct reference.
00351 void MipsRegisterInfo::
00352 eliminateFrameIndex(MachineBasicBlock::iterator II, int SPAdj, 
00353                     RegScavenger *RS) const 
00354 {
00355   MachineInstr &MI = *II;
00356   MachineFunction &MF = *MI.getParent()->getParent();
00357 
00358   unsigned i = 0;
00359   while (!MI.getOperand(i).isFI()) {
00360     ++i;
00361     assert(i < MI.getNumOperands() && 
00362            "Instr doesn't have FrameIndex operand!");
00363   }
00364 
00365   #ifndef NDEBUG
00366   DEBUG(errs() << "\nFunction : " << MF.getFunction()->getName() << "\n");
00367   DOUT << "<--------->\n";
00368   MI.print(DOUT);
00369   #endif
00370 
00371   int FrameIndex = MI.getOperand(i).getIndex();
00372   int stackSize  = MF.getFrameInfo()->getStackSize();
00373   int spOffset   = MF.getFrameInfo()->getObjectOffset(FrameIndex);
00374 
00375   #ifndef NDEBUG
00376   DOUT << "FrameIndex : " << FrameIndex << "\n";
00377   DOUT << "spOffset   : " << spOffset << "\n";
00378   DOUT << "stackSize  : " << stackSize << "\n";
00379   #endif
00380 
00381   // as explained on LowerFormalArguments, detect negative offsets
00382   // and adjust SPOffsets considering the final stack size.
00383   int Offset = ((spOffset < 0) ? (stackSize + (-(spOffset+4))) : (spOffset));
00384   Offset    += MI.getOperand(i-1).getImm();
00385 
00386   #ifndef NDEBUG
00387   DOUT << "Offset     : " << Offset << "\n";
00388   DOUT << "<--------->\n";
00389   #endif
00390 
00391   MI.getOperand(i-1).ChangeToImmediate(Offset);
00392   MI.getOperand(i).ChangeToRegister(getFrameRegister(MF), false);
00393 }
00394 
00395 void MipsRegisterInfo::
00396 emitPrologue(MachineFunction &MF) const 
00397 {
00398   MachineBasicBlock &MBB   = MF.front();
00399   MachineFrameInfo *MFI    = MF.getFrameInfo();
00400   MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
00401   MachineBasicBlock::iterator MBBI = MBB.begin();
00402   DebugLoc dl = (MBBI != MBB.end() ?
00403                  MBBI->getDebugLoc() : DebugLoc::getUnknownLoc());
00404   bool isPIC = (MF.getTarget().getRelocationModel() == Reloc::PIC_);
00405 
00406   // Get the right frame order for Mips.
00407   adjustMipsStackFrame(MF);
00408 
00409   // Get the number of bytes to allocate from the FrameInfo.
00410   unsigned StackSize = MFI->getStackSize();
00411 
00412   // No need to allocate space on the stack.
00413   if (StackSize == 0 && !MFI->hasCalls()) return;
00414 
00415   int FPOffset = MipsFI->getFPStackOffset();
00416   int RAOffset = MipsFI->getRAStackOffset();
00417 
00418   BuildMI(MBB, MBBI, dl, TII.get(Mips::NOREORDER));
00419   
00420   // TODO: check need from GP here.
00421   if (isPIC && Subtarget.isABI_O32()) 
00422     BuildMI(MBB, MBBI, dl, TII.get(Mips::CPLOAD)).addReg(getPICCallReg());
00423   BuildMI(MBB, MBBI, dl, TII.get(Mips::NOMACRO));
00424 
00425   // Adjust stack : addi sp, sp, (-imm)
00426   BuildMI(MBB, MBBI, dl, TII.get(Mips::ADDiu), Mips::SP)
00427       .addReg(Mips::SP).addImm(-StackSize);
00428 
00429   // Save the return address only if the function isnt a leaf one.
00430   // sw  $ra, stack_loc($sp)
00431   if (MFI->hasCalls()) { 
00432     BuildMI(MBB, MBBI, dl, TII.get(Mips::SW))
00433         .addReg(Mips::RA).addImm(RAOffset).addReg(Mips::SP);
00434   }
00435 
00436   // if framepointer enabled, save it and set it
00437   // to point to the stack pointer
00438   if (hasFP(MF)) {
00439     // sw  $fp,stack_loc($sp)
00440     BuildMI(MBB, MBBI, dl, TII.get(Mips::SW))
00441       .addReg(Mips::FP).addImm(FPOffset).addReg(Mips::SP);
00442 
00443     // move $fp, $sp
00444     BuildMI(MBB, MBBI, dl, TII.get(Mips::ADDu), Mips::FP)
00445       .addReg(Mips::SP).addReg(Mips::ZERO);
00446   }
00447 
00448   // PIC speficic function prologue
00449   if ((isPIC) && (MFI->hasCalls())) {
00450     BuildMI(MBB, MBBI, dl, TII.get(Mips::CPRESTORE))
00451       .addImm(MipsFI->getGPStackOffset());
00452   }
00453 }
00454 
00455 void MipsRegisterInfo::
00456 emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const 
00457 {
00458   MachineBasicBlock::iterator MBBI = prior(MBB.end());
00459   MachineFrameInfo *MFI            = MF.getFrameInfo();
00460   MipsFunctionInfo *MipsFI         = MF.getInfo<MipsFunctionInfo>();
00461   DebugLoc dl = MBBI->getDebugLoc();
00462 
00463   // Get the number of bytes from FrameInfo
00464   int NumBytes = (int) MFI->getStackSize();
00465 
00466   // Get the FI's where RA and FP are saved.
00467   int FPOffset = MipsFI->getFPStackOffset();
00468   int RAOffset = MipsFI->getRAStackOffset();
00469 
00470   // if framepointer enabled, restore it and restore the
00471   // stack pointer
00472   if (hasFP(MF)) {
00473     // move $sp, $fp
00474     BuildMI(MBB, MBBI, dl, TII.get(Mips::ADDu), Mips::SP)
00475       .addReg(Mips::FP).addReg(Mips::ZERO);
00476 
00477     // lw  $fp,stack_loc($sp)
00478     BuildMI(MBB, MBBI, dl, TII.get(Mips::LW), Mips::FP)
00479       .addImm(FPOffset).addReg(Mips::SP);
00480   }
00481 
00482   // Restore the return address only if the function isnt a leaf one.
00483   // lw  $ra, stack_loc($sp)
00484   if (MFI->hasCalls()) { 
00485     BuildMI(MBB, MBBI, dl, TII.get(Mips::LW), Mips::RA)
00486       .addImm(RAOffset).addReg(Mips::SP);
00487   }
00488 
00489   // adjust stack  : insert addi sp, sp, (imm)
00490   if (NumBytes) {
00491     BuildMI(MBB, MBBI, dl, TII.get(Mips::ADDiu), Mips::SP)
00492       .addReg(Mips::SP).addImm(NumBytes);
00493   }
00494 }
00495 
00496 
00497 void MipsRegisterInfo::
00498 processFunctionBeforeFrameFinalized(MachineFunction &MF) const {
00499   // Set the SPOffset on the FI where GP must be saved/loaded.
00500   MachineFrameInfo *MFI = MF.getFrameInfo();
00501   bool isPIC = (MF.getTarget().getRelocationModel() == Reloc::PIC_);
00502   if (MFI->hasCalls() && isPIC) { 
00503     MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
00504     MFI->setObjectOffset(MipsFI->getGPFI(), MipsFI->getGPStackOffset());
00505   }    
00506 }
00507 
00508 unsigned MipsRegisterInfo::
00509 getRARegister() const {
00510   return Mips::RA;
00511 }
00512 
00513 unsigned MipsRegisterInfo::
00514 getFrameRegister(MachineFunction &MF) const {
00515   return hasFP(MF) ? Mips::FP : Mips::SP;
00516 }
00517 
00518 unsigned MipsRegisterInfo::
00519 getEHExceptionRegister() const {
00520   llvm_unreachable("What is the exception register");
00521   return 0;
00522 }
00523 
00524 unsigned MipsRegisterInfo::
00525 getEHHandlerRegister() const {
00526   llvm_unreachable("What is the exception handler register");
00527   return 0;
00528 }
00529 
00530 int MipsRegisterInfo::
00531 getDwarfRegNum(unsigned RegNum, bool isEH) const {
00532   llvm_unreachable("What is the dwarf register number");
00533   return -1;
00534 }
00535 
00536 #include "MipsGenRegisterInfo.inc"
00537