aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Airlie <[email protected]>2019-07-02 07:10:53 +1000
committerDave Airlie <[email protected]>2019-07-07 16:23:32 +1000
commit2a55acbc1de0b8d1901988ee4f17d5697519c2d2 (patch)
tree0a625d7bdc92bf1bfb5c761725f4ba26b3d274fd
parent4f709c86a92e561b4b72f6ace44e1fbf9fae5e67 (diff)
gallivm: add compare exchange wrapper
This just pulls the wrapper from LLVM for older versions Reviewed-by: Roland Scheidegger <[email protected]>
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld.h1
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_misc.cpp30
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_misc.h9
3 files changed, 39 insertions, 1 deletions
diff --git a/src/gallium/auxiliary/gallivm/lp_bld.h b/src/gallium/auxiliary/gallivm/lp_bld.h
index 239c27e3c25..ca23005b808 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld.h
@@ -108,5 +108,4 @@ typedef void *LLVMMCJITMemoryManagerRef;
# define LLVMSetAlignment LLVMSetAlignmentBackport
#endif
-
#endif /* LP_BLD_H */
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
index f307c26d4f7..79d10293e80 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
+++ b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
@@ -804,3 +804,33 @@ lp_is_function(LLVMValueRef v)
return llvm::isa<llvm::Function>(llvm::unwrap(v));
#endif
}
+
+#if HAVE_LLVM < 0x309
+static llvm::AtomicOrdering mapFromLLVMOrdering(LLVMAtomicOrdering Ordering) {
+ switch (Ordering) {
+ case LLVMAtomicOrderingNotAtomic: return llvm::AtomicOrdering::NotAtomic;
+ case LLVMAtomicOrderingUnordered: return llvm::AtomicOrdering::Unordered;
+ case LLVMAtomicOrderingMonotonic: return llvm::AtomicOrdering::Monotonic;
+ case LLVMAtomicOrderingAcquire: return llvm::AtomicOrdering::Acquire;
+ case LLVMAtomicOrderingRelease: return llvm::AtomicOrdering::Release;
+ case LLVMAtomicOrderingAcquireRelease:
+ return llvm::AtomicOrdering::AcquireRelease;
+ case LLVMAtomicOrderingSequentiallyConsistent:
+ return llvm::AtomicOrdering::SequentiallyConsistent;
+ }
+
+ llvm_unreachable("Invalid LLVMAtomicOrdering value!");
+}
+
+LLVMValueRef LLVMBuildAtomicCmpXchg(LLVMBuilderRef B, LLVMValueRef Ptr,
+ LLVMValueRef Cmp, LLVMValueRef New,
+ LLVMAtomicOrdering SuccessOrdering,
+ LLVMAtomicOrdering FailureOrdering,
+ LLVMBool SingleThread)
+{
+ /* LLVM 3.8 doesn't have a second ordering and uses old SynchronizationScope enum */
+ return llvm::wrap(llvm::unwrap(B)->CreateAtomicCmpXchg(llvm::unwrap(Ptr), llvm::unwrap(Cmp),
+ llvm::unwrap(New), mapFromLLVMOrdering(SuccessOrdering),
+ SingleThread ? llvm::SynchronizationScope::SingleThread : llvm::SynchronizationScope::CrossThread));
+}
+#endif
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.h b/src/gallium/auxiliary/gallivm/lp_bld_misc.h
index ca5ba5c44f2..629751502e7 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_misc.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_misc.h
@@ -76,6 +76,15 @@ lp_get_called_value(LLVMValueRef call);
extern bool
lp_is_function(LLVMValueRef v);
+/* LLVM 3.9 introduces this, provide our own for earlier */
+#if HAVE_LLVM < 0x309
+LLVMValueRef LLVMBuildAtomicCmpXchg(LLVMBuilderRef B, LLVMValueRef Ptr,
+ LLVMValueRef Cmp, LLVMValueRef New,
+ LLVMAtomicOrdering SuccessOrdering,
+ LLVMAtomicOrdering FailureOrdering,
+ LLVMBool SingleThread);
+#endif
+
#ifdef __cplusplus
}
#endif