[llvm-commits] [llvm] r60672 - /llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp

Chris Lattner sabre at nondot.org
Sun Dec 7 10:39:13 PST 2008


Author: lattner
Date: Sun Dec  7 12:39:13 2008
New Revision: 60672

URL: http://llvm.org/viewvc/llvm-project?rev=60672&view=rev
Log:
factor some code, fixing some fixme's.

Modified:
    llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp

Modified: llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp?rev=60672&r1=60671&r2=60672&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp Sun Dec  7 12:39:13 2008
@@ -57,6 +57,21 @@
   return false;
 }
 
+/// RemoveFromReverseMap - This is a helper function that removes Val from
+/// 'Inst's set in ReverseMap.  If the set becomes empty, remove Inst's entry.
+template <typename KeyTy>
+static void RemoveFromReverseMap(DenseMap<Instruction*, 
+                                 SmallPtrSet<KeyTy*, 4> > &ReverseMap,
+                                 Instruction *Inst, KeyTy *Val) {
+  typename DenseMap<Instruction*, SmallPtrSet<KeyTy*, 4> >::iterator
+  InstIt = ReverseMap.find(Inst);
+  assert(InstIt != ReverseMap.end() && "Reverse map out of sync?");
+  bool Found = InstIt->second.erase(Val);
+  assert(Found && "Invalid reverse map!"); Found=Found;
+  if (InstIt->second.empty())
+    ReverseMap.erase(InstIt);
+}
+
 
 /// getCallSiteDependencyFrom - Private helper for finding the local
 /// dependencies of a call site.
@@ -207,12 +222,7 @@
   if (Instruction *Inst = LocalCache.getInst()) {
     ScanPos = Inst;
    
-    SmallPtrSet<Instruction*, 4> &InstMap = ReverseLocalDeps[Inst];
-    bool Found = InstMap.erase(QueryInst);
-    assert(Found && "Invalid reverse map!"); Found=Found;
-    if (InstMap.empty())
-      // FIXME: use an iterator to avoid looking up inst again.
-      ReverseLocalDeps.erase(Inst);
+    RemoveFromReverseMap(ReverseLocalDeps, Inst, QueryInst);
   }
   
   BasicBlock *QueryParent = QueryInst->getParent();
@@ -363,13 +373,8 @@
     if (ExistingResult) {
       if (Instruction *Inst = ExistingResult->getInst()) {
         ScanPos = Inst;
-      
         // We're removing QueryInst's use of Inst.
-        SmallPtrSet<Instruction*, 4> &InstMap = ReverseNonLocalDeps[Inst];
-        bool Found = InstMap.erase(QueryInst);
-        assert(Found && "Invalid reverse map!"); Found=Found;
-        // FIXME: Use an iterator to avoid looking up inst again.
-        if (InstMap.empty()) ReverseNonLocalDeps.erase(Inst);
+        RemoveFromReverseMap(ReverseNonLocalDeps, Inst, QueryInst);
       }
     }
     
@@ -527,11 +532,8 @@
         ScanPos = ExistingResult->getInst();
 
         // Eliminating the dirty entry from 'Cache', so update the reverse info.
-        SmallPtrSet<void *, 4> &InstMap = ReverseNonLocalPtrDeps[ScanPos];
-        bool Contained = InstMap.erase(CacheKey.getOpaqueValue());
-        assert(Contained && "Invalid cache entry"); Contained=Contained;
-        // FIXME: Use an iterator to avoid a repeated lookup in ".erase".
-        if (InstMap.empty()) ReverseNonLocalPtrDeps.erase(ScanPos);
+        RemoveFromReverseMap(ReverseNonLocalPtrDeps, ScanPos,
+                             CacheKey.getOpaqueValue());
       } else {
         ++NumUncacheNonLocalPtr;
       }
@@ -595,12 +597,7 @@
     assert(Target->getParent() == PInfo[i].first && Target != P.getPointer());
     
     // Eliminating the dirty entry from 'Cache', so update the reverse info.
-    SmallPtrSet<void *, 4> &InstMap = ReverseNonLocalPtrDeps[Target];
-    bool Contained = InstMap.erase(P.getOpaqueValue());
-    assert(Contained && "Invalid cache entry"); Contained=Contained;
-    
-    // FIXME: Use an iterator to avoid a repeated lookup in ".erase".
-    if (InstMap.empty()) ReverseNonLocalPtrDeps.erase(Target);
+    RemoveFromReverseMap(ReverseNonLocalPtrDeps, Target, P.getOpaqueValue());
   }
   
   // Remove P from NonLocalPointerDeps (which deletes NonLocalDepInfo).
@@ -620,7 +617,7 @@
     for (NonLocalDepInfo::iterator DI = BlockMap.begin(), DE = BlockMap.end();
          DI != DE; ++DI)
       if (Instruction *Inst = DI->second.getInst())
-        ReverseNonLocalDeps[Inst].erase(RemInst);
+        RemoveFromReverseMap(ReverseNonLocalDeps, Inst, RemInst);
     NonLocalDeps.erase(NLDI);
   }
 
@@ -629,14 +626,8 @@
   LocalDepMapType::iterator LocalDepEntry = LocalDeps.find(RemInst);
   if (LocalDepEntry != LocalDeps.end()) {
     // Remove us from DepInst's reverse set now that the local dep info is gone.
-    if (Instruction *Inst = LocalDepEntry->second.getInst()) {
-      SmallPtrSet<Instruction*, 4> &RLD = ReverseLocalDeps[Inst];
-      bool Found = RLD.erase(RemInst);
-      assert(Found && "Invalid reverse map!"); Found=Found;
-      // FIXME: Use an iterator to avoid looking up Inst again.
-      if (RLD.empty())
-        ReverseLocalDeps.erase(Inst);
-    }
+    if (Instruction *Inst = LocalDepEntry->second.getInst())
+      RemoveFromReverseMap(ReverseLocalDeps, Inst, RemInst);
 
     // Remove this local dependency info.
     LocalDeps.erase(LocalDepEntry);





More information about the llvm-commits mailing list