[llvm] [C API] Support uinc_wrap/udec_wrap in atomicrmw when accessing the bin op (PR #87163)
Benji Smith via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 30 09:58:37 PDT 2024
https://github.com/Benjins created https://github.com/llvm/llvm-project/pull/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
>From cd317c8efd821217f5e9ceb37b12879241aaad4b Mon Sep 17 00:00:00 2001
From: Benji Smith <benjsith at gmail.com>
Date: Sat, 30 Mar 2024 11:57:52 -0400
Subject: [PATCH] [C API] Support uinc_wrap/udec_wrap in atomicrmw when
accessing the bin op
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
---
llvm/docs/ReleaseNotes.rst | 3 +++
llvm/include/llvm-c/Core.h | 4 ++++
llvm/lib/IR/Core.cpp | 4 ++++
llvm/test/Bindings/llvm-c/atomics.ll | 25 +++++++++++++++++++++++++
4 files changed, 36 insertions(+)
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 7588048334d792..e846514b1b25fc 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 254c298abe4b9c..db9322dd81bb57 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/include/llvm-c/Core.h
@@ -390,6 +390,10 @@ typedef enum {
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 3aee6195725253..9d72e9c4df4580 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -3755,6 +3755,8 @@ 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!");
@@ -3777,6 +3779,8 @@ 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