[llvm] dfe12b3 - [C API] Support uinc_wrap/udec_wrap in atomicrmw when accessing the bin op (#87163)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 15 18:37:58 PDT 2024
Author: Benji Smith
Date: 2024-04-16T10:37:55+09:00
New Revision: dfe12b3fd193318403622a8ae51e0362c27502d1
URL: https://github.com/llvm/llvm-project/commit/dfe12b3fd193318403622a8ae51e0362c27502d1
DIFF: https://github.com/llvm/llvm-project/commit/dfe12b3fd193318403622a8ae51e0362c27502d1.diff
LOG: [C API] Support uinc_wrap/udec_wrap in atomicrmw when accessing the bin op (#87163)
These previously were added in the C++ API in
778cf5431cafc243f81dd5c8cbd27701ff7f9120, but without updating the enum
in the C API or mapping functions.
Corresponding tests for all current atomicrmw bin ops have been added as
well.
Added:
Modified:
llvm/docs/ReleaseNotes.rst
llvm/include/llvm-c/Core.h
llvm/lib/IR/Core.cpp
llvm/test/Bindings/llvm-c/atomics.ll
Removed:
################################################################################
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 11add9274a7a07..76ef6ceb940780 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -149,6 +149,9 @@ Changes to the C API
* Deprecated ``LLVMConstNUWNeg`` and ``LLVMBuildNUWNeg``.
+* Added ``LLVMAtomicRMWBinOpUIncWrap`` and ``LLVMAtomicRMWBinOpUDecWrap`` to
+ ``LLVMAtomicRMWBinOp`` enum for AtomicRMW instructions.
+
Changes to the CodeGen infrastructure
-------------------------------------
diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h
index 6be5957ce61033..0b03f3b36fcdd3 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/include/llvm-c/Core.h
@@ -361,35 +361,39 @@ typedef enum {
} LLVMAtomicOrdering;
typedef enum {
- LLVMAtomicRMWBinOpXchg, /**< Set the new value and return the one old */
- LLVMAtomicRMWBinOpAdd, /**< Add a value and return the old one */
- LLVMAtomicRMWBinOpSub, /**< Subtract a value and return the old one */
- LLVMAtomicRMWBinOpAnd, /**< And a value and return the old one */
- LLVMAtomicRMWBinOpNand, /**< Not-And a value and return the old one */
- LLVMAtomicRMWBinOpOr, /**< OR a value and return the old one */
- LLVMAtomicRMWBinOpXor, /**< Xor a value and return the old one */
- LLVMAtomicRMWBinOpMax, /**< Sets the value if it's greater than the
- original using a signed comparison and return
- the old one */
- LLVMAtomicRMWBinOpMin, /**< Sets the value if it's Smaller than the
- original using a signed comparison and return
- the old one */
- LLVMAtomicRMWBinOpUMax, /**< Sets the value if it's greater than the
- original using an unsigned comparison and return
- the old one */
- LLVMAtomicRMWBinOpUMin, /**< Sets the value if it's greater than the
- original using an unsigned comparison and return
- the old one */
- LLVMAtomicRMWBinOpFAdd, /**< Add a floating point value and return the
- old one */
- LLVMAtomicRMWBinOpFSub, /**< Subtract a floating point value and return the
+ LLVMAtomicRMWBinOpXchg, /**< Set the new value and return the one old */
+ LLVMAtomicRMWBinOpAdd, /**< Add a value and return the old one */
+ LLVMAtomicRMWBinOpSub, /**< Subtract a value and return the old one */
+ LLVMAtomicRMWBinOpAnd, /**< And a value and return the old one */
+ LLVMAtomicRMWBinOpNand, /**< Not-And a value and return the old one */
+ LLVMAtomicRMWBinOpOr, /**< OR a value and return the old one */
+ LLVMAtomicRMWBinOpXor, /**< Xor a value and return the old one */
+ LLVMAtomicRMWBinOpMax, /**< Sets the value if it's greater than the
+ original using a signed comparison and return
+ the old one */
+ LLVMAtomicRMWBinOpMin, /**< Sets the value if it's Smaller than the
+ original using a signed comparison and return
+ the old one */
+ LLVMAtomicRMWBinOpUMax, /**< Sets the value if it's greater than the
+ original using an unsigned comparison and return
+ the old one */
+ LLVMAtomicRMWBinOpUMin, /**< Sets the value if it's greater than the
+ original using an unsigned comparison and return
+ the old one */
+ LLVMAtomicRMWBinOpFAdd, /**< Add a floating point value and return the
old one */
- LLVMAtomicRMWBinOpFMax, /**< Sets the value if it's greater than the
- original using an floating point comparison and
- return the old one */
- LLVMAtomicRMWBinOpFMin, /**< Sets the value if it's smaller than the
- original using an floating point comparison and
- return the old one */
+ LLVMAtomicRMWBinOpFSub, /**< Subtract a floating point value and return the
+ old one */
+ LLVMAtomicRMWBinOpFMax, /**< Sets the value if it's greater than the
+ original using an floating point comparison and
+ return the old one */
+ LLVMAtomicRMWBinOpFMin, /**< Sets the value if it's smaller than the
+ original using an floating point comparison and
+ return the old one */
+ LLVMAtomicRMWBinOpUIncWrap, /**< Increments the value, wrapping back to zero
+ when incremented above input value */
+ LLVMAtomicRMWBinOpUDecWrap, /**< Decrements the value, wrapping back to
+ the input value when decremented below zero */
} LLVMAtomicRMWBinOp;
typedef enum {
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index 8ce9c5ca63bede..6aff94f39d9c0c 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -3769,6 +3769,10 @@ static AtomicRMWInst::BinOp mapFromLLVMRMWBinOp(LLVMAtomicRMWBinOp BinOp) {
case LLVMAtomicRMWBinOpFSub: return AtomicRMWInst::FSub;
case LLVMAtomicRMWBinOpFMax: return AtomicRMWInst::FMax;
case LLVMAtomicRMWBinOpFMin: return AtomicRMWInst::FMin;
+ case LLVMAtomicRMWBinOpUIncWrap:
+ return AtomicRMWInst::UIncWrap;
+ case LLVMAtomicRMWBinOpUDecWrap:
+ return AtomicRMWInst::UDecWrap;
}
llvm_unreachable("Invalid LLVMAtomicRMWBinOp value!");
@@ -3791,6 +3795,10 @@ static LLVMAtomicRMWBinOp mapToLLVMRMWBinOp(AtomicRMWInst::BinOp BinOp) {
case AtomicRMWInst::FSub: return LLVMAtomicRMWBinOpFSub;
case AtomicRMWInst::FMax: return LLVMAtomicRMWBinOpFMax;
case AtomicRMWInst::FMin: return LLVMAtomicRMWBinOpFMin;
+ case AtomicRMWInst::UIncWrap:
+ return LLVMAtomicRMWBinOpUIncWrap;
+ case AtomicRMWInst::UDecWrap:
+ return LLVMAtomicRMWBinOpUDecWrap;
default: break;
}
diff --git a/llvm/test/Bindings/llvm-c/atomics.ll b/llvm/test/Bindings/llvm-c/atomics.ll
index e64a29944ef9df..162368c9d98d0e 100644
--- a/llvm/test/Bindings/llvm-c/atomics.ll
+++ b/llvm/test/Bindings/llvm-c/atomics.ll
@@ -36,6 +36,31 @@ define void @atomic_load_store(ptr %word) {
ret void
}
+define void @atomic_rmw_ops(ptr %p, i32 %i, float %f) {
+ ; Test all atomicrmw operations
+ %a.xchg = atomicrmw xchg ptr %p, i32 %i acq_rel, align 8
+ %a.add = atomicrmw add ptr %p, i32 %i acq_rel, align 8
+ %a.sub = atomicrmw sub ptr %p, i32 %i acq_rel, align 8
+ %a.and = atomicrmw and ptr %p, i32 %i acq_rel, align 8
+ %a.nand = atomicrmw nand ptr %p, i32 %i acq_rel, align 8
+ %a.or = atomicrmw or ptr %p, i32 %i acq_rel, align 8
+ %a.xor = atomicrmw xor ptr %p, i32 %i acq_rel, align 8
+ %a.max = atomicrmw max ptr %p, i32 %i acq_rel, align 8
+ %a.min = atomicrmw min ptr %p, i32 %i acq_rel, align 8
+ %a.umax = atomicrmw umax ptr %p, i32 %i acq_rel, align 8
+ %a.umin = atomicrmw umin ptr %p, i32 %i acq_rel, align 8
+
+ %a.fadd = atomicrmw fadd ptr %p, float %f acq_rel, align 8
+ %a.fsub = atomicrmw fsub ptr %p, float %f acq_rel, align 8
+ %a.fmax = atomicrmw fmax ptr %p, float %f acq_rel, align 8
+ %a.fmin = atomicrmw fmin ptr %p, float %f acq_rel, align 8
+
+ %a.uinc_wrap = atomicrmw uinc_wrap ptr %p, i32 %i acq_rel, align 8
+ %a.udec_wrap = atomicrmw udec_wrap ptr %p, i32 %i acq_rel, align 8
+
+ ret void
+}
+
define i32 @main() {
%1 = alloca i32, align 4
%2 = cmpxchg ptr %1, i32 2, i32 3 seq_cst acquire
More information about the llvm-commits
mailing list