[PATCH] D131059: [Timer][Statistics] Make global constructor ordering more robust
Nicolai Hähnle via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 3 02:07:03 PDT 2022
nhaehnle created this revision.
nhaehnle added a reviewer: efriedma.
Herald added a subscriber: hiraditya.
Herald added a project: All.
nhaehnle requested review of this revision.
Herald added a project: LLVM.
It was observed in D129117 <https://reviews.llvm.org/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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D131059
Files:
llvm/include/llvm/Support/Timer.h
llvm/lib/Support/Statistic.cpp
llvm/lib/Support/Timer.cpp
Index: llvm/lib/Support/Timer.cpp
===================================================================
--- llvm/lib/Support/Timer.cpp
+++ llvm/lib/Support/Timer.cpp
@@ -499,7 +499,8 @@
return delim;
}
-void TimerGroup::ConstructTimerLists() {
+void TimerGroup::ConstructForStatistics() {
+ (void)getLibSupportInfoOutputFilename();
(void)*NamedGroupedTimers;
}
Index: llvm/lib/Support/Statistic.cpp
===================================================================
--- llvm/lib/Support/Statistic.cpp
+++ llvm/lib/Support/Statistic.cpp
@@ -120,8 +120,9 @@
}
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.
Index: llvm/include/llvm/Support/Timer.h
===================================================================
--- llvm/include/llvm/Support/Timer.h
+++ llvm/include/llvm/Support/Timer.h
@@ -231,10 +231,10 @@
/// 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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131059.449597.patch
Type: text/x-patch
Size: 1874 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220803/ccaeaa5d/attachment.bin>
More information about the llvm-commits
mailing list