[llvm] r282323 - [RegisterBankInfo] Keep valid pointers for PartialMappings.

Quentin Colombet via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 23 21:53:48 PDT 2016


Author: qcolombet
Date: Fri Sep 23 23:53:48 2016
New Revision: 282323

URL: http://llvm.org/viewvc/llvm-project?rev=282323&view=rev
Log:
[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).

Modified:
    llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h
    llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp

Modified: llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h?rev=282323&r1=282322&r2=282323&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h Fri Sep 23 23:53:48 2016
@@ -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<unsigned, PartialMapping> MapOfPartialMappings;
+  mutable DenseMap<unsigned, PartialMapping *> 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 {

Modified: llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp?rev=282323&r1=282322&r2=282323&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp Fri Sep 23 23:53:48 2016
@@ -54,6 +54,11 @@ RegisterBankInfo::RegisterBankInfo(Regis
   });
 }
 
+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(unsi
   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




More information about the llvm-commits mailing list