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