[llvm] 44f06db - Fix pass return status for loop extractor

via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 26 06:49:49 PDT 2020


Author: serge-sans-paille
Date: 2020-06-26T15:49:27+02:00
New Revision: 44f06db43941749b631756ff13cf7e8f7b2903fe

URL: https://github.com/llvm/llvm-project/commit/44f06db43941749b631756ff13cf7e8f7b2903fe
DIFF: https://github.com/llvm/llvm-project/commit/44f06db43941749b631756ff13cf7e8f7b2903fe.diff

LOG: Fix pass return status for loop extractor

As loop extractor has a dependency on another pass (namely BreakCriticalEdges)
that may update the IR, use the getAnalysis version introduced in
55fe7b79bb7fab49af3720840224c0720bdb03c6 to carry that change.

Add an assert in getAnalysisID to make sure no other changed status is missed -
according to validation this was the only one.

Related to https://reviews.llvm.org/D80916

Differential Revision: https://reviews.llvm.org/D81236

Added: 
    

Modified: 
    llvm/include/llvm/PassAnalysisSupport.h
    llvm/lib/Transforms/IPO/LoopExtractor.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/PassAnalysisSupport.h b/llvm/include/llvm/PassAnalysisSupport.h
index b41598ca9b73..d85a82e2cdde 100644
--- a/llvm/include/llvm/PassAnalysisSupport.h
+++ b/llvm/include/llvm/PassAnalysisSupport.h
@@ -270,6 +270,9 @@ AnalysisType &Pass::getAnalysisID(AnalysisID PI, Function &F, bool *Changed) {
   assert(ResultPass && "Unable to find requested analysis info");
   if (Changed)
     *Changed |= LocalChanged;
+  else
+    assert(!LocalChanged &&
+           "A pass trigged a code update but the update status is lost");
 
   // Because the AnalysisType may not be a subclass of pass (for
   // AnalysisGroups), we use getAdjustedAnalysisPointer here to potentially

diff  --git a/llvm/lib/Transforms/IPO/LoopExtractor.cpp b/llvm/lib/Transforms/IPO/LoopExtractor.cpp
index 14c39503e385..f7f5b4cf6704 100644
--- a/llvm/lib/Transforms/IPO/LoopExtractor.cpp
+++ b/llvm/lib/Transforms/IPO/LoopExtractor.cpp
@@ -131,18 +131,19 @@ bool LoopExtractor::runOnFunction(Function &F) {
   if (F.empty())
     return false;
 
-  LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>(F).getLoopInfo();
+  bool Changed = false;
+  LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>(F, &Changed).getLoopInfo();
 
   // If there are no loops in the function.
   if (LI.empty())
-    return false;
+    return Changed;
 
   DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>(F).getDomTree();
 
   // If there is more than one top-level loop in this function, extract all of
   // the loops.
   if (std::next(LI.begin()) != LI.end())
-    return extractLoops(LI.begin(), LI.end(), LI, DT);
+    return Changed | extractLoops(LI.begin(), LI.end(), LI, DT);
 
   // Otherwise there is exactly one top-level loop.
   Loop *TLL = *LI.begin();
@@ -171,14 +172,14 @@ bool LoopExtractor::runOnFunction(Function &F) {
     }
 
     if (ShouldExtractLoop)
-      return extractLoop(TLL, LI, DT);
+      return Changed | extractLoop(TLL, LI, DT);
   }
 
   // Okay, this function is a minimal container around the specified loop.
   // If we extract the loop, we will continue to just keep extracting it
   // infinitely... so don't extract it. However, if the loop contains any
   // sub-loops, extract them.
-  return extractLoops(TLL->begin(), TLL->end(), LI, DT);
+  return Changed | extractLoops(TLL->begin(), TLL->end(), LI, DT);
 }
 
 bool LoopExtractor::extractLoops(Loop::iterator From, Loop::iterator To,


        


More information about the llvm-commits mailing list