diff --git a/llvm/include/llvm/IR/PassTimingInfo.h b/llvm/include/llvm/IR/PassTimingInfo.h --- a/llvm/include/llvm/IR/PassTimingInfo.h +++ b/llvm/include/llvm/IR/PassTimingInfo.h @@ -54,8 +54,8 @@ /// Map of timers for pass invocations StringMap TimingData; - /// Stack of currently active timers. - SmallVector TimerStack; + /// Currently active timer. + Timer *ActiveTimer; /// Custom output stream to print timing information into. /// By default (== nullptr) we emit time report into the stream created by diff --git a/llvm/lib/IR/PassTimingInfo.cpp b/llvm/lib/IR/PassTimingInfo.cpp --- a/llvm/lib/IR/PassTimingInfo.cpp +++ b/llvm/lib/IR/PassTimingInfo.cpp @@ -234,23 +234,28 @@ } void TimePassesHandler::startTimer(StringRef PassID) { + assert(!ActiveTimer && "overlapping timers causes double counting"); Timer &MyTimer = getPassTimer(PassID); - TimerStack.push_back(&MyTimer); - if (!MyTimer.isRunning()) - MyTimer.startTimer(); + ActiveTimer = &MyTimer; + assert(!MyTimer.isRunning()); + MyTimer.startTimer(); } void TimePassesHandler::stopTimer(StringRef PassID) { - assert(TimerStack.size() > 0 && "empty stack in popTimer"); - Timer *MyTimer = TimerStack.pop_back_val(); - assert(MyTimer && "timer should be present"); - if (MyTimer->isRunning()) - MyTimer->stopTimer(); + assert(ActiveTimer); + assert(ActiveTimer->isRunning()); + ActiveTimer->stopTimer(); + ActiveTimer = nullptr; +} + +static bool shouldIgnorePass(StringRef PassID) { + return isSpecialPass(PassID, + {"PassManager", "PassAdaptor", "AnalysisManagerProxy", + "ModuleInlinerWrapperPass", "DevirtSCCRepeatedPass"}); } void TimePassesHandler::runBeforePass(StringRef PassID) { - if (isSpecialPass(PassID, - {"PassManager", "PassAdaptor", "AnalysisManagerProxy"})) + if (shouldIgnorePass(PassID)) return; startTimer(PassID); @@ -260,8 +265,7 @@ } void TimePassesHandler::runAfterPass(StringRef PassID) { - if (isSpecialPass(PassID, - {"PassManager", "PassAdaptor", "AnalysisManagerProxy"})) + if (shouldIgnorePass(PassID)) return; stopTimer(PassID); @@ -284,10 +288,6 @@ [this](StringRef P, const PreservedAnalyses &) { this->runAfterPass(P); }); - PIC.registerBeforeAnalysisCallback( - [this](StringRef P, Any) { this->runBeforePass(P); }); - PIC.registerAfterAnalysisCallback( - [this](StringRef P, Any) { this->runAfterPass(P); }); } } // namespace llvm diff --git a/llvm/test/Other/time-passes.ll b/llvm/test/Other/time-passes.ll --- a/llvm/test/Other/time-passes.ll +++ b/llvm/test/Other/time-passes.ll @@ -27,31 +27,19 @@ ; TIME-DOUBLE-LICM-DAG: LICMPass #4 ; TIME-DOUBLE-LICM-DAG: LICMPass #5 ; TIME-DOUBLE-LICM-DAG: LICMPass #6 -; TIME-PER_RUN-DAG: LCSSAPass -; TIME-PER_RUN-DAG: LoopSimplifyPass -; TIME-PER_RUN-DAG: ScalarEvolutionAnalysis -; TIME-PER_RUN-DAG: LoopAnalysis -; TIME-PER_RUN-DAG: VerifierPass -; TIME-PER_RUN-DAG: DominatorTreeAnalysis -; TIME-PER_RUN-DAG: TargetLibraryAnalysis +; TIME-PER-RUN-DAG: LCSSAPass +; TIME-PER-RUN-DAG: LoopSimplifyPass +; TIME-PER-RUN-DAG: VerifierPass ; TIME-PER-PASS-DAG: InstCombinePass ; TIME-PER-PASS-DAG: LICMPass ; TIME-PER-PASS-DAG: LCSSAPass ; TIME-PER-PASS-DAG: LoopSimplifyPass -; TIME-PER-PASS-DAG: ScalarEvolutionAnalysis -; TIME-PER-PASS-DAG: LoopAnalysis ; TIME-PER-PASS-DAG: VerifierPass -; TIME-PER-PASS-DAG: DominatorTreeAnalysis -; TIME-PER-PASS-DAG: TargetLibraryAnalysis ; TIME-PER-PASS-NOT: InstCombinePass # ; TIME-PER-PASS-NOT: LICMPass # ; TIME-PER-PASS-NOT: LCSSAPass # ; TIME-PER-PASS-NOT: LoopSimplifyPass # -; TIME-PER-PASS-NOT: ScalarEvolutionAnalysis # -; TIME-PER-PASS-NOT: LoopAnalysis # ; TIME-PER-PASS-NOT: VerifierPass # -; TIME-PER-PASS-NOT: DominatorTreeAnalysis # -; TIME-PER-PASS-NOT: TargetLibraryAnalysis # ; TIME: Total{{$}} define i32 @foo() {