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) : PseudoSourceValue(MipsPSV) { 29 #ifndef NDEBUG 30 Name = N; 31 Val = nullptr; 32 #endif 33 } 34 35 MipsCallEntry::MipsCallEntry(const GlobalValue *V) 36 : PseudoSourceValue(MipsPSV) { 37 #ifndef NDEBUG 38 Val = V; 39 #endif 40 } 41 42 bool MipsCallEntry::isConstant(const MachineFrameInfo *) const { 43 return false; 44 } 45 46 bool MipsCallEntry::isAliased(const MachineFrameInfo *) const { 47 return false; 48 } 49 50 bool MipsCallEntry::mayAlias(const MachineFrameInfo *) const { 51 return false; 52 } 53 54 void MipsCallEntry::printCustom(raw_ostream &O) const { 55 O << "MipsCallEntry: "; 56 #ifndef NDEBUG 57 if (Val) 58 O << Val->getName(); 59 else 60 O << Name; 61 #endif 62 } 63 64 MipsFunctionInfo::~MipsFunctionInfo() {} 65 66 bool MipsFunctionInfo::globalBaseRegSet() const { 67 return GlobalBaseReg; 68 } 69 70 unsigned MipsFunctionInfo::getGlobalBaseReg() { 71 // Return if it has already been initialized. 72 if (GlobalBaseReg) 73 return GlobalBaseReg; 74 75 MipsSubtarget const &STI = 76 static_cast<const MipsSubtarget &>(MF.getSubtarget()); 77 78 const TargetRegisterClass *RC = 79 STI.inMips16Mode() 80 ? &Mips::CPU16RegsRegClass 81 : STI.inMicroMipsMode() 82 ? &Mips::GPRMM16RegClass 83 : static_cast<const MipsTargetMachine &>(MF.getTarget()) 84 .getABI() 85 .IsN64() 86 ? &Mips::GPR64RegClass 87 : &Mips::GPR32RegClass; 88 return GlobalBaseReg = MF.getRegInfo().createVirtualRegister(RC); 89 } 90 91 bool MipsFunctionInfo::mips16SPAliasRegSet() const { 92 return Mips16SPAliasReg; 93 } 94 unsigned MipsFunctionInfo::getMips16SPAliasReg() { 95 // Return if it has already been initialized. 96 if (Mips16SPAliasReg) 97 return Mips16SPAliasReg; 98 99 const TargetRegisterClass *RC = &Mips::CPU16RegsRegClass; 100 return Mips16SPAliasReg = MF.getRegInfo().createVirtualRegister(RC); 101 } 102 103 void MipsFunctionInfo::createEhDataRegsFI() { 104 for (int I = 0; I < 4; ++I) { 105 const TargetRegisterClass *RC = 106 static_cast<const MipsTargetMachine &>(MF.getTarget()).getABI().IsN64() 107 ? &Mips::GPR64RegClass 108 : &Mips::GPR32RegClass; 109 110 EhDataRegFI[I] = MF.getFrameInfo()->CreateStackObject(RC->getSize(), 111 RC->getAlignment(), false); 112 } 113 } 114 115 bool MipsFunctionInfo::isEhDataRegFI(int FI) const { 116 return CallsEhReturn && (FI == EhDataRegFI[0] || FI == EhDataRegFI[1] 117 || FI == EhDataRegFI[2] || FI == EhDataRegFI[3]); 118 } 119 120 MachinePointerInfo MipsFunctionInfo::callPtrInfo(StringRef Name) { 121 std::unique_ptr<const MipsCallEntry> &E = ExternalCallEntries[Name]; 122 123 if (!E) 124 E = llvm::make_unique<MipsCallEntry>(Name); 125 126 return MachinePointerInfo(E.get()); 127 } 128 129 MachinePointerInfo MipsFunctionInfo::callPtrInfo(const GlobalValue *Val) { 130 std::unique_ptr<const MipsCallEntry> &E = GlobalCallEntries[Val]; 131 132 if (!E) 133 E = llvm::make_unique<MipsCallEntry>(Val); 134 135 return MachinePointerInfo(E.get()); 136 } 137 138 int MipsFunctionInfo::getMoveF64ViaSpillFI(const TargetRegisterClass *RC) { 139 if (MoveF64ViaSpillFI == -1) { 140 MoveF64ViaSpillFI = MF.getFrameInfo()->CreateStackObject( 141 RC->getSize(), RC->getAlignment(), false); 142 } 143 return MoveF64ViaSpillFI; 144 } 145 146 void MipsFunctionInfo::anchor() { } 147