llvm.org GIT mirror llvm / 7515c71
Revert "[C++11] Replace LLVM atomics with std::atomic." Breaks the MSVC build. DataStream.cpp(44): error C2552: 'llvm::Statistic::Value' : non-aggregates cannot be initialized with initializer list git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202731 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 6 years ago
9 changed file(s) with 41 addition(s) and 49 deletion(s). Raw diff Collapse all Expand all
2525 #ifndef LLVM_ADT_STATISTIC_H
2626 #define LLVM_ADT_STATISTIC_H
2727
28 #include "llvm/Support/Atomic.h"
2829 #include "llvm/Support/Valgrind.h"
29 #include
3030
3131 namespace llvm {
3232 class raw_ostream;
3535 public:
3636 const char *Name;
3737 const char *Desc;
38 std::atomic Value;
38 volatile llvm::sys::cas_flag Value;
3939 bool Initialized;
4040
41 unsigned getValue() const { return Value; }
41 llvm::sys::cas_flag getValue() const { return Value; }
4242 const char *getName() const { return Name; }
4343 const char *getDesc() const { return Desc; }
4444
6262 // atomic operation to update the value safely in the presence of
6363 // concurrent accesses, but not to read the return value, so the
6464 // return value is not thread safe.
65 ++Value;
65 sys::AtomicIncrement(&Value);
6666 return init();
6767 }
6868
6969 unsigned operator++(int) {
7070 init();
71 unsigned OldValue = Value++;
71 unsigned OldValue = Value;
72 sys::AtomicIncrement(&Value);
7273 return OldValue;
7374 }
7475
7576 const Statistic &operator--() {
76 --Value;
77 sys::AtomicDecrement(&Value);
7778 return init();
7879 }
7980
8081 unsigned operator--(int) {
8182 init();
82 unsigned OldValue = Value--;
83 unsigned OldValue = Value;
84 sys::AtomicDecrement(&Value);
8385 return OldValue;
8486 }
8587
8688 const Statistic &operator+=(const unsigned &V) {
8789 if (!V) return *this;
88 Value += V;
90 sys::AtomicAdd(&Value, V);
8991 return init();
9092 }
9193
9294 const Statistic &operator-=(const unsigned &V) {
9395 if (!V) return *this;
94 Value -= V;
96 sys::AtomicAdd(&Value, -V);
9597 return init();
9698 }
9799
98100 const Statistic &operator*=(const unsigned &V) {
99 unsigned Original, Result;
100 do {
101 Original = Value;
102 Result = Original * V;
103 } while (!Value.compare_exchange_strong(Original, Result));
101 sys::AtomicMul(&Value, V);
104102 return init();
105103 }
106104
107105 const Statistic &operator/=(const unsigned &V) {
108 unsigned Original, Result;
109 do {
110 Original = Value;
111 Result = Original / V;
112 } while (!Value.compare_exchange_strong(Original, Result));
106 sys::AtomicDiv(&Value, V);
113107 return init();
114108 }
115109
156150 protected:
157151 Statistic &init() {
158152 bool tmp = Initialized;
159 std::atomic_thread_fence(std::memory_order_seq_cst);
153 sys::MemoryFence();
160154 if (!tmp) RegisterStatistic();
161155 TsanHappensAfter(this);
162156 return *this;
167161 // STATISTIC - A macro to make definition of statistics really simple. This
168162 // automatically passes the DEBUG_TYPE of the file into the statistic.
169163 #define STATISTIC(VARNAME, DESC) \
170 static llvm::Statistic VARNAME = { DEBUG_TYPE, DESC, {}, 0 }
164 static llvm::Statistic VARNAME = { DEBUG_TYPE, DESC, 0, 0 }
171165
172166 /// \brief Enable the collection and printing of statistics.
173167 void EnableStatistics();
2323 #include "Pass.h"
2424 #include "llvm/InitializePasses.h"
2525 #include "llvm/PassRegistry.h"
26 #include "llvm/Support/Atomic.h"
2627 #include "llvm/Support/Valgrind.h"
27 #include
2828 #include
2929
3030 namespace llvm {
146146 };
147147
148148 #define CALL_ONCE_INITIALIZATION(function) \
149 static std::atomic initialized; \
150 int old_val = 0; \
151 if (initialized.compare_exchange_strong(old_val, 1)) { \
149 static volatile sys::cas_flag initialized = 0; \
150 sys::cas_flag old_val = sys::CompareAndSwap(&initialized, 1, 0); \
151 if (old_val == 0) { \
152152 function(Registry); \
153 std::atomic_thread_fence(std::memory_order_seq_cst); \
153 sys::MemoryFence(); \
154154 TsanIgnoreWritesBegin(); \
155155 TsanHappensBefore(&initialized); \
156156 initialized = 2; \
157157 TsanIgnoreWritesEnd(); \
158158 } else { \
159 int tmp = initialized.load(); \
160 std::atomic_thread_fence(std::memory_order_seq_cst); \
159 sys::cas_flag tmp = initialized; \
160 sys::MemoryFence(); \
161161 while (tmp != 2) { \
162 tmp = initialized.load(); \
163 std::atomic_thread_fence(std::memory_order_seq_cst); \
162 tmp = initialized; \
163 sys::MemoryFence(); \
164164 } \
165165 } \
166166 TsanHappensAfter(&initialized);
1313 #ifndef LLVM_SUPPORT_MANAGED_STATIC_H
1414 #define LLVM_SUPPORT_MANAGED_STATIC_H
1515
16 #include "llvm/Support/Atomic.h"
1617 #include "llvm/Support/Threading.h"
1718 #include "llvm/Support/Valgrind.h"
18 #include
1919
2020 namespace llvm {
2121
6363 // Accessors.
6464 C &operator*() {
6565 void* tmp = Ptr;
66 if (llvm_is_multithreaded())
67 std::atomic_thread_fence(std::memory_order_seq_cst);
66 if (llvm_is_multithreaded()) sys::MemoryFence();
6867 if (!tmp) RegisterManagedStatic(object_creator, object_deleter::call);
6968 TsanHappensAfter(this);
7069
7271 }
7372 C *operator->() {
7473 void* tmp = Ptr;
75 if (llvm_is_multithreaded())
76 std::atomic_thread_fence(std::memory_order_seq_cst);
74 if (llvm_is_multithreaded()) sys::MemoryFence();
7775 if (!tmp) RegisterManagedStatic(object_creator, object_deleter::call);
7876 TsanHappensAfter(this);
7977
8179 }
8280 const C &operator*() const {
8381 void* tmp = Ptr;
84 if (llvm_is_multithreaded())
85 std::atomic_thread_fence(std::memory_order_seq_cst);
82 if (llvm_is_multithreaded()) sys::MemoryFence();
8683 if (!tmp) RegisterManagedStatic(object_creator, object_deleter::call);
8784 TsanHappensAfter(this);
8885
9087 }
9188 const C *operator->() const {
9289 void* tmp = Ptr;
93 if (llvm_is_multithreaded())
94 std::atomic_thread_fence(std::memory_order_seq_cst);
90 if (llvm_is_multithreaded()) sys::MemoryFence();
9591 if (!tmp) RegisterManagedStatic(object_creator, object_deleter::call);
9692 TsanHappensAfter(this);
9793
1717 #include "LLVMContextImpl.h"
1818 #include "llvm/ADT/StringExtras.h"
1919 #include "llvm/IR/Type.h"
20 #include "llvm/Support/Atomic.h"
2021 #include "llvm/Support/Debug.h"
2122 #include "llvm/Support/ManagedStatic.h"
2223 #include "llvm/Support/Mutex.h"
1818 #include "llvm/IR/Function.h"
1919 #include "llvm/IR/Instruction.h"
2020 #include "llvm/IR/Metadata.h"
21 #include
21 #include "llvm/Support/Atomic.h"
2222 #include
2323
2424 using namespace llvm;
2525
2626 int llvm::getNextAvailablePluginDiagnosticKind() {
27 static std::atomic PluginKindID(DK_FirstPluginKind);
28 return ++PluginKindID;
27 static sys::cas_flag PluginKindID = DK_FirstPluginKind;
28 return (int)sys::AtomicIncrement(&PluginKindID);
2929 }
3030
3131 DiagnosticInfoInlineAsm::DiagnosticInfoInlineAsm(const Instruction &I,
1212
1313 #include "llvm/Support/ManagedStatic.h"
1414 #include "llvm/Config/config.h"
15 #include "llvm/Support/Atomic.h"
1516 #include
1617 using namespace llvm;
1718
2627 void* tmp = Creator ? Creator() : 0;
2728
2829 TsanHappensBefore(this);
29 std::atomic_thread_fence(std::memory_order_seq_cst);
30 sys::MemoryFence();
3031
3132 // This write is racy against the first read in the ManagedStatic
3233 // accessors. The race is benign because it does a second read after a
7575 StatInfo->addStatistic(this);
7676
7777 TsanHappensBefore(this);
78 std::atomic_thread_fence(std::memory_order_seq_cst);
78 sys::MemoryFence();
7979 // Remember we have been registered.
8080 TsanIgnoreWritesBegin();
8181 Initialized = true;
1212
1313 #include "llvm/Support/Threading.h"
1414 #include "llvm/Config/config.h"
15 #include "llvm/Support/Atomic.h"
1516 #include "llvm/Support/Mutex.h"
16 #include
1717 #include
1818
1919 using namespace llvm;
3030
3131 // We fence here to ensure that all initialization is complete BEFORE we
3232 // return from llvm_start_multithreaded().
33 std::atomic_thread_fence(std::memory_order_seq_cst);
33 sys::MemoryFence();
3434 return true;
3535 #else
3636 return false;
4343
4444 // We fence here to insure that all threaded operations are complete BEFORE we
4545 // return from llvm_stop_multithreaded().
46 std::atomic_thread_fence(std::memory_order_seq_cst);
46 sys::MemoryFence();
4747
4848 multithreaded_mode = false;
4949 delete global_lock;
8080 static TimerGroup *DefaultTimerGroup = 0;
8181 static TimerGroup *getDefaultTimerGroup() {
8282 TimerGroup *tmp = DefaultTimerGroup;
83 std::atomic_thread_fence(std::memory_order_seq_cst);
83 sys::MemoryFence();
8484 if (tmp) return tmp;
8585
8686 llvm_acquire_global_lock();
8787 tmp = DefaultTimerGroup;
8888 if (!tmp) {
8989 tmp = new TimerGroup("Miscellaneous Ungrouped Timers");
90 std::atomic_thread_fence(std::memory_order_seq_cst);
90 sys::MemoryFence();
9191 DefaultTimerGroup = tmp;
9292 }
9393 llvm_release_global_lock();