From: Dave Airlie Date: Mon, 1 Jul 2019 21:10:53 +0000 (+1000) Subject: gallivm: add compare exchange wrapper X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2a55acbc1de0b8d1901988ee4f17d5697519c2d2;p=mesa.git gallivm: add compare exchange wrapper This just pulls the wrapper from LLVM for older versions Reviewed-by: Roland Scheidegger --- 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