diff --git a/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h b/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h --- a/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h +++ b/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h @@ -183,6 +183,12 @@ PreservedAnalyses runWithoutLoopNestPasses(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &U); + +private: + static const Loop &getLoopFromIR(Loop &L) { return L; } + static const Loop &getLoopFromIR(LoopNest &LN) { + return LN.getOutermostLoop(); + } }; /// The Loop pass manager. @@ -358,9 +364,12 @@ Optional LoopPassManager::runSinglePass( IRUnitT &IR, PassT &Pass, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &U, PassInstrumentation &PI) { + // Get the loop in case of Loop pass and outermost loop in case of LoopNest + // pass which is to be passed to BeforePass and AfterPass call backs. + const Loop &L = getLoopFromIR(IR); // Check the PassInstrumentation's BeforePass callbacks before running the // pass, skip its execution completely if asked to (callback returns false). - if (!PI.runBeforePass(*Pass, IR)) + if (!PI.runBeforePass(*Pass, L)) return None; PreservedAnalyses PA; @@ -373,7 +382,7 @@ if (U.skipCurrentLoop()) PI.runAfterPassInvalidated(*Pass, PA); else - PI.runAfterPass(*Pass, IR, PA); + PI.runAfterPass(*Pass, L, PA); return PA; } diff --git a/llvm/test/Other/loopnest-callback.ll b/llvm/test/Other/loopnest-callback.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Other/loopnest-callback.ll @@ -0,0 +1,9 @@ +;RUN: opt -disable-output -passes=loop-interchange -print-after-all < %s 2>&1 | FileCheck %s + +; CHECK: IR Dump After LoopInterchangePass +define void @foo() { +entry: + br label %for.cond +for.cond: + br label %for.cond +}