aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/Timer.cpp
diff options
context:
space:
mode:
authorAlan Zhao <ayzhao@google.com>2025-03-13 10:13:28 -0700
committerGitHub <noreply@github.com>2025-03-13 10:13:28 -0700
commit09d8e442ac2884aabe4cdfb01d1444b54cff7147 (patch)
treeb0ad1885aca40d3926b3194d173f6ecc993fb19c /llvm/lib/Support/Timer.cpp
parent09a36c82793ba32b87faf11fbfc2e7624f25e92e (diff)
downloadllvm-09d8e442ac2884aabe4cdfb01d1444b54cff7147.zip
llvm-09d8e442ac2884aabe4cdfb01d1444b54cff7147.tar.gz
llvm-09d8e442ac2884aabe4cdfb01d1444b54cff7147.tar.bz2
[llvm][Timer] Use global TimerGroups for both new pass manager and old pass manager timers (#130375)
Additionally, remove the behavior for both pass manager's timer manager classes (`PassTimingInfo` for the old pass manager and `TimePassesHandler` for the new pass manager) where these classes would print the values of their timers upon destruction. Currently, each pass manager manages their own `TimerGroup`s. This is problematic because of duplicate `TimerGroup`s (both pass managers have a `TimerGroup` for pass times with identical names and descriptions). The result is that in Clang, `-ftime-report` has two "Pass execution timing report" sections (one for the new pass manager which manages optimization passes, and one for the old pass manager which manages the backend). The result of this change is that Clang's `-ftime-report` now prints both optimization and backend pass timing info in a unified "Pass execution timing report" section. Moving the ownership of the `TimerGroups` to globals also makes it easier to implement JSON-formatted `-ftime-report`. This was not possible with the old structure because the two pass managers were created and destroyed in far parts of the codebase and outputting JSON requires the printing logic to be at the same place because of formatting. Previous discourse discussion: https://discourse.llvm.org/t/difficulties-with-implementing-json-formatted-ftime-report/84353
Diffstat (limited to 'llvm/lib/Support/Timer.cpp')
-rw-r--r--llvm/lib/Support/Timer.cpp26
1 files changed, 21 insertions, 5 deletions
diff --git a/llvm/lib/Support/Timer.cpp b/llvm/lib/Support/Timer.cpp
index eca7268..4d3b4f7 100644
--- a/llvm/lib/Support/Timer.cpp
+++ b/llvm/lib/Support/Timer.cpp
@@ -222,16 +222,27 @@ public:
StringRef GroupDescription) {
sys::SmartScopedLock<true> L(timerLock());
- std::pair<TimerGroup*, Name2TimerMap> &GroupEntry = Map[GroupName];
-
- if (!GroupEntry.first)
- GroupEntry.first = new TimerGroup(GroupName, GroupDescription);
-
+ std::pair<TimerGroup *, Name2TimerMap> &GroupEntry =
+ getGroupEntry(GroupName, GroupDescription);
Timer &T = GroupEntry.second[Name];
if (!T.isInitialized())
T.init(Name, Description, *GroupEntry.first);
return T;
}
+
+ TimerGroup &getTimerGroup(StringRef GroupName, StringRef GroupDescription) {
+ return *getGroupEntry(GroupName, GroupDescription).first;
+ }
+
+private:
+ std::pair<TimerGroup *, Name2TimerMap> &
+ getGroupEntry(StringRef GroupName, StringRef GroupDescription) {
+ std::pair<TimerGroup *, Name2TimerMap> &GroupEntry = Map[GroupName];
+ if (!GroupEntry.first)
+ GroupEntry.first = new TimerGroup(GroupName, GroupDescription);
+
+ return GroupEntry;
+ }
};
}
@@ -244,6 +255,11 @@ NamedRegionTimer::NamedRegionTimer(StringRef Name, StringRef Description,
: &namedGroupedTimers().get(Name, Description, GroupName,
GroupDescription)) {}
+TimerGroup &NamedRegionTimer::getNamedTimerGroup(StringRef GroupName,
+ StringRef GroupDescription) {
+ return namedGroupedTimers().getTimerGroup(GroupName, GroupDescription);
+}
+
//===----------------------------------------------------------------------===//
// TimerGroup Implementation
//===----------------------------------------------------------------------===//