[llvm-commits] [llvm] r60274 - in /llvm/trunk: include/llvm/Analysis/MemoryDependenceAnalysis.h lib/Analysis/MemoryDependenceAnalysis.cpp

Chris Lattner sabre at nondot.org
Sat Nov 29 18:52:27 PST 2008


Author: lattner
Date: Sat Nov 29 20:52:26 2008
New Revision: 60274

URL: http://llvm.org/viewvc/llvm-project?rev=60274&view=rev
Log:
Two changes: Make getDependency remove QueryInst for a dirty record's
ReverseLocalDeps when we update it.  This fixes a regression test
failure from my last commit.

Second, for each non-local cached information structure, keep a bit that
indicates whether it is dirty or not.  This saves us a scan over the whole
thing in the common case when it isn't dirty.

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

Modified: llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h?rev=60274&r1=60273&r2=60274&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h (original)
+++ llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h Sat Nov 29 20:52:26 2008
@@ -129,11 +129,14 @@
 
     typedef DenseMap<BasicBlock*, DepResultTy> NonLocalDepInfo;
     
+    /// PerInstNLInfo - This is the instruction we keep for each cached access
+    /// that we have for an instruction.  The pointer is an owning pointer and
+    /// the bool indicates whether we have any dirty bits in the set.
+    typedef PointerIntPair<NonLocalDepInfo*, 1, bool> PerInstNLInfo;
     
     // A map from instructions to their non-local dependencies.
-    typedef DenseMap<Instruction*,
-                     // This is an owning pointer.
-                     NonLocalDepInfo*> NonLocalDepMapType;
+    typedef DenseMap<Instruction*, PerInstNLInfo> NonLocalDepMapType;
+      
     NonLocalDepMapType NonLocalDeps;
     
     // A reverse mapping from dependencies to the dependees.  This is
@@ -158,7 +161,7 @@
       LocalDeps.clear();
       for (NonLocalDepMapType::iterator I = NonLocalDeps.begin(),
            E = NonLocalDeps.end(); I != E; ++I)
-        delete I->second;
+        delete I->second.getPointer();
       NonLocalDeps.clear();
       ReverseLocalDeps.clear();
       ReverseNonLocalDeps.clear();

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

==============================================================================
--- llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp Sat Nov 29 20:52:26 2008
@@ -199,8 +199,14 @@
     
   // Otherwise, if we have a dirty entry, we know we can start the scan at that
   // instruction, which may save us some work.
-  if (Instruction *Inst = LocalCache.getPointer())
+  if (Instruction *Inst = LocalCache.getPointer()) {
     ScanPos = Inst;
+   
+    SmallPtrSet<Instruction*, 4> &InstMap = ReverseLocalDeps[Inst];
+    InstMap.erase(QueryInst);
+    if (InstMap.empty())
+      ReverseLocalDeps.erase(Inst);
+  }
   
   // Do the scan.
   LocalCache = getDependencyFromInternal(QueryInst, ScanPos,
@@ -227,10 +233,10 @@
                                                       MemDepResult> > &Result) {
   assert(getDependency(QueryInst).isNonLocal() &&
      "getNonLocalDependency should only be used on insts with non-local deps!");
-  NonLocalDepInfo *&CacheP = NonLocalDeps[QueryInst];
-  if (CacheP == 0) CacheP = new NonLocalDepInfo();
+  PerInstNLInfo &CacheP = NonLocalDeps[QueryInst];
+  if (CacheP.getPointer() == 0) CacheP.setPointer(new NonLocalDepInfo());
   
-  NonLocalDepInfo &Cache = *CacheP;
+  NonLocalDepInfo &Cache = *CacheP.getPointer();
 
   /// DirtyBlocks - This is the set of blocks that need to be recomputed.  In
   /// the cached case, this can happen due to instructions being deleted etc. In
@@ -240,13 +246,13 @@
   
   if (!Cache.empty()) {
     // If we already have a partially computed set of results, scan them to
-    // determine what is dirty, seeding our initial DirtyBlocks worklist.
-    // FIXME: In the "don't need to be updated" case, this is expensive, why not
-    // have a per-"cache" flag saying it is undirty?
-    for (NonLocalDepInfo::iterator I = Cache.begin(), E = Cache.end();
+    // determine what is dirty, seeding our initial DirtyBlocks worklist.  The
+    // Int bit of CacheP tells us if we have anything dirty.
+    if (CacheP.getInt())
+      for (NonLocalDepInfo::iterator I = Cache.begin(), E = Cache.end();
          I != E; ++I)
-      if (I->second.getInt() == Dirty)
-        DirtyBlocks.push_back(I->first);
+        if (I->second.getInt() == Dirty)
+          DirtyBlocks.push_back(I->first);
     
     NumCacheNonLocal++;
     
@@ -315,7 +321,7 @@
   // for any cached queries.
   NonLocalDepMapType::iterator NLDI = NonLocalDeps.find(RemInst);
   if (NLDI != NonLocalDeps.end()) {
-    NonLocalDepInfo &BlockMap = *NLDI->second;
+    NonLocalDepInfo &BlockMap = *NLDI->second.getPointer();
     for (NonLocalDepInfo::iterator DI = BlockMap.begin(), DE = BlockMap.end();
          DI != DE; ++DI)
       if (Instruction *Inst = DI->second.getPointer())
@@ -388,11 +394,13 @@
          I != E; ++I) {
       assert(*I != RemInst && "Already removed NonLocalDep info for RemInst");
       
-      NonLocalDepInfo &INLD = *NonLocalDeps[*I];
-      assert(&INLD != 0 && "Reverse mapping out of date?");
+      PerInstNLInfo &INLD = NonLocalDeps[*I];
+      assert(INLD.getPointer() != 0 && "Reverse mapping out of date?");
+      // The information is now dirty!
+      INLD.setInt(true);
       
-      for (NonLocalDepInfo::iterator DI = INLD.begin(), DE = INLD.end();
-           DI != DE; ++DI) {
+      for (NonLocalDepInfo::iterator DI = INLD.getPointer()->begin(), 
+           DE = INLD.getPointer()->end(); DI != DE; ++DI) {
         if (DI->second.getPointer() != RemInst) continue;
         
         // Convert to a dirty entry for the subsequent instruction.
@@ -435,9 +443,9 @@
   for (NonLocalDepMapType::const_iterator I = NonLocalDeps.begin(),
        E = NonLocalDeps.end(); I != E; ++I) {
     assert(I->first != D && "Inst occurs in data structures");
-    NonLocalDepInfo &INLD = *I->second;
-    for (NonLocalDepInfo::iterator II = INLD.begin(), EE = INLD.end();
-         II  != EE; ++II)
+    const PerInstNLInfo &INLD = I->second;
+    for (NonLocalDepInfo::iterator II = INLD.getPointer()->begin(),
+         EE = INLD.getPointer()->end(); II  != EE; ++II)
       assert(II->second.getPointer() != D && "Inst occurs in data structures");
   }
   





More information about the llvm-commits mailing list