From c4c31e2020a7ad36f055a668eca10902e1d724e9 Mon Sep 17 00:00:00 2001 From: Erich Keane Date: Thu, 16 Feb 2017 20:19:49 +0000 Subject: [PATCH] Change default TimerGroup singleton to use magic statics TimerGroup was showing up on a leak in valigrind, and used some pretty complex code to implement a singleton. This patch replaces the implementation with a vastly simpler one. Differential Revision: https://reviews.llvm.org/D28367 llvm-svn: 295370 --- llvm/lib/Support/Timer.cpp | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/llvm/lib/Support/Timer.cpp b/llvm/lib/Support/Timer.cpp index fbd73d0b6b3b..8d68c6ae9682 100644 --- a/llvm/lib/Support/Timer.cpp +++ b/llvm/lib/Support/Timer.cpp @@ -72,22 +72,9 @@ std::unique_ptr llvm::CreateInfoOutputFile() { return llvm::make_unique(2, false); // stderr. } - -static TimerGroup *DefaultTimerGroup = nullptr; static TimerGroup *getDefaultTimerGroup() { - TimerGroup *tmp = DefaultTimerGroup; - sys::MemoryFence(); - if (tmp) return tmp; - - sys::SmartScopedLock Lock(*TimerLock); - tmp = DefaultTimerGroup; - if (!tmp) { - tmp = new TimerGroup("misc", "Miscellaneous Ungrouped Timers"); - sys::MemoryFence(); - DefaultTimerGroup = tmp; - } - - return tmp; + static TimerGroup DefaultTimerGroup("misc", "Miscellaneous Ungrouped Timers"); + return &DefaultTimerGroup; } //===----------------------------------------------------------------------===// @@ -309,7 +296,7 @@ void TimerGroup::PrintQueuedTimers(raw_ostream &OS) { // If this is not an collection of ungrouped times, print the total time. // Ungrouped timers don't really make sense to add up. We still print the // TOTAL line to make the percentages make sense. - if (this != DefaultTimerGroup) + if (this != getDefaultTimerGroup()) OS << format(" Total Execution Time: %5.4f seconds (%5.4f wall clock)\n", Total.getProcessTime(), Total.getWallTime()); OS << '\n';