[polly] r249237 - BlockGenerator: Use AssertingVH in maps

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 3 10:19:50 PDT 2015


Author: grosser
Date: Sat Oct  3 12:19:49 2015
New Revision: 249237

URL: http://llvm.org/viewvc/llvm-project?rev=249237&view=rev
Log:
BlockGenerator: Use AssertingVH in maps

By using asserting value handles, we will get assertions when we forget to clear
any of the Value maps instead of difficult to debug undefined behavior.

Modified:
    polly/trunk/include/polly/CodeGen/BlockGenerators.h
    polly/trunk/lib/CodeGen/BlockGenerators.cpp

Modified: polly/trunk/include/polly/CodeGen/BlockGenerators.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/CodeGen/BlockGenerators.h?rev=249237&r1=249236&r2=249237&view=diff
==============================================================================
--- polly/trunk/include/polly/CodeGen/BlockGenerators.h (original)
+++ polly/trunk/include/polly/CodeGen/BlockGenerators.h Sat Oct  3 12:19:49 2015
@@ -65,7 +65,7 @@ public:
   ///@{
 
   /// @see The ScalarMap and PHIOpMap member.
-  using ScalarAllocaMapTy = DenseMap<Value *, Value *>;
+  using ScalarAllocaMapTy = DenseMap<AssertingVH<Value>, AssertingVH<Value>>;
 
   /// @brief Simple vector of instructions to store escape users.
   using EscapeUserVectorTy = SmallVector<Instruction *, 4>;
@@ -74,7 +74,8 @@ public:
   ///
   /// @see The EscapeMap member.
   using EscapeUsersAllocaMapTy =
-      DenseMap<Instruction *, std::pair<Value *, EscapeUserVectorTy>>;
+      DenseMap<Instruction *,
+               std::pair<AssertingVH<Value>, EscapeUserVectorTy>>;
 
   ///@}
 

Modified: polly/trunk/lib/CodeGen/BlockGenerators.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/BlockGenerators.cpp?rev=249237&r1=249236&r2=249237&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/BlockGenerators.cpp (original)
+++ polly/trunk/lib/CodeGen/BlockGenerators.cpp Sat Oct  3 12:19:49 2015
@@ -362,18 +362,17 @@ void BlockGenerator::copyBB(ScopStmt &St
 Value *BlockGenerator::getOrCreateAlloca(Value *ScalarBase,
                                          ScalarAllocaMapTy &Map,
                                          const char *NameExt) {
-  // Check if an alloca was cached for the base instruction.
-  Value *&Addr = Map[ScalarBase];
-
   // If no alloca was found create one and insert it in the entry block.
-  if (!Addr) {
+  if (!Map.count(ScalarBase)) {
     auto *Ty = ScalarBase->getType();
     auto NewAddr = new AllocaInst(Ty, ScalarBase->getName() + NameExt);
     EntryBB = &Builder.GetInsertBlock()->getParent()->getEntryBlock();
     NewAddr->insertBefore(EntryBB->getFirstInsertionPt());
-    Addr = NewAddr;
+    Map[ScalarBase] = NewAddr;
   }
 
+  auto Addr = Map[ScalarBase];
+
   if (GlobalMap.count(Addr))
     return GlobalMap[Addr];
 




More information about the llvm-commits mailing list