[llvm] [C API] Add usub_cond and usub_sat atomic ops to C API (PR #109532)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 21 08:53:37 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-ir
Author: Benji Smith (Benjins)
<details>
<summary>Changes</summary>
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
---
Full diff: https://github.com/llvm/llvm-project/pull/109532.diff
4 Files Affected:
- (modified) llvm/docs/ReleaseNotes.rst (+1)
- (modified) llvm/include/llvm-c/Core.h (+3)
- (modified) llvm/lib/IR/Core.cpp (+8)
- (modified) llvm/test/Bindings/llvm-c/atomics.ll (+3)
``````````diff
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
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/109532
More information about the llvm-commits
mailing list