summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-06-23 18:01:04 +0000
committerOwen Anderson <resistor@mac.com>2009-06-23 18:01:04 +0000
commit0de9953e888c30e0a01df90c972b1f2e2dce1614 (patch)
tree7998d72beb0e95b63ad0aa47e6649ab4ed0be827
parentbb3231f7c491ce8d8945833a7515a25027e1c8a7 (diff)
downloadllvm-0de9953e888c30e0a01df90c972b1f2e2dce1614.tar.gz
llvm-0de9953e888c30e0a01df90c972b1f2e2dce1614.tar.bz2
llvm-0de9953e888c30e0a01df90c972b1f2e2dce1614.tar.xz
Label the existing atomic functions as 32-bit specific, and add a 64-bit one that will be useful in
the near future. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73971 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/System/Atomic.h15
-rw-r--r--include/llvm/Type.h8
-rw-r--r--lib/System/Atomic.cpp26
-rw-r--r--lib/VMCore/Mangler.cpp2
4 files changed, 32 insertions, 19 deletions
diff --git a/include/llvm/System/Atomic.h b/include/llvm/System/Atomic.h
index c4049d40da..a94ad2d92e 100644
--- a/include/llvm/System/Atomic.h
+++ b/include/llvm/System/Atomic.h
@@ -20,13 +20,14 @@ namespace llvm {
namespace sys {
void MemoryFence();
- typedef uint32_t cas_flag;
- cas_flag CompareAndSwap(volatile cas_flag* ptr,
- cas_flag new_value,
- cas_flag old_value);
- cas_flag AtomicIncrement(volatile cas_flag* ptr);
- cas_flag AtomicDecrement(volatile cas_flag* ptr);
- cas_flag AtomicAdd(volatile cas_flag* ptr, cas_flag val);
+ uint32_t CompareAndSwap32(volatile uint32_t* ptr,
+ uint32_t new_value,
+ uint32_t old_value);
+ uint32_t AtomicIncrement32(volatile uint32_t* ptr);
+ uint32_t AtomicDecrement32(volatile uint32_t* ptr);
+ uint32_t AtomicAdd32(volatile uint32_t* ptr, uint32_t val);
+
+ uint64_t AtomicAdd64(volatile uint64_t* ptr, uint64_t val);
}
}
diff --git a/include/llvm/Type.h b/include/llvm/Type.h
index d439233d8c..8c07b3e2a0 100644
--- a/include/llvm/Type.h
+++ b/include/llvm/Type.h
@@ -103,7 +103,7 @@ private:
/// has no AbstractTypeUsers, the type is deleted. This is only sensical for
/// derived types.
///
- mutable sys::cas_flag RefCount;
+ mutable uint32_t RefCount;
const Type *getForwardedTypeInternal() const;
@@ -338,7 +338,7 @@ public:
void addRef() const {
assert(isAbstract() && "Cannot add a reference to a non-abstract type!");
- sys::AtomicIncrement(&RefCount);
+ sys::AtomicIncrement32(&RefCount);
}
void dropRef() const {
@@ -347,8 +347,8 @@ public:
// If this is the last PATypeHolder using this object, and there are no
// PATypeHandles using it, the type is dead, delete it now.
- sys::cas_flag OldCount = sys::AtomicDecrement(&RefCount);
- if (OldCount == 0 && AbstractTypeUsers.empty())
+ uint32_t Count = sys::AtomicDecrement32(&RefCount);
+ if (Count == 0 && AbstractTypeUsers.empty())
this->destroy();
}
diff --git a/lib/System/Atomic.cpp b/lib/System/Atomic.cpp
index 6e751a30d4..65e14697ed 100644
--- a/lib/System/Atomic.cpp
+++ b/lib/System/Atomic.cpp
@@ -35,11 +35,11 @@ void sys::MemoryFence() {
#endif
}
-sys::cas_flag sys::CompareAndSwap(volatile sys::cas_flag* ptr,
- sys::cas_flag new_value,
- sys::cas_flag old_value) {
+uint32_t sys::CompareAndSwap32(volatile uint32_t* ptr,
+ uint32_t new_value,
+ uint32_t old_value) {
#if LLVM_MULTITHREADED==0
- sys::cas_flag result = *ptr;
+ uint32_t result = *ptr;
if (result == old_value)
*ptr = new_value;
return result;
@@ -52,7 +52,7 @@ sys::cas_flag sys::CompareAndSwap(volatile sys::cas_flag* ptr,
#endif
}
-sys::cas_flag sys::AtomicIncrement(volatile sys::cas_flag* ptr) {
+uint32_t sys::AtomicIncrement32(volatile uint32_t* ptr) {
#if LLVM_MULTITHREADED==0
++(*ptr);
return *ptr;
@@ -65,7 +65,7 @@ sys::cas_flag sys::AtomicIncrement(volatile sys::cas_flag* ptr) {
#endif
}
-sys::cas_flag sys::AtomicDecrement(volatile sys::cas_flag* ptr) {
+uint32_t sys::AtomicDecrement32(volatile uint32_t* ptr) {
#if LLVM_MULTITHREADED==0
--(*ptr);
return *ptr;
@@ -78,7 +78,7 @@ sys::cas_flag sys::AtomicDecrement(volatile sys::cas_flag* ptr) {
#endif
}
-sys::cas_flag sys::AtomicAdd(volatile sys::cas_flag* ptr, sys::cas_flag val) {
+uint32_t sys::AtomicAdd32(volatile uint32_t* ptr, uint32_t val) {
#if LLVM_MULTITHREADED==0
*ptr += val;
return *ptr;
@@ -91,4 +91,16 @@ sys::cas_flag sys::AtomicAdd(volatile sys::cas_flag* ptr, sys::cas_flag val) {
#endif
}
+uint64_t sys::AtomicAdd64(volatile uint64_t* ptr, uint64_t val) {
+#if LLVM_MULTITHREADED==0
+ *ptr += val;
+ return *ptr;
+#elif defined(__GNUC__)
+ return __sync_add_and_fetch(ptr, val);
+#elif defined(_MSC_VER)
+ return InterlockedAdd64(ptr, val);
+#else
+# error No atomic add implementation for your platform!
+#endif
+}
diff --git a/lib/VMCore/Mangler.cpp b/lib/VMCore/Mangler.cpp
index 1a68b89054..0f6f216ceb 100644
--- a/lib/VMCore/Mangler.cpp
+++ b/lib/VMCore/Mangler.cpp
@@ -168,7 +168,7 @@ std::string Mangler::getValueName(const GlobalValue *GV, const char * Suffix) {
static uint32_t GlobalID = 0;
unsigned OldID = GlobalID;
- sys::AtomicIncrement(&GlobalID);
+ sys::AtomicIncrement32(&GlobalID);
Name = "__unnamed_" + utostr(TypeUniqueID) + "_" + utostr(OldID);
} else {