diff options
| author | Akira Hatanaka <ahatanaka@mips.com> | 2013-09-27 22:30:36 +0000 |
|---|---|---|
| committer | Akira Hatanaka <ahatanaka@mips.com> | 2013-09-27 22:30:36 +0000 |
| commit | 479a778590483bb3e2ca48537ed9eb7b15270ad6 (patch) | |
| tree | ad1ff6f862b2236532db43da30038a961e2d6c14 /lib | |
| parent | b99f6e14af3752c356b6acc887e1a3dcd961e19f (diff) | |
| download | external_llvm-479a778590483bb3e2ca48537ed9eb7b15270ad6.zip external_llvm-479a778590483bb3e2ca48537ed9eb7b15270ad6.tar.gz external_llvm-479a778590483bb3e2ca48537ed9eb7b15270ad6.tar.bz2 | |
[mips] Define a derived class of PseudoSourceValue that represents a GOT entry
resolved by lazy-binding.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191578 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Target/Mips/MipsMachineFunction.cpp | 69 | ||||
| -rw-r--r-- | lib/Target/Mips/MipsMachineFunction.h | 37 |
2 files changed, 106 insertions, 0 deletions
diff --git a/lib/Target/Mips/MipsMachineFunction.cpp b/lib/Target/Mips/MipsMachineFunction.cpp index a7299d7..c32f56c 100644 --- a/lib/Target/Mips/MipsMachineFunction.cpp +++ b/lib/Target/Mips/MipsMachineFunction.cpp @@ -22,6 +22,53 @@ static cl::opt<bool> FixGlobalBaseReg("mips-fix-global-base-reg", cl::Hidden, cl::init(true), cl::desc("Always use $gp as the global base register.")); +// class MipsCallEntry. +MipsCallEntry::MipsCallEntry(const StringRef &N) { +#ifndef NDEBUG + Name = N; + Val = 0; +#endif +} + +MipsCallEntry::MipsCallEntry(const GlobalValue *V) { +#ifndef NDEBUG + Val = V; +#endif +} + +bool MipsCallEntry::isConstant(const MachineFrameInfo *) const { + return false; +} + +bool MipsCallEntry::isAliased(const MachineFrameInfo *) const { + return false; +} + +bool MipsCallEntry::mayAlias(const MachineFrameInfo *) const { + return false; +} + +void MipsCallEntry::printCustom(raw_ostream &O) const { + O << "MipsCallEntry: "; +#ifndef NDEBUG + if (Val) + O << Val->getName(); + else + O << Name; +#endif +} + +MipsFunctionInfo::~MipsFunctionInfo() { + for (StringMap<const MipsCallEntry *>::iterator + I = ExternalCallEntries.begin(), E = ExternalCallEntries.end(); I != E; + ++I) + delete I->getValue(); + + for (ValueMap<const GlobalValue *, const MipsCallEntry *>::iterator + I = GlobalCallEntries.begin(), E = GlobalCallEntries.end(); I != E; ++I) + delete I->second; +} + bool MipsFunctionInfo::globalBaseRegSet() const { return GlobalBaseReg; } @@ -72,4 +119,26 @@ bool MipsFunctionInfo::isEhDataRegFI(int FI) const { || FI == EhDataRegFI[2] || FI == EhDataRegFI[3]); } +MachinePointerInfo MipsFunctionInfo::callPtrInfo(const StringRef &Name) { + StringMap<const MipsCallEntry *>::const_iterator I; + I = ExternalCallEntries.find(Name); + + if (I != ExternalCallEntries.end()) + return MachinePointerInfo(I->getValue()); + + const MipsCallEntry *E = ExternalCallEntries[Name] = new MipsCallEntry(Name); + return MachinePointerInfo(E); +} + +MachinePointerInfo MipsFunctionInfo::callPtrInfo(const GlobalValue *Val) { + ValueMap<const GlobalValue *, const MipsCallEntry *>::const_iterator I; + I = GlobalCallEntries.find(Val); + + if (I != GlobalCallEntries.end()) + return MachinePointerInfo(I->second); + + const MipsCallEntry *E = GlobalCallEntries[Val] = new MipsCallEntry(Val); + return MachinePointerInfo(E); +} + void MipsFunctionInfo::anchor() { } diff --git a/lib/Target/Mips/MipsMachineFunction.h b/lib/Target/Mips/MipsMachineFunction.h index 36c2e59..43bf682 100644 --- a/lib/Target/Mips/MipsMachineFunction.h +++ b/lib/Target/Mips/MipsMachineFunction.h @@ -15,14 +15,37 @@ #define MIPS_MACHINE_FUNCTION_INFO_H #include "MipsSubtarget.h" +#include "llvm/ADT/StringMap.h" +#include "llvm/ADT/ValueMap.h" #include "llvm/CodeGen/MachineFrameInfo.h" #include "llvm/CodeGen/MachineFunction.h" +#include "llvm/CodeGen/MachineMemOperand.h" +#include "llvm/CodeGen/PseudoSourceValue.h" +#include "llvm/IR/GlobalValue.h" #include "llvm/Target/TargetFrameLowering.h" #include "llvm/Target/TargetMachine.h" #include <utility> namespace llvm { +/// \brief A class derived from PseudoSourceValue that represents a GOT entry +/// resolved by lazy-binding. +class MipsCallEntry : public PseudoSourceValue { +public: + explicit MipsCallEntry(const StringRef &N); + explicit MipsCallEntry(const GlobalValue *V); + virtual bool isConstant(const MachineFrameInfo *) const; + virtual bool isAliased(const MachineFrameInfo *) const; + virtual bool mayAlias(const MachineFrameInfo *) const; + +private: + virtual void printCustom(raw_ostream &O) const; +#ifndef NDEBUG + std::string Name; + const GlobalValue *Val; +#endif +}; + /// MipsFunctionInfo - This class is derived from MachineFunction private /// Mips target-specific information for each MachineFunction. class MipsFunctionInfo : public MachineFunctionInfo { @@ -32,6 +55,8 @@ public: VarArgsFrameIndex(0), CallsEhReturn(false) {} + ~MipsFunctionInfo(); + unsigned getSRetReturnReg() const { return SRetReturnReg; } void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; } @@ -59,6 +84,14 @@ public: int getEhDataRegFI(unsigned Reg) const { return EhDataRegFI[Reg]; } bool isEhDataRegFI(int FI) const; + /// \brief Create a MachinePointerInfo that has a MipsCallEntr object + /// representing a GOT entry for an external function. + MachinePointerInfo callPtrInfo(const StringRef &Name); + + /// \brief Create a MachinePointerInfo that has a MipsCallEntr object + /// representing a GOT entry for a global function. + MachinePointerInfo callPtrInfo(const GlobalValue *Val); + private: virtual void anchor(); @@ -92,6 +125,10 @@ private: /// Frame objects for spilling eh data registers. int EhDataRegFI[4]; + + /// MipsCallEntry maps. + StringMap<const MipsCallEntry *> ExternalCallEntries; + ValueMap<const GlobalValue *, const MipsCallEntry *> GlobalCallEntries; }; } // end of namespace llvm |
