From 38d1af6c06b47c825a806e9f8497a52f68de105f Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Thu, 1 Feb 2018 20:28:33 +0000 Subject: [PATCH] [ADT] Replace sys::MemoryFence with standard atomics. This is a bit faster in theory, in practice it's cold code that's only active in !NDEBUG, so it probably doesn't make a difference. This is one of the last users of our homegrown Atomic.h. llvm-svn: 323999 --- include/llvm/ADT/Statistic.h | 11 ++++------- lib/Support/Statistic.cpp | 8 ++------ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/include/llvm/ADT/Statistic.h b/include/llvm/ADT/Statistic.h index d5ebba409c3..6d478b14015 100644 --- a/include/llvm/ADT/Statistic.h +++ b/include/llvm/ADT/Statistic.h @@ -26,7 +26,6 @@ #ifndef LLVM_ADT_STATISTIC_H #define LLVM_ADT_STATISTIC_H -#include "llvm/Support/Atomic.h" #include "llvm/Support/Compiler.h" #include #include @@ -42,7 +41,7 @@ public: const char *Name; const char *Desc; std::atomic Value; - bool Initialized; + std::atomic Initialized; unsigned getValue() const { return Value.load(std::memory_order_relaxed); } const char *getDebugType() const { return DebugType; } @@ -147,10 +146,8 @@ public: protected: Statistic &init() { - bool tmp = Initialized; - sys::MemoryFence(); - if (!tmp) RegisterStatistic(); - TsanHappensAfter(this); + if (!Initialized.load(std::memory_order_acquire)) + RegisterStatistic(); return *this; } @@ -160,7 +157,7 @@ protected: // STATISTIC - A macro to make definition of statistics really simple. This // automatically passes the DEBUG_TYPE of the file into the statistic. #define STATISTIC(VARNAME, DESC) \ - static llvm::Statistic VARNAME = {DEBUG_TYPE, #VARNAME, DESC, {0}, false} + static llvm::Statistic VARNAME = {DEBUG_TYPE, #VARNAME, DESC, {0}, {false}} /// \brief Enable the collection and printing of statistics. void EnableStatistics(bool PrintOnExit = true); diff --git a/lib/Support/Statistic.cpp b/lib/Support/Statistic.cpp index 544ae2d0983..370274dc299 100644 --- a/lib/Support/Statistic.cpp +++ b/lib/Support/Statistic.cpp @@ -82,16 +82,12 @@ void Statistic::RegisterStatistic() { // If stats are enabled, inform StatInfo that this statistic should be // printed. sys::SmartScopedLock Writer(*StatLock); - if (!Initialized) { + if (!Initialized.load(std::memory_order_relaxed)) { if (Stats || Enabled) StatInfo->addStatistic(this); - TsanHappensBefore(this); - sys::MemoryFence(); // Remember we have been registered. - TsanIgnoreWritesBegin(); - Initialized = true; - TsanIgnoreWritesEnd(); + Initialized.store(true, std::memory_order_release); } }