OSDN Git Service

Fix pass return status for loop extractor
authorserge-sans-paille <sguelton@redhat.com>
Fri, 26 Jun 2020 13:23:05 +0000 (15:23 +0200)
committerserge-sans-paille <sguelton@redhat.com>
Fri, 26 Jun 2020 13:49:27 +0000 (15:49 +0200)
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

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

index b41598c..d85a82e 100644 (file)
@@ -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
index 14c3950..f7f5b4c 100644 (file)
@@ -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,