From: Quentin Colombet Date: Sat, 24 Sep 2016 04:53:48 +0000 (+0000) Subject: [RegisterBankInfo] Keep valid pointers for PartialMappings. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=245edb6c141a7d052e3f77bf64ee0516f15be3f6;p=llvm [RegisterBankInfo] Keep valid pointers for PartialMappings. Previously we were using the address of the unique instance of a partial mapping in the related map to access this instance. However, when the map grows, the whole set of instances may be moved elsewhere and the previous addresses are not valid anymore. Instead, keep the address of the unique heap allocated instance of a partial mapping. Note: I did not see any actual bugs for that problem as the number of partial mappings dynamically allocated is small (<= 4). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282323 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h b/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h index 761f50f2190..dd9572e60c8 100644 --- a/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h +++ b/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h @@ -298,7 +298,7 @@ protected: /// Keep dynamically allocated PartialMapping in a separate map. /// This shouldn't be needed when everything gets TableGen'ed. - mutable DenseMap MapOfPartialMappings; + mutable DenseMap MapOfPartialMappings; /// Create a RegisterBankInfo that can accomodate up to \p NumRegBanks /// RegisterBank instances. @@ -401,7 +401,7 @@ protected: } public: - virtual ~RegisterBankInfo() {} + virtual ~RegisterBankInfo(); /// Get the register bank identified by \p ID. const RegisterBank &getRegBank(unsigned ID) const { diff --git a/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp b/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp index b52e0985398..172067233a1 100644 --- a/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp +++ b/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp @@ -54,6 +54,11 @@ RegisterBankInfo::RegisterBankInfo(RegisterBank **RegBanks, }); } +RegisterBankInfo::~RegisterBankInfo() { + for (auto It : MapOfPartialMappings) + delete It.second; +} + bool RegisterBankInfo::verify(const TargetRegisterInfo &TRI) const { DEBUG(for (unsigned Idx = 0, End = getNumRegBanks(); Idx != End; ++Idx) { const RegisterBank &RegBank = getRegBank(Idx); @@ -320,13 +325,13 @@ RegisterBankInfo::getPartialMapping(unsigned StartIdx, unsigned Length, hash_code Hash = hash_combine(StartIdx, Length, RegBank.getID()); const auto &It = MapOfPartialMappings.find(Hash); if (It != MapOfPartialMappings.end()) - return It->second; + return *It->second; ++NumPartialMappingsCreated; - PartialMapping &PartMapping = MapOfPartialMappings[Hash]; - PartMapping = PartialMapping{StartIdx, Length, RegBank}; - return PartMapping; + PartialMapping *&PartMapping = MapOfPartialMappings[Hash]; + PartMapping = new PartialMapping{StartIdx, Length, RegBank}; + return *PartMapping; } RegisterBankInfo::InstructionMapping