[llvm] r202731 - Revert "[C++11] Replace LLVM atomics with std::atomic."

Benjamin Kramer benny.kra at googlemail.com
Mon Mar 3 10:02:34 PST 2014


Author: d0k
Date: Mon Mar  3 12:02:34 2014
New Revision: 202731

URL: http://llvm.org/viewvc/llvm-project?rev=202731&view=rev
Log:
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

Modified:
    llvm/trunk/include/llvm/ADT/Statistic.h
    llvm/trunk/include/llvm/PassSupport.h
    llvm/trunk/include/llvm/Support/ManagedStatic.h
    llvm/trunk/lib/IR/Attributes.cpp
    llvm/trunk/lib/IR/DiagnosticInfo.cpp
    llvm/trunk/lib/Support/ManagedStatic.cpp
    llvm/trunk/lib/Support/Statistic.cpp
    llvm/trunk/lib/Support/Threading.cpp
    llvm/trunk/lib/Support/Timer.cpp

Modified: llvm/trunk/include/llvm/ADT/Statistic.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/Statistic.h?rev=202731&r1=202730&r2=202731&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/Statistic.h (original)
+++ llvm/trunk/include/llvm/ADT/Statistic.h Mon Mar  3 12:02:34 2014
@@ -26,8 +26,8 @@
 #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;
@@ -36,10 +36,10 @@ class Statistic {
 public:
   const char *Name;
   const char *Desc;
-  std::atomic<unsigned> Value;
+  volatile llvm::sys::cas_flag Value;
   bool Initialized;
 
-  unsigned getValue() const { return Value; }
+  llvm::sys::cas_flag getValue() const { return Value; }
   const char *getName() const { return Name; }
   const char *getDesc() const { return Desc; }
 
@@ -63,54 +63,48 @@ public:
     // 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.
-    ++Value;
+    sys::AtomicIncrement(&Value);
     return init();
   }
 
   unsigned operator++(int) {
     init();
-    unsigned OldValue = Value++;
+    unsigned OldValue = Value;
+    sys::AtomicIncrement(&Value);
     return OldValue;
   }
 
   const Statistic &operator--() {
-    --Value;
+    sys::AtomicDecrement(&Value);
     return init();
   }
 
   unsigned operator--(int) {
     init();
-    unsigned OldValue = Value--;
+    unsigned OldValue = Value;
+    sys::AtomicDecrement(&Value);
     return OldValue;
   }
 
   const Statistic &operator+=(const unsigned &V) {
     if (!V) return *this;
-    Value += V;
+    sys::AtomicAdd(&Value, V);
     return init();
   }
 
   const Statistic &operator-=(const unsigned &V) {
     if (!V) return *this;
-    Value -= V;
+    sys::AtomicAdd(&Value, -V);
     return init();
   }
 
   const Statistic &operator*=(const unsigned &V) {
-    unsigned Original, Result;
-    do {
-      Original = Value;
-      Result = Original * V;
-    } while (!Value.compare_exchange_strong(Original, Result));
+    sys::AtomicMul(&Value, V);
     return init();
   }
 
   const Statistic &operator/=(const unsigned &V) {
-    unsigned Original, Result;
-    do {
-      Original = Value;
-      Result = Original / V;
-    } while (!Value.compare_exchange_strong(Original, Result));
+    sys::AtomicDiv(&Value, V);
     return init();
   }
 
@@ -157,7 +151,7 @@ public:
 protected:
   Statistic &init() {
     bool tmp = Initialized;
-    std::atomic_thread_fence(std::memory_order_seq_cst);
+    sys::MemoryFence();
     if (!tmp) RegisterStatistic();
     TsanHappensAfter(this);
     return *this;
@@ -168,7 +162,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, DESC, {}, 0 }
+  static llvm::Statistic VARNAME = { DEBUG_TYPE, DESC, 0, 0 }
 
 /// \brief Enable the collection and printing of statistics.
 void EnableStatistics();

Modified: llvm/trunk/include/llvm/PassSupport.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/PassSupport.h?rev=202731&r1=202730&r2=202731&view=diff
==============================================================================
--- llvm/trunk/include/llvm/PassSupport.h (original)
+++ llvm/trunk/include/llvm/PassSupport.h Mon Mar  3 12:02:34 2014
@@ -24,8 +24,8 @@
 #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 {
@@ -147,21 +147,21 @@ private:
 };
 
 #define CALL_ONCE_INITIALIZATION(function) \
-  static std::atomic<int> initialized; \
-  int old_val = 0; \
-  if (initialized.compare_exchange_strong(old_val, 1)) { \
+  static volatile sys::cas_flag initialized = 0; \
+  sys::cas_flag old_val = sys::CompareAndSwap(&initialized, 1, 0); \
+  if (old_val == 0) { \
     function(Registry); \
-    std::atomic_thread_fence(std::memory_order_seq_cst); \
+    sys::MemoryFence(); \
     TsanIgnoreWritesBegin(); \
     TsanHappensBefore(&initialized); \
     initialized = 2; \
     TsanIgnoreWritesEnd(); \
   } else { \
-    int tmp = initialized.load(); \
-    std::atomic_thread_fence(std::memory_order_seq_cst); \
+    sys::cas_flag tmp = initialized; \
+    sys::MemoryFence(); \
     while (tmp != 2) { \
-      tmp = initialized.load(); \
-      std::atomic_thread_fence(std::memory_order_seq_cst); \
+      tmp = initialized; \
+      sys::MemoryFence(); \
     } \
   } \
   TsanHappensAfter(&initialized);

Modified: llvm/trunk/include/llvm/Support/ManagedStatic.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ManagedStatic.h?rev=202731&r1=202730&r2=202731&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/ManagedStatic.h (original)
+++ llvm/trunk/include/llvm/Support/ManagedStatic.h Mon Mar  3 12:02:34 2014
@@ -14,9 +14,9 @@
 #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 {
 
@@ -64,8 +64,7 @@ public:
   // Accessors.
   C &operator*() {
     void* tmp = Ptr;
-    if (llvm_is_multithreaded())
-      std::atomic_thread_fence(std::memory_order_seq_cst);
+    if (llvm_is_multithreaded()) sys::MemoryFence();
     if (!tmp) RegisterManagedStatic(object_creator<C>, object_deleter<C>::call);
     TsanHappensAfter(this);
 
@@ -73,8 +72,7 @@ public:
   }
   C *operator->() {
     void* tmp = Ptr;
-    if (llvm_is_multithreaded())
-      std::atomic_thread_fence(std::memory_order_seq_cst);
+    if (llvm_is_multithreaded()) sys::MemoryFence();
     if (!tmp) RegisterManagedStatic(object_creator<C>, object_deleter<C>::call);
     TsanHappensAfter(this);
 
@@ -82,8 +80,7 @@ public:
   }
   const C &operator*() const {
     void* tmp = Ptr;
-    if (llvm_is_multithreaded())
-      std::atomic_thread_fence(std::memory_order_seq_cst);
+    if (llvm_is_multithreaded()) sys::MemoryFence();
     if (!tmp) RegisterManagedStatic(object_creator<C>, object_deleter<C>::call);
     TsanHappensAfter(this);
 
@@ -91,8 +88,7 @@ public:
   }
   const C *operator->() const {
     void* tmp = Ptr;
-    if (llvm_is_multithreaded())
-      std::atomic_thread_fence(std::memory_order_seq_cst);
+    if (llvm_is_multithreaded()) sys::MemoryFence();
     if (!tmp) RegisterManagedStatic(object_creator<C>, object_deleter<C>::call);
     TsanHappensAfter(this);
 

Modified: llvm/trunk/lib/IR/Attributes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Attributes.cpp?rev=202731&r1=202730&r2=202731&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Attributes.cpp (original)
+++ llvm/trunk/lib/IR/Attributes.cpp Mon Mar  3 12:02:34 2014
@@ -18,6 +18,7 @@
 #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"

Modified: llvm/trunk/lib/IR/DiagnosticInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DiagnosticInfo.cpp?rev=202731&r1=202730&r2=202731&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DiagnosticInfo.cpp (original)
+++ llvm/trunk/lib/IR/DiagnosticInfo.cpp Mon Mar  3 12:02:34 2014
@@ -19,14 +19,14 @@
 #include "llvm/IR/Function.h"
 #include "llvm/IR/Instruction.h"
 #include "llvm/IR/Metadata.h"
-#include <atomic>
+#include "llvm/Support/Atomic.h"
 #include <string>
 
 using namespace llvm;
 
 int llvm::getNextAvailablePluginDiagnosticKind() {
-  static std::atomic<int> PluginKindID(DK_FirstPluginKind);
-  return ++PluginKindID;
+  static sys::cas_flag PluginKindID = DK_FirstPluginKind;
+  return (int)sys::AtomicIncrement(&PluginKindID);
 }
 
 DiagnosticInfoInlineAsm::DiagnosticInfoInlineAsm(const Instruction &I,

Modified: llvm/trunk/lib/Support/ManagedStatic.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/ManagedStatic.cpp?rev=202731&r1=202730&r2=202731&view=diff
==============================================================================
--- llvm/trunk/lib/Support/ManagedStatic.cpp (original)
+++ llvm/trunk/lib/Support/ManagedStatic.cpp Mon Mar  3 12:02:34 2014
@@ -13,6 +13,7 @@
 
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Config/config.h"
+#include "llvm/Support/Atomic.h"
 #include <cassert>
 using namespace llvm;
 
@@ -27,7 +28,7 @@ void ManagedStaticBase::RegisterManagedS
       void* tmp = Creator ? Creator() : 0;
 
       TsanHappensBefore(this);
-      std::atomic_thread_fence(std::memory_order_seq_cst);
+      sys::MemoryFence();
 
       // This write is racy against the first read in the ManagedStatic
       // accessors. The race is benign because it does a second read after a

Modified: llvm/trunk/lib/Support/Statistic.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Statistic.cpp?rev=202731&r1=202730&r2=202731&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Statistic.cpp (original)
+++ llvm/trunk/lib/Support/Statistic.cpp Mon Mar  3 12:02:34 2014
@@ -76,7 +76,7 @@ void Statistic::RegisterStatistic() {
       StatInfo->addStatistic(this);
 
     TsanHappensBefore(this);
-    std::atomic_thread_fence(std::memory_order_seq_cst);
+    sys::MemoryFence();
     // Remember we have been registered.
     TsanIgnoreWritesBegin();
     Initialized = true;

Modified: llvm/trunk/lib/Support/Threading.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Threading.cpp?rev=202731&r1=202730&r2=202731&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Threading.cpp (original)
+++ llvm/trunk/lib/Support/Threading.cpp Mon Mar  3 12:02:34 2014
@@ -13,8 +13,8 @@
 
 #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;
@@ -31,7 +31,7 @@ bool llvm::llvm_start_multithreaded() {
 
   // We fence here to ensure that all initialization is complete BEFORE we
   // return from llvm_start_multithreaded().
-  std::atomic_thread_fence(std::memory_order_seq_cst);
+  sys::MemoryFence();
   return true;
 #else
   return false;
@@ -44,7 +44,7 @@ void llvm::llvm_stop_multithreaded() {
 
   // We fence here to insure that all threaded operations are complete BEFORE we
   // return from llvm_stop_multithreaded().
-  std::atomic_thread_fence(std::memory_order_seq_cst);
+  sys::MemoryFence();
 
   multithreaded_mode = false;
   delete global_lock;

Modified: llvm/trunk/lib/Support/Timer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Timer.cpp?rev=202731&r1=202730&r2=202731&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Timer.cpp (original)
+++ llvm/trunk/lib/Support/Timer.cpp Mon Mar  3 12:02:34 2014
@@ -81,14 +81,14 @@ raw_ostream *llvm::CreateInfoOutputFile(
 static TimerGroup *DefaultTimerGroup = 0;
 static TimerGroup *getDefaultTimerGroup() {
   TimerGroup *tmp = DefaultTimerGroup;
-  std::atomic_thread_fence(std::memory_order_seq_cst);
+  sys::MemoryFence();
   if (tmp) return tmp;
   
   llvm_acquire_global_lock();
   tmp = DefaultTimerGroup;
   if (!tmp) {
     tmp = new TimerGroup("Miscellaneous Ungrouped Timers");
-    std::atomic_thread_fence(std::memory_order_seq_cst);
+    sys::MemoryFence();
     DefaultTimerGroup = tmp;
   }
   llvm_release_global_lock();





More information about the llvm-commits mailing list