[llvm] af2e549 - [Timer][Statistics] Make global constructor ordering more robust
Nicolai Hähnle via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 25 10:10:23 PDT 2022
Author: Nicolai Hähnle
Date: 2022-08-25T19:09:49+02:00
New Revision: af2e54992de969f3ec75e397f1840068c2ebd060
URL: https://github.com/llvm/llvm-project/commit/af2e54992de969f3ec75e397f1840068c2ebd060
DIFF: https://github.com/llvm/llvm-project/commit/af2e54992de969f3ec75e397f1840068c2ebd060.diff
LOG: [Timer][Statistics] Make global constructor ordering more robust
It was observed in D129117 that the subtle dependency between statistic
and timer code is not entirely robust: the global destructor
~StatisticInfo indirectly calls CreateInfoOutputFile, which requires
the LibSupportInfoOutputFilename to not have been destructed.
By constructing LibSupportInfoOutputFilename before the StatisticInfo
object, the order of destruction is guaranteed.
Differential Revision: https://reviews.llvm.org/D131059
Added:
Modified:
llvm/include/llvm/Support/Timer.h
llvm/lib/Support/Statistic.cpp
llvm/lib/Support/Timer.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Support/Timer.h b/llvm/include/llvm/Support/Timer.h
index 742d20ce51dd..d72af3541af0 100644
--- a/llvm/include/llvm/Support/Timer.h
+++ b/llvm/include/llvm/Support/Timer.h
@@ -231,10 +231,10 @@ class TimerGroup {
/// Prints all timers as JSON key/value pairs.
static const char *printAllJSONValues(raw_ostream &OS, const char *delim);
- /// Ensure global timer group lists are initialized. This function is mostly
- /// used by the Statistic code to influence the construction and destruction
- /// order of the global timer lists.
- static void ConstructTimerLists();
+ /// Ensure global objects required for statistics printing are initialized.
+ /// This function is used by the Statistic code to ensure correct order of
+ /// global constructors and destructors.
+ static void constructForStatistics();
/// This makes the default group unmanaged, and lets the user manage the
/// group's lifetime.
diff --git a/llvm/lib/Support/Statistic.cpp b/llvm/lib/Support/Statistic.cpp
index df9f7c5e0be3..24ef3e9abaeb 100644
--- a/llvm/lib/Support/Statistic.cpp
+++ b/llvm/lib/Support/Statistic.cpp
@@ -120,8 +120,9 @@ void TrackingStatistic::RegisterStatistic() {
}
StatisticInfo::StatisticInfo() {
- // Ensure timergroup lists are created first so they are destructed after us.
- TimerGroup::ConstructTimerLists();
+ // Ensure that necessary timer global objects are created first so they are
+ // destructed after us.
+ TimerGroup::constructForStatistics();
}
// Print information when destroyed, iff command line option is specified.
diff --git a/llvm/lib/Support/Timer.cpp b/llvm/lib/Support/Timer.cpp
index 08e1a8a0e0aa..c1b0fdbc077b 100644
--- a/llvm/lib/Support/Timer.cpp
+++ b/llvm/lib/Support/Timer.cpp
@@ -499,7 +499,8 @@ const char *TimerGroup::printAllJSONValues(raw_ostream &OS, const char *delim) {
return delim;
}
-void TimerGroup::ConstructTimerLists() {
+void TimerGroup::constructForStatistics() {
+ (void)getLibSupportInfoOutputFilename();
(void)*NamedGroupedTimers;
}
More information about the llvm-commits
mailing list