]> granicus.if.org Git - llvm/commitdiff
[RegisterBankInfo] Keep valid pointers for PartialMappings.
authorQuentin Colombet <qcolombet@apple.com>
Sat, 24 Sep 2016 04:53:48 +0000 (04:53 +0000)
committerQuentin Colombet <qcolombet@apple.com>
Sat, 24 Sep 2016 04:53:48 +0000 (04:53 +0000)
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

include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h
lib/CodeGen/GlobalISel/RegisterBankInfo.cpp

index 761f50f2190945fa42f8a132040c9481750f98ee..dd9572e60c89129ede8bd95ae450a230c3a5e98d 100644 (file)
@@ -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 {
index b52e098539860da00bbc4c1f8eeba12eebbf5802..172067233a1989c7a644769088e80486e2295c0e 100644 (file)
@@ -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