1 //===-- MipsMachineFunctionInfo.cpp - Private data used for Mips ----------===// 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 #include "MipsMachineFunction.h" 11 #include "MCTargetDesc/MipsBaseInfo.h" 12 #include "MipsInstrInfo.h" 13 #include "MipsSubtarget.h" 14 #include "llvm/CodeGen/MachineInstrBuilder.h" 15 #include "llvm/CodeGen/MachineRegisterInfo.h" 16 #include "llvm/IR/Function.h" 17 #include "llvm/Support/CommandLine.h" 18 #include "llvm/Support/raw_ostream.h" 19 20 using namespace llvm; 21 22 static cl::opt<bool> 23 FixGlobalBaseReg("mips-fix-global-base-reg", cl::Hidden, cl::init(true), 24 cl::desc("Always use $gp as the global base register.")); 25 26 // class MipsCallEntry. MipsCallEntry(StringRef N)27MipsCallEntry::MipsCallEntry(StringRef N) { 28 #ifndef NDEBUG 29 Name = N; 30 Val = nullptr; 31 #endif 32 } 33 MipsCallEntry(const GlobalValue * V)34MipsCallEntry::MipsCallEntry(const GlobalValue *V) { 35 #ifndef NDEBUG 36 Val = V; 37 #endif 38 } 39 isConstant(const MachineFrameInfo *) const40bool MipsCallEntry::isConstant(const MachineFrameInfo *) const { 41 return false; 42 } 43 isAliased(const MachineFrameInfo *) const44bool MipsCallEntry::isAliased(const MachineFrameInfo *) const { 45 return false; 46 } 47 mayAlias(const MachineFrameInfo *) const48bool MipsCallEntry::mayAlias(const MachineFrameInfo *) const { 49 return false; 50 } 51 printCustom(raw_ostream & O) const52void MipsCallEntry::printCustom(raw_ostream &O) const { 53 O << "MipsCallEntry: "; 54 #ifndef NDEBUG 55 if (Val) 56 O << Val->getName(); 57 else 58 O << Name; 59 #endif 60 } 61 ~MipsFunctionInfo()62MipsFunctionInfo::~MipsFunctionInfo() { 63 for (StringMap<const MipsCallEntry *>::iterator 64 I = ExternalCallEntries.begin(), E = ExternalCallEntries.end(); I != E; 65 ++I) 66 delete I->getValue(); 67 68 for (const auto &Entry : GlobalCallEntries) 69 delete Entry.second; 70 } 71 globalBaseRegSet() const72bool MipsFunctionInfo::globalBaseRegSet() const { 73 return GlobalBaseReg; 74 } 75 getGlobalBaseReg()76unsigned MipsFunctionInfo::getGlobalBaseReg() { 77 // Return if it has already been initialized. 78 if (GlobalBaseReg) 79 return GlobalBaseReg; 80 81 const MipsSubtarget &ST = MF.getTarget().getSubtarget<MipsSubtarget>(); 82 83 const TargetRegisterClass *RC = 84 ST.inMips16Mode() ? &Mips::CPU16RegsRegClass 85 : ST.isABI_N64() ? &Mips::GPR64RegClass 86 : &Mips::GPR32RegClass; 87 return GlobalBaseReg = MF.getRegInfo().createVirtualRegister(RC); 88 } 89 mips16SPAliasRegSet() const90bool MipsFunctionInfo::mips16SPAliasRegSet() const { 91 return Mips16SPAliasReg; 92 } getMips16SPAliasReg()93unsigned MipsFunctionInfo::getMips16SPAliasReg() { 94 // Return if it has already been initialized. 95 if (Mips16SPAliasReg) 96 return Mips16SPAliasReg; 97 98 const TargetRegisterClass *RC = &Mips::CPU16RegsRegClass; 99 return Mips16SPAliasReg = MF.getRegInfo().createVirtualRegister(RC); 100 } 101 createEhDataRegsFI()102void MipsFunctionInfo::createEhDataRegsFI() { 103 for (int I = 0; I < 4; ++I) { 104 const MipsSubtarget &ST = MF.getTarget().getSubtarget<MipsSubtarget>(); 105 const TargetRegisterClass *RC = ST.isABI_N64() ? 106 &Mips::GPR64RegClass : &Mips::GPR32RegClass; 107 108 EhDataRegFI[I] = MF.getFrameInfo()->CreateStackObject(RC->getSize(), 109 RC->getAlignment(), false); 110 } 111 } 112 isEhDataRegFI(int FI) const113bool MipsFunctionInfo::isEhDataRegFI(int FI) const { 114 return CallsEhReturn && (FI == EhDataRegFI[0] || FI == EhDataRegFI[1] 115 || FI == EhDataRegFI[2] || FI == EhDataRegFI[3]); 116 } 117 callPtrInfo(StringRef Name)118MachinePointerInfo MipsFunctionInfo::callPtrInfo(StringRef Name) { 119 const MipsCallEntry *&E = ExternalCallEntries[Name]; 120 121 if (!E) 122 E = new MipsCallEntry(Name); 123 124 return MachinePointerInfo(E); 125 } 126 callPtrInfo(const GlobalValue * Val)127MachinePointerInfo MipsFunctionInfo::callPtrInfo(const GlobalValue *Val) { 128 const MipsCallEntry *&E = GlobalCallEntries[Val]; 129 130 if (!E) 131 E = new MipsCallEntry(Val); 132 133 return MachinePointerInfo(E); 134 } 135 getMoveF64ViaSpillFI(const TargetRegisterClass * RC)136int MipsFunctionInfo::getMoveF64ViaSpillFI(const TargetRegisterClass *RC) { 137 if (MoveF64ViaSpillFI == -1) { 138 MoveF64ViaSpillFI = MF.getFrameInfo()->CreateStackObject( 139 RC->getSize(), RC->getAlignment(), false); 140 } 141 return MoveF64ViaSpillFI; 142 } 143 anchor()144void MipsFunctionInfo::anchor() { } 145