#ifndef LLVM_ADT_STATISTIC_H
#define LLVM_ADT_STATISTIC_H
-#include "llvm/Support/Atomic.h"
#include "llvm/Support/Valgrind.h"
+#include <atomic>
namespace llvm {
class raw_ostream;
public:
const char *Name;
const char *Desc;
- volatile llvm::sys::cas_flag Value;
+ std::atomic<unsigned> Value;
bool Initialized;
- llvm::sys::cas_flag getValue() const { return Value; }
+ unsigned getValue() const { return Value; }
const char *getName() const { return Name; }
const char *getDesc() const { return Desc; }
// atomic operation to update the value safely in the presence of
// concurrent accesses, but not to read the return value, so the
// return value is not thread safe.
- sys::AtomicIncrement(&Value);
+ ++Value;
return init();
}
unsigned operator++(int) {
init();
- unsigned OldValue = Value;
- sys::AtomicIncrement(&Value);
+ unsigned OldValue = Value++;
return OldValue;
}
const Statistic &operator--() {
- sys::AtomicDecrement(&Value);
+ --Value;
return init();
}
unsigned operator--(int) {
init();
- unsigned OldValue = Value;
- sys::AtomicDecrement(&Value);
+ unsigned OldValue = Value--;
return OldValue;
}
const Statistic &operator+=(const unsigned &V) {
if (!V) return *this;
- sys::AtomicAdd(&Value, V);
+ Value += V;
return init();
}
const Statistic &operator-=(const unsigned &V) {
if (!V) return *this;
- sys::AtomicAdd(&Value, -V);
+ Value -= V;
return init();
}
const Statistic &operator*=(const unsigned &V) {
- sys::AtomicMul(&Value, V);
+ unsigned Original, Result;
+ do {
+ Original = Value;
+ Result = Original * V;
+ } while (!Value.compare_exchange_strong(Original, Result));
return init();
}
const Statistic &operator/=(const unsigned &V) {
- sys::AtomicDiv(&Value, V);
+ unsigned Original, Result;
+ do {
+ Original = Value;
+ Result = Original / V;
+ } while (!Value.compare_exchange_strong(Original, Result));
return init();
}
protected:
Statistic &init() {
bool tmp = Initialized;
- sys::MemoryFence();
+ std::atomic_thread_fence(std::memory_order_seq_cst);
if (!tmp) RegisterStatistic();
TsanHappensAfter(this);
return *this;
// 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, DESC, 0, 0 }
+ static llvm::Statistic VARNAME = { DEBUG_TYPE, DESC, {}, 0 }
/// \brief Enable the collection and printing of statistics.
void EnableStatistics();
#include "Pass.h"
#include "llvm/InitializePasses.h"
#include "llvm/PassRegistry.h"
-#include "llvm/Support/Atomic.h"
#include "llvm/Support/Valgrind.h"
+#include <atomic>
#include <vector>
namespace llvm {
};
#define CALL_ONCE_INITIALIZATION(function) \
- static volatile sys::cas_flag initialized = 0; \
- sys::cas_flag old_val = sys::CompareAndSwap(&initialized, 1, 0); \
- if (old_val == 0) { \
+ static std::atomic<int> initialized; \
+ int old_val = 0; \
+ if (initialized.compare_exchange_strong(old_val, 1)) { \
function(Registry); \
- sys::MemoryFence(); \
+ std::atomic_thread_fence(std::memory_order_seq_cst); \
TsanIgnoreWritesBegin(); \
TsanHappensBefore(&initialized); \
initialized = 2; \
TsanIgnoreWritesEnd(); \
} else { \
- sys::cas_flag tmp = initialized; \
- sys::MemoryFence(); \
+ int tmp = initialized.load(); \
+ std::atomic_thread_fence(std::memory_order_seq_cst); \
while (tmp != 2) { \
- tmp = initialized; \
- sys::MemoryFence(); \
+ tmp = initialized.load(); \
+ std::atomic_thread_fence(std::memory_order_seq_cst); \
} \
} \
TsanHappensAfter(&initialized);
#ifndef LLVM_SUPPORT_MANAGED_STATIC_H
#define LLVM_SUPPORT_MANAGED_STATIC_H
-#include "llvm/Support/Atomic.h"
#include "llvm/Support/Threading.h"
#include "llvm/Support/Valgrind.h"
+#include <atomic>
namespace llvm {
// Accessors.
C &operator*() {
void* tmp = Ptr;
- if (llvm_is_multithreaded()) sys::MemoryFence();
+ if (llvm_is_multithreaded())
+ std::atomic_thread_fence(std::memory_order_seq_cst);
if (!tmp) RegisterManagedStatic(object_creator<C>, object_deleter<C>::call);
TsanHappensAfter(this);
}
C *operator->() {
void* tmp = Ptr;
- if (llvm_is_multithreaded()) sys::MemoryFence();
+ if (llvm_is_multithreaded())
+ std::atomic_thread_fence(std::memory_order_seq_cst);
if (!tmp) RegisterManagedStatic(object_creator<C>, object_deleter<C>::call);
TsanHappensAfter(this);
}
const C &operator*() const {
void* tmp = Ptr;
- if (llvm_is_multithreaded()) sys::MemoryFence();
+ if (llvm_is_multithreaded())
+ std::atomic_thread_fence(std::memory_order_seq_cst);
if (!tmp) RegisterManagedStatic(object_creator<C>, object_deleter<C>::call);
TsanHappensAfter(this);
}
const C *operator->() const {
void* tmp = Ptr;
- if (llvm_is_multithreaded()) sys::MemoryFence();
+ if (llvm_is_multithreaded())
+ std::atomic_thread_fence(std::memory_order_seq_cst);
if (!tmp) RegisterManagedStatic(object_creator<C>, object_deleter<C>::call);
TsanHappensAfter(this);
#include "LLVMContextImpl.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/IR/Type.h"
-#include "llvm/Support/Atomic.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Mutex.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Metadata.h"
-#include "llvm/Support/Atomic.h"
+#include <atomic>
#include <string>
using namespace llvm;
int llvm::getNextAvailablePluginDiagnosticKind() {
- static sys::cas_flag PluginKindID = DK_FirstPluginKind;
- return (int)sys::AtomicIncrement(&PluginKindID);
+ static std::atomic<int> PluginKindID(DK_FirstPluginKind);
+ return ++PluginKindID;
}
DiagnosticInfoInlineAsm::DiagnosticInfoInlineAsm(const Instruction &I,
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Config/config.h"
-#include "llvm/Support/Atomic.h"
#include <cassert>
using namespace llvm;
void* tmp = Creator ? Creator() : 0;
TsanHappensBefore(this);
- sys::MemoryFence();
+ std::atomic_thread_fence(std::memory_order_seq_cst);
// This write is racy against the first read in the ManagedStatic
// accessors. The race is benign because it does a second read after a
StatInfo->addStatistic(this);
TsanHappensBefore(this);
- sys::MemoryFence();
+ std::atomic_thread_fence(std::memory_order_seq_cst);
// Remember we have been registered.
TsanIgnoreWritesBegin();
Initialized = true;
#include "llvm/Support/Threading.h"
#include "llvm/Config/config.h"
-#include "llvm/Support/Atomic.h"
#include "llvm/Support/Mutex.h"
+#include <atomic>
#include <cassert>
using namespace llvm;
// We fence here to ensure that all initialization is complete BEFORE we
// return from llvm_start_multithreaded().
- sys::MemoryFence();
+ std::atomic_thread_fence(std::memory_order_seq_cst);
return true;
#else
return false;
// We fence here to insure that all threaded operations are complete BEFORE we
// return from llvm_stop_multithreaded().
- sys::MemoryFence();
+ std::atomic_thread_fence(std::memory_order_seq_cst);
multithreaded_mode = false;
delete global_lock;
static TimerGroup *DefaultTimerGroup = 0;
static TimerGroup *getDefaultTimerGroup() {
TimerGroup *tmp = DefaultTimerGroup;
- sys::MemoryFence();
+ std::atomic_thread_fence(std::memory_order_seq_cst);
if (tmp) return tmp;
llvm_acquire_global_lock();
tmp = DefaultTimerGroup;
if (!tmp) {
tmp = new TimerGroup("Miscellaneous Ungrouped Timers");
- sys::MemoryFence();
+ std::atomic_thread_fence(std::memory_order_seq_cst);
DefaultTimerGroup = tmp;
}
llvm_release_global_lock();