From 2a55acbc1de0b8d1901988ee4f17d5697519c2d2 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 2 Jul 2019 07:10:53 +1000 Subject: gallivm: add compare exchange wrapper This just pulls the wrapper from LLVM for older versions Reviewed-by: Roland Scheidegger --- src/gallium/auxiliary/gallivm/lp_bld.h | 1 - src/gallium/auxiliary/gallivm/lp_bld_misc.cpp | 30 +++++++++++++++++++++++++++ src/gallium/auxiliary/gallivm/lp_bld_misc.h | 9 ++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) (limited to 'src/gallium/auxiliary/gallivm') 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::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 -- cgit v1.2.3