Skip to content

[PassTimingInfo] Handle nested timers in passes #70165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions llvm/include/llvm/IR/PassTimingInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ class TimePassesHandler {
/// Map of timers for pass invocations
StringMap<TimerVector> TimingData;

/// Currently active pass timer.
Timer *ActivePassTimer = nullptr;
/// Stack of currently active pass timers. Passes can run other
/// passes.
SmallVector<Timer *, 8> PassActiveTimerStack;
/// Stack of currently active analysis timers. Analyses can request other
/// analyses.
SmallVector<Timer *, 8> AnalysisActiveTimerStack;
Expand Down
24 changes: 18 additions & 6 deletions llvm/lib/IR/PassTimingInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,20 +252,32 @@ static bool shouldIgnorePass(StringRef PassID) {
void TimePassesHandler::startPassTimer(StringRef PassID) {
if (shouldIgnorePass(PassID))
return;
assert(!ActivePassTimer && "should only have one pass timer at a time");
// Stop the previous pass timer to prevent double counting when a
// pass requests another pass.
if (!PassActiveTimerStack.empty()) {
assert(PassActiveTimerStack.back()->isRunning());
PassActiveTimerStack.back()->stopTimer();
}
Timer &MyTimer = getPassTimer(PassID, /*IsPass*/ true);
ActivePassTimer = &MyTimer;
PassActiveTimerStack.push_back(&MyTimer);
assert(!MyTimer.isRunning());
MyTimer.startTimer();
}

void TimePassesHandler::stopPassTimer(StringRef PassID) {
if (shouldIgnorePass(PassID))
return;
assert(ActivePassTimer);
assert(ActivePassTimer->isRunning());
ActivePassTimer->stopTimer();
ActivePassTimer = nullptr;
assert(!PassActiveTimerStack.empty() && "empty stack in popTimer");
Timer *MyTimer = PassActiveTimerStack.pop_back_val();
assert(MyTimer && "timer should be present");
assert(MyTimer->isRunning());
MyTimer->stopTimer();

// Restart the previously stopped timer.
if (!PassActiveTimerStack.empty()) {
assert(!PassActiveTimerStack.back()->isRunning());
PassActiveTimerStack.back()->startTimer();
}
}

void TimePassesHandler::startAnalysisTimer(StringRef PassID) {
Expand Down
15 changes: 13 additions & 2 deletions llvm/test/Other/time-passes.ll
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
; RUN: opt < %s -disable-output -passes='default<O2>' -time-passes 2>&1 | FileCheck %s --check-prefix=TIME
;
; For new pass manager, check that -time-passes-per-run emit one report for each pass run.
; RUN: opt < %s -disable-output -passes='instcombine,instcombine,loop-mssa(licm)' -time-passes-per-run 2>&1 | FileCheck %s --check-prefix=TIME --check-prefix=TIME-PER-RUN
; RUN: opt < %s -disable-output -passes='coro-cleanup,function(instcombine,instcombine,loop-mssa(licm))' -time-passes-per-run 2>&1 | FileCheck %s --check-prefix=TIME --check-prefix=TIME-PER-RUN --check-prefix=TIME-PER-RUN-CORO
; RUN: opt < %s -disable-output -passes='instcombine,loop-mssa(licm),instcombine,loop-mssa(licm)' -time-passes-per-run 2>&1 | FileCheck %s --check-prefix=TIME --check-prefix=TIME-PER-RUN -check-prefix=TIME-DOUBLE-LICM
;
; For new pass manager, check that -time-passes emit one report for each pass.
; RUN: opt < %s -disable-output -passes='instcombine,instcombine,loop-mssa(licm)' -time-passes 2>&1 | FileCheck %s --check-prefixes=TIME,TIME-PER-PASS
; RUN: opt < %s -disable-output -passes='coro-cleanup,function(instcombine,instcombine,loop-mssa(licm))' -time-passes 2>&1 | FileCheck %s --check-prefixes=TIME,TIME-PER-PASS,TIME-PER-PASS-CORO
; RUN: opt < %s -disable-output -passes='instcombine,loop-mssa(licm),instcombine,loop-mssa(licm)' -time-passes 2>&1 | FileCheck %s --check-prefixes=TIME,TIME-PER-PASS
;
; The following 2 test runs verify -info-output-file interaction (default goes to stderr, '-' goes to stdout).
Expand All @@ -30,11 +30,15 @@
; TIME-PER-RUN-DAG: LCSSAPass
; TIME-PER-RUN-DAG: LoopSimplifyPass
; TIME-PER-RUN-DAG: VerifierPass
; TIME-PER-RUN-CORO-DAG: SimplifyCFGPass #1
; TIME-PER-RUN-CORO-DAG: CoroCleanupPass #1
; TIME-PER-PASS-DAG: InstCombinePass
; TIME-PER-PASS-DAG: LICMPass
; TIME-PER-PASS-DAG: LCSSAPass
; TIME-PER-PASS-DAG: LoopSimplifyPass
; TIME-PER-PASS-DAG: VerifierPass
; TIME-PER-PASS-CORO-DAG: SimplifyCFGPass
; TIME-PER-PASS-CORO-DAG: CoroCleanupPass
; TIME-PER-PASS-NOT: InstCombinePass #
; TIME-PER-PASS-NOT: LICMPass #
; TIME-PER-PASS-NOT: LCSSAPass #
Expand Down Expand Up @@ -78,3 +82,10 @@ end:
ret void

}

define void @baz_coro() {
%unused = call ptr @llvm.coro.begin(token none, ptr null)
ret void
}

declare ptr @llvm.coro.begin(token, ptr)