From 264b1a34445efe12411a8c5256216e9686d1d7e2 Mon Sep 17 00:00:00 2001 From: Quentin Colombet Date: Mon, 7 Mar 2016 21:22:09 +0000 Subject: [PATCH] [MachineRegisterInfo] Get rid of the global-isel ifdefs. One additional pointer is not a big deal size-wise and it makes the code much nicer! llvm-svn: 262856 --- include/llvm/CodeGen/MachineRegisterInfo.h | 15 ++++++++++----- lib/CodeGen/MachineRegisterInfo.cpp | 9 +++------ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/include/llvm/CodeGen/MachineRegisterInfo.h b/include/llvm/CodeGen/MachineRegisterInfo.h index 65fb1be8c83..ab29c4849ef 100644 --- a/include/llvm/CodeGen/MachineRegisterInfo.h +++ b/include/llvm/CodeGen/MachineRegisterInfo.h @@ -105,10 +105,17 @@ private: /// started. BitVector ReservedRegs; -#ifdef LLVM_BUILD_GLOBAL_ISEL + typedef DenseMap VRegToSizeMap; /// Map generic virtual registers to their actual size. - DenseMap VRegToSize; -#endif + mutable std::unique_ptr VRegToSize; + + /// Accessor for VRegToSize. This accessor should only be used + /// by global-isel related work. + VRegToSizeMap &getVRegToSize() const { + if (!VRegToSize) + VRegToSize.reset(new VRegToSizeMap); + return *VRegToSize.get(); + } /// Keep track of the physical registers that are live in to the function. /// Live in values are typically arguments in registers. LiveIn values are @@ -592,7 +599,6 @@ public: /// unsigned createVirtualRegister(const TargetRegisterClass *RegClass); -#ifdef LLVM_BUILD_GLOBAL_ISEL /// Get the size of \p VReg or 0 if VReg is not a generic /// (target independent) virtual register. unsigned getSize(unsigned VReg) const; @@ -600,7 +606,6 @@ public: /// Create and return a new generic virtual register with a size of \p Size. /// \pre Size > 0. unsigned createGenericVirtualRegister(unsigned Size); -#endif /// getNumVirtRegs - Return the number of virtual registers created. /// diff --git a/lib/CodeGen/MachineRegisterInfo.cpp b/lib/CodeGen/MachineRegisterInfo.cpp index 313c259a547..2b81f6b2015 100644 --- a/lib/CodeGen/MachineRegisterInfo.cpp +++ b/lib/CodeGen/MachineRegisterInfo.cpp @@ -103,12 +103,10 @@ MachineRegisterInfo::createVirtualRegister(const TargetRegisterClass *RegClass){ return Reg; } -#ifdef LLVM_BUILD_GLOBAL_ISEL unsigned MachineRegisterInfo::getSize(unsigned VReg) const { - DenseMap::const_iterator SizeIt = - VRegToSize.find(VReg); - return SizeIt != VRegToSize.end()? SizeIt->second: 0; + VRegToSizeMap::const_iterator SizeIt = getVRegToSize().find(VReg); + return SizeIt != getVRegToSize().end() ? SizeIt->second : 0; } unsigned @@ -120,13 +118,12 @@ MachineRegisterInfo::createGenericVirtualRegister(unsigned Size) { VRegInfo.grow(Reg); // FIXME: Should we use a dummy register class? VRegInfo[Reg].first = nullptr; - VRegToSize[Reg] = Size; + getVRegToSize()[Reg] = Size; RegAllocHints.grow(Reg); if (TheDelegate) TheDelegate->MRI_NoteNewVirtualRegister(Reg); return Reg; } -#endif // LLVM_BUILD_GLOBAL_ISEL /// clearVirtRegs - Remove all virtual registers (after physreg assignment). void MachineRegisterInfo::clearVirtRegs() {