LLVM API Documentation
00001 //===-- MipsMachineFunctionInfo.cpp - Private data used for Mips ----------===// 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 #include "MipsMachineFunction.h" 00011 #include "MCTargetDesc/MipsBaseInfo.h" 00012 #include "MipsInstrInfo.h" 00013 #include "MipsSubtarget.h" 00014 #include "llvm/CodeGen/MachineInstrBuilder.h" 00015 #include "llvm/CodeGen/MachineRegisterInfo.h" 00016 #include "llvm/IR/Function.h" 00017 #include "llvm/Support/CommandLine.h" 00018 #include "llvm/Support/raw_ostream.h" 00019 00020 using namespace llvm; 00021 00022 static cl::opt<bool> 00023 FixGlobalBaseReg("mips-fix-global-base-reg", cl::Hidden, cl::init(true), 00024 cl::desc("Always use $gp as the global base register.")); 00025 00026 // class MipsCallEntry. 00027 MipsCallEntry::MipsCallEntry(StringRef N) { 00028 #ifndef NDEBUG 00029 Name = N; 00030 Val = nullptr; 00031 #endif 00032 } 00033 00034 MipsCallEntry::MipsCallEntry(const GlobalValue *V) { 00035 #ifndef NDEBUG 00036 Val = V; 00037 #endif 00038 } 00039 00040 bool MipsCallEntry::isConstant(const MachineFrameInfo *) const { 00041 return false; 00042 } 00043 00044 bool MipsCallEntry::isAliased(const MachineFrameInfo *) const { 00045 return false; 00046 } 00047 00048 bool MipsCallEntry::mayAlias(const MachineFrameInfo *) const { 00049 return false; 00050 } 00051 00052 void MipsCallEntry::printCustom(raw_ostream &O) const { 00053 O << "MipsCallEntry: "; 00054 #ifndef NDEBUG 00055 if (Val) 00056 O << Val->getName(); 00057 else 00058 O << Name; 00059 #endif 00060 } 00061 00062 MipsFunctionInfo::~MipsFunctionInfo() { 00063 for (StringMap<const MipsCallEntry *>::iterator 00064 I = ExternalCallEntries.begin(), E = ExternalCallEntries.end(); I != E; 00065 ++I) 00066 delete I->getValue(); 00067 00068 for (const auto &Entry : GlobalCallEntries) 00069 delete Entry.second; 00070 } 00071 00072 bool MipsFunctionInfo::globalBaseRegSet() const { 00073 return GlobalBaseReg; 00074 } 00075 00076 unsigned MipsFunctionInfo::getGlobalBaseReg() { 00077 // Return if it has already been initialized. 00078 if (GlobalBaseReg) 00079 return GlobalBaseReg; 00080 00081 const MipsSubtarget &ST = MF.getTarget().getSubtarget<MipsSubtarget>(); 00082 00083 const TargetRegisterClass *RC; 00084 if (ST.inMips16Mode()) 00085 RC=(const TargetRegisterClass*)&Mips::CPU16RegsRegClass; 00086 else 00087 RC = ST.isABI_N64() ? 00088 (const TargetRegisterClass*)&Mips::GPR64RegClass : 00089 (const TargetRegisterClass*)&Mips::GPR32RegClass; 00090 return GlobalBaseReg = MF.getRegInfo().createVirtualRegister(RC); 00091 } 00092 00093 bool MipsFunctionInfo::mips16SPAliasRegSet() const { 00094 return Mips16SPAliasReg; 00095 } 00096 unsigned MipsFunctionInfo::getMips16SPAliasReg() { 00097 // Return if it has already been initialized. 00098 if (Mips16SPAliasReg) 00099 return Mips16SPAliasReg; 00100 00101 const TargetRegisterClass *RC; 00102 RC=(const TargetRegisterClass*)&Mips::CPU16RegsRegClass; 00103 return Mips16SPAliasReg = MF.getRegInfo().createVirtualRegister(RC); 00104 } 00105 00106 void MipsFunctionInfo::createEhDataRegsFI() { 00107 for (int I = 0; I < 4; ++I) { 00108 const MipsSubtarget &ST = MF.getTarget().getSubtarget<MipsSubtarget>(); 00109 const TargetRegisterClass *RC = ST.isABI_N64() ? 00110 &Mips::GPR64RegClass : &Mips::GPR32RegClass; 00111 00112 EhDataRegFI[I] = MF.getFrameInfo()->CreateStackObject(RC->getSize(), 00113 RC->getAlignment(), false); 00114 } 00115 } 00116 00117 bool MipsFunctionInfo::isEhDataRegFI(int FI) const { 00118 return CallsEhReturn && (FI == EhDataRegFI[0] || FI == EhDataRegFI[1] 00119 || FI == EhDataRegFI[2] || FI == EhDataRegFI[3]); 00120 } 00121 00122 MachinePointerInfo MipsFunctionInfo::callPtrInfo(StringRef Name) { 00123 const MipsCallEntry *&E = ExternalCallEntries[Name]; 00124 00125 if (!E) 00126 E = new MipsCallEntry(Name); 00127 00128 return MachinePointerInfo(E); 00129 } 00130 00131 MachinePointerInfo MipsFunctionInfo::callPtrInfo(const GlobalValue *Val) { 00132 const MipsCallEntry *&E = GlobalCallEntries[Val]; 00133 00134 if (!E) 00135 E = new MipsCallEntry(Val); 00136 00137 return MachinePointerInfo(E); 00138 } 00139 00140 int MipsFunctionInfo::getMoveF64ViaSpillFI(const TargetRegisterClass *RC) { 00141 if (MoveF64ViaSpillFI == -1) { 00142 MoveF64ViaSpillFI = MF.getFrameInfo()->CreateStackObject( 00143 RC->getSize(), RC->getAlignment(), false); 00144 } 00145 return MoveF64ViaSpillFI; 00146 } 00147 00148 void MipsFunctionInfo::anchor() { }