gallivm: add compare exchange wrapper
authorDave Airlie <airlied@redhat.com>
Mon, 1 Jul 2019 21:10:53 +0000 (07:10 +1000)
committerDave Airlie <airlied@redhat.com>
Sun, 7 Jul 2019 06:23:32 +0000 (16:23 +1000)
This just pulls the wrapper from LLVM for older versions

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
src/gallium/auxiliary/gallivm/lp_bld.h
src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
src/gallium/auxiliary/gallivm/lp_bld_misc.h

index 239c27e3c255dc8ab51dc2557947c56fdac81d9a..ca23005b808229a733a5d092cffab660b8e2dff9 100644 (file)
@@ -108,5 +108,4 @@ typedef void *LLVMMCJITMemoryManagerRef;
 #  define LLVMSetAlignment LLVMSetAlignmentBackport
 #endif
 
-
 #endif /* LP_BLD_H */
index f307c26d4f7429204687b95adc68a619cb9d5a40..79d10293e8006110a104f3c698d57977a96a11b0 100644 (file)
@@ -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
index ca5ba5c44f2ba3e15c7a1610e53340e669cfb0e2..629751502e796bc2c85d4f4104152a77397a3d83 100644 (file)
@@ -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