[llvm] r263232 - [memdep] Just require domtree for memdep.

Chandler Carruth via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 11 05:46:00 PST 2016


Author: chandlerc
Date: Fri Mar 11 07:46:00 2016
New Revision: 263232

URL: http://llvm.org/viewvc/llvm-project?rev=263232&view=rev
Log:
[memdep] Just require domtree for memdep.

This doesn't cause us to construct dominator trees any more often in the
normal pipeline, and removes an entire mode of memdep that needed to be
reasoned about and maintained. Perhaps more importantly, it removes the
ability for the results of memdep to be different because of accidental
pass scheduling goofs or the order of evaluation of 'getResult' calls.

Essentially, 'getCachedResult', unless across IR-unit boundaries, is
extremely dangerous. We need to work much harder to avoid it (or its
analog in the old pass manager).

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=263232&r1=263231&r2=263232&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h (original)
+++ llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h Fri Mar 11 07:46:00 2016
@@ -341,13 +341,13 @@ private:
   AliasAnalysis &AA;
   AssumptionCache ∾
   const TargetLibraryInfo &TLI;
-  DominatorTree *DT;
+  DominatorTree &DT;
   PredIteratorCache PredCache;
 
 public:
   MemoryDependenceResults(AliasAnalysis &AA, AssumptionCache &AC,
                           const TargetLibraryInfo &TLI,
-                          DominatorTree *DT = nullptr)
+                          DominatorTree &DT)
       : AA(AA), AC(AC), TLI(TLI), DT(DT) {}
 
   /// Returns the instruction on which a memory operation depends.

Modified: llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp?rev=263232&r1=263231&r2=263232&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp Fri Mar 11 07:46:00 2016
@@ -373,7 +373,7 @@ MemoryDependenceResults::getInvariantGro
 
     for (Use &Us : Ptr->uses()) {
       auto *U = dyn_cast<Instruction>(Us.getUser());
-      if (!U || U == LI || !DT->dominates(U, LI))
+      if (!U || U == LI || !DT.dominates(U, LI))
         continue;
 
       if (auto *BCI = dyn_cast<BitCastInst>(U)) {
@@ -642,7 +642,7 @@ MemDepResult MemoryDependenceResults::ge
     ModRefInfo MR = AA.getModRefInfo(Inst, MemLoc);
     // If necessary, perform additional analysis.
     if (MR == MRI_ModRef)
-      MR = AA.callCapturesBefore(Inst, MemLoc, DT, &OBB);
+      MR = AA.callCapturesBefore(Inst, MemLoc, &DT, &OBB);
     switch (MR) {
     case MRI_NoModRef:
       // If the call has no effect on the queried pointer, just ignore it.
@@ -1127,10 +1127,7 @@ bool MemoryDependenceResults::getNonLoca
         continue;
       }
 
-      if (!DT) {
-        Result.push_back(
-            NonLocalDepResult(Entry.getBB(), MemDepResult::getUnknown(), Addr));
-      } else if (DT->isReachableFromEntry(Entry.getBB())) {
+      if (DT.isReachableFromEntry(Entry.getBB())) {
         Result.push_back(
             NonLocalDepResult(Entry.getBB(), Entry.getResult(), Addr));
       }
@@ -1199,11 +1196,7 @@ bool MemoryDependenceResults::getNonLoca
 
       // If we got a Def or Clobber, add this to the list of results.
       if (!Dep.isNonLocal()) {
-        if (!DT) {
-          Result.push_back(NonLocalDepResult(BB, MemDepResult::getUnknown(),
-                                             Pointer.getAddr()));
-          continue;
-        } else if (DT->isReachableFromEntry(BB)) {
+        if (DT.isReachableFromEntry(BB)) {
           Result.push_back(NonLocalDepResult(BB, Dep, Pointer.getAddr()));
           continue;
         }
@@ -1274,7 +1267,7 @@ bool MemoryDependenceResults::getNonLoca
       // Get the PHI translated pointer in this predecessor.  This can fail if
       // not translatable, in which case the getAddr() returns null.
       PHITransAddr &PredPointer = PredList.back().second;
-      PredPointer.PHITranslateValue(BB, Pred, DT, /*MustDominate=*/false);
+      PredPointer.PHITranslateValue(BB, Pred, &DT, /*MustDominate=*/false);
       Value *PredPtrVal = PredPointer.getAddr();
 
       // Check to see if we have already visited this pred block with another
@@ -1397,7 +1390,7 @@ bool MemoryDependenceResults::getNonLoca
         continue;
 
       assert((GotWorklistLimit || I.getResult().isNonLocal() ||
-              !DT->isReachableFromEntry(BB)) &&
+              !DT.isReachableFromEntry(BB)) &&
              "Should only be here with transparent block");
       foundBlock = true;
       I.setResult(MemDepResult::getUnknown());
@@ -1666,7 +1659,7 @@ MemoryDependenceAnalysis::run(Function &
   auto &AA = AM.getResult<AAManager>(F);
   auto &AC = AM.getResult<AssumptionAnalysis>(F);
   auto &TLI = AM.getResult<TargetLibraryAnalysis>(F);
-  auto *DT = AM.getCachedResult<DominatorTreeAnalysis>(F);
+  auto &DT = AM.getResult<DominatorTreeAnalysis>(F);
   return MemoryDependenceResults(AA, AC, TLI, DT);
 }
 
@@ -1676,6 +1669,7 @@ INITIALIZE_PASS_BEGIN(MemoryDependenceWr
                       "Memory Dependence Analysis", false, true)
 INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
 INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
+INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
 INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
 INITIALIZE_PASS_END(MemoryDependenceWrapperPass, "memdep",
                     "Memory Dependence Analysis", false, true)
@@ -1692,6 +1686,7 @@ void MemoryDependenceWrapperPass::releas
 void MemoryDependenceWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
   AU.setPreservesAll();
   AU.addRequired<AssumptionCacheTracker>();
+  AU.addRequired<DominatorTreeWrapperPass>();
   AU.addRequiredTransitive<AAResultsWrapperPass>();
   AU.addRequiredTransitive<TargetLibraryInfoWrapperPass>();
 }
@@ -1700,8 +1695,8 @@ bool MemoryDependenceWrapperPass::runOnF
   auto &AA = getAnalysis<AAResultsWrapperPass>().getAAResults();
   auto &AC = getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
   auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
-  auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>();
-  MemDep.emplace(AA, AC, TLI, DTWP ? &DTWP->getDomTree() : nullptr);
+  auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
+  MemDep.emplace(AA, AC, TLI, DT);
   return false;
 }
 




More information about the llvm-commits mailing list