summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/ADT/Statistic.h11
-rw-r--r--llvm/lib/Support/Statistic.cpp8
2 files changed, 6 insertions, 13 deletions
diff --git a/llvm/include/llvm/ADT/Statistic.h b/llvm/include/llvm/ADT/Statistic.h
index d5ebba409c3..6d478b14015 100644
--- a/llvm/include/llvm/ADT/Statistic.h
+++ b/llvm/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 <atomic>
#include <memory>
@@ -42,7 +41,7 @@ public:
const char *Name;
const char *Desc;
std::atomic<unsigned> Value;
- bool Initialized;
+ std::atomic<bool> 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/llvm/lib/Support/Statistic.cpp b/llvm/lib/Support/Statistic.cpp
index 544ae2d0983..370274dc299 100644
--- a/llvm/lib/Support/Statistic.cpp
+++ b/llvm/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<true> 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);
}
}
OpenPOWER on IntegriCloud