[llvm] df6855b - [C API] Add usub_cond and usub_sat atomic ops to C API (#109532)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 23 00:54:05 PDT 2024
Author: Benji Smith
Date: 2024-09-23T09:54:02+02:00
New Revision: df6855ba57b2cede7b1578e74276f3ad33c2ad5d
URL: https://github.com/llvm/llvm-project/commit/df6855ba57b2cede7b1578e74276f3ad33c2ad5d
DIFF: https://github.com/llvm/llvm-project/commit/df6855ba57b2cede7b1578e74276f3ad33c2ad5d.diff
LOG: [C API] Add usub_cond and usub_sat atomic ops to C API (#109532)
These were added in the C++ API in
https://github.com/llvm/llvm-project/pull/105568 but were not exposed
via the C API previously
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 660a3785367a39..e2a6480c153aeb 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -204,6 +204,7 @@ Changes to the C API
* ``LLVMGetNextDbgRecord``
* ``LLVMGetPreviousDbgRecord``
+* Added ``LLVMAtomicRMWBinOpUSubCond`` and ``LLVMAtomicRMWBinOpUSubSat`` 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 19e059295018e4..26d4ef424b2a1e 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/include/llvm-c/Core.h
@@ -395,6 +395,9 @@ typedef enum {
when incremented above input value */
LLVMAtomicRMWBinOpUDecWrap, /**< Decrements the value, wrapping back to
the input value when decremented below zero */
+ LLVMAtomicRMWBinOpUSubCond, /**<Subtracts the value only if no unsigned
+ overflow */
+ LLVMAtomicRMWBinOpUSubSat, /**<Subtracts the value, clamping to zero */
} LLVMAtomicRMWBinOp;
typedef enum {
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index 32a04c59d4d260..8e8a374ffbbb6a 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -3965,6 +3965,10 @@ static AtomicRMWInst::BinOp mapFromLLVMRMWBinOp(LLVMAtomicRMWBinOp BinOp) {
return AtomicRMWInst::UIncWrap;
case LLVMAtomicRMWBinOpUDecWrap:
return AtomicRMWInst::UDecWrap;
+ case LLVMAtomicRMWBinOpUSubCond:
+ return AtomicRMWInst::USubCond;
+ case LLVMAtomicRMWBinOpUSubSat:
+ return AtomicRMWInst::USubSat;
}
llvm_unreachable("Invalid LLVMAtomicRMWBinOp value!");
@@ -3991,6 +3995,10 @@ static LLVMAtomicRMWBinOp mapToLLVMRMWBinOp(AtomicRMWInst::BinOp BinOp) {
return LLVMAtomicRMWBinOpUIncWrap;
case AtomicRMWInst::UDecWrap:
return LLVMAtomicRMWBinOpUDecWrap;
+ case AtomicRMWInst::USubCond:
+ return LLVMAtomicRMWBinOpUSubCond;
+ case AtomicRMWInst::USubSat:
+ return LLVMAtomicRMWBinOpUSubSat;
default: break;
}
diff --git a/llvm/test/Bindings/llvm-c/atomics.ll b/llvm/test/Bindings/llvm-c/atomics.ll
index 162368c9d98d0e..588bd240f980c1 100644
--- a/llvm/test/Bindings/llvm-c/atomics.ll
+++ b/llvm/test/Bindings/llvm-c/atomics.ll
@@ -58,6 +58,9 @@ define void @atomic_rmw_ops(ptr %p, i32 %i, float %f) {
%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
+ %a.usub_sat = atomicrmw usub_sat ptr %p, i32 %i acq_rel, align 8
+ %a.usub_cond = atomicrmw usub_cond ptr %p, i32 %i acq_rel, align 8
+
ret void
}
More information about the llvm-commits
mailing list