LLVM API Documentation
00001 //===-- Mips16RegisterInfo.cpp - MIPS16 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 MIPS16 implementation of the TargetRegisterInfo class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "Mips16RegisterInfo.h" 00015 #include "Mips.h" 00016 #include "Mips16InstrInfo.h" 00017 #include "MipsAnalyzeImmediate.h" 00018 #include "MipsInstrInfo.h" 00019 #include "MipsMachineFunction.h" 00020 #include "MipsSubtarget.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/MachineRegisterInfo.h" 00027 #include "llvm/IR/Constants.h" 00028 #include "llvm/IR/DebugInfo.h" 00029 #include "llvm/IR/Function.h" 00030 #include "llvm/IR/Type.h" 00031 #include "llvm/Support/CommandLine.h" 00032 #include "llvm/Support/Debug.h" 00033 #include "llvm/Support/ErrorHandling.h" 00034 #include "llvm/Support/raw_ostream.h" 00035 #include "llvm/Target/TargetFrameLowering.h" 00036 #include "llvm/Target/TargetInstrInfo.h" 00037 #include "llvm/Target/TargetMachine.h" 00038 #include "llvm/Target/TargetOptions.h" 00039 00040 using namespace llvm; 00041 00042 #define DEBUG_TYPE "mips16-registerinfo" 00043 00044 Mips16RegisterInfo::Mips16RegisterInfo(const MipsSubtarget &ST) 00045 : MipsRegisterInfo(ST) {} 00046 00047 bool Mips16RegisterInfo::requiresRegisterScavenging 00048 (const MachineFunction &MF) const { 00049 return false; 00050 } 00051 bool Mips16RegisterInfo::requiresFrameIndexScavenging 00052 (const MachineFunction &MF) const { 00053 return false; 00054 } 00055 00056 bool Mips16RegisterInfo::useFPForScavengingIndex 00057 (const MachineFunction &MF) const { 00058 return false; 00059 } 00060 00061 bool Mips16RegisterInfo::saveScavengerRegister 00062 (MachineBasicBlock &MBB, 00063 MachineBasicBlock::iterator I, 00064 MachineBasicBlock::iterator &UseMI, 00065 const TargetRegisterClass *RC, 00066 unsigned Reg) const { 00067 DebugLoc DL; 00068 const TargetInstrInfo &TII = *MBB.getParent()->getSubtarget().getInstrInfo(); 00069 TII.copyPhysReg(MBB, I, DL, Mips::T0, Reg, true); 00070 TII.copyPhysReg(MBB, UseMI, DL, Reg, Mips::T0, true); 00071 return true; 00072 } 00073 00074 const TargetRegisterClass * 00075 Mips16RegisterInfo::intRegClass(unsigned Size) const { 00076 assert(Size == 4); 00077 return &Mips::CPU16RegsRegClass; 00078 } 00079 00080 void Mips16RegisterInfo::eliminateFI(MachineBasicBlock::iterator II, 00081 unsigned OpNo, int FrameIndex, 00082 uint64_t StackSize, 00083 int64_t SPOffset) const { 00084 MachineInstr &MI = *II; 00085 MachineFunction &MF = *MI.getParent()->getParent(); 00086 MachineFrameInfo *MFI = MF.getFrameInfo(); 00087 00088 const std::vector<CalleeSavedInfo> &CSI = MFI->getCalleeSavedInfo(); 00089 int MinCSFI = 0; 00090 int MaxCSFI = -1; 00091 00092 if (CSI.size()) { 00093 MinCSFI = CSI[0].getFrameIdx(); 00094 MaxCSFI = CSI[CSI.size() - 1].getFrameIdx(); 00095 } 00096 00097 // The following stack frame objects are always 00098 // referenced relative to $sp: 00099 // 1. Outgoing arguments. 00100 // 2. Pointer to dynamically allocated stack space. 00101 // 3. Locations for callee-saved registers. 00102 // Everything else is referenced relative to whatever register 00103 // getFrameRegister() returns. 00104 unsigned FrameReg; 00105 00106 if (FrameIndex >= MinCSFI && FrameIndex <= MaxCSFI) 00107 FrameReg = Mips::SP; 00108 else { 00109 const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering(); 00110 if (TFI->hasFP(MF)) { 00111 FrameReg = Mips::S0; 00112 } 00113 else { 00114 if ((MI.getNumOperands()> OpNo+2) && MI.getOperand(OpNo+2).isReg()) 00115 FrameReg = MI.getOperand(OpNo+2).getReg(); 00116 else 00117 FrameReg = Mips::SP; 00118 } 00119 } 00120 // Calculate final offset. 00121 // - There is no need to change the offset if the frame object 00122 // is one of the 00123 // following: an outgoing argument, pointer to a dynamically allocated 00124 // stack space or a $gp restore location, 00125 // - If the frame object is any of the following, 00126 // its offset must be adjusted 00127 // by adding the size of the stack: 00128 // incoming argument, callee-saved register location or local variable. 00129 int64_t Offset; 00130 bool IsKill = false; 00131 Offset = SPOffset + (int64_t)StackSize; 00132 Offset += MI.getOperand(OpNo + 1).getImm(); 00133 00134 00135 DEBUG(errs() << "Offset : " << Offset << "\n" << "<--------->\n"); 00136 00137 if (!MI.isDebugValue() && 00138 !Mips16InstrInfo::validImmediate(MI.getOpcode(), FrameReg, Offset)) { 00139 MachineBasicBlock &MBB = *MI.getParent(); 00140 DebugLoc DL = II->getDebugLoc(); 00141 unsigned NewImm; 00142 const Mips16InstrInfo &TII = 00143 *static_cast<const Mips16InstrInfo *>( 00144 MBB.getParent()->getSubtarget().getInstrInfo()); 00145 FrameReg = TII.loadImmediate(FrameReg, Offset, MBB, II, DL, NewImm); 00146 Offset = SignExtend64<16>(NewImm); 00147 IsKill = true; 00148 } 00149 MI.getOperand(OpNo).ChangeToRegister(FrameReg, false, false, IsKill); 00150 MI.getOperand(OpNo + 1).ChangeToImmediate(Offset); 00151 00152 00153 }