Skip to content

Commit cbf7f3c

Browse files
committed
[C API] Add usub_cond and usub_sat atomic ops to C API
These were added in the C++ API in llvm#105568 but were not exposed via the C API previously
1 parent c9e5c42 commit cbf7f3c

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

Diff for: llvm/docs/ReleaseNotes.rst

+1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ Changes to the C API
204204
* ``LLVMGetNextDbgRecord``
205205
* ``LLVMGetPreviousDbgRecord``
206206

207+
* Added ``LLVMAtomicRMWBinOpUSubCond`` and ``LLVMAtomicRMWBinOpUSubSat`` to ``LLVMAtomicRMWBinOp`` enum for AtomicRMW instructions.
207208

208209
Changes to the CodeGen infrastructure
209210
-------------------------------------

Diff for: llvm/include/llvm-c/Core.h

+3
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,9 @@ typedef enum {
395395
when incremented above input value */
396396
LLVMAtomicRMWBinOpUDecWrap, /**< Decrements the value, wrapping back to
397397
the input value when decremented below zero */
398+
LLVMAtomicRMWBinOpUSubCond, /**<Subtracts the value only if no unsigned
399+
overflow */
400+
LLVMAtomicRMWBinOpUSubSat, /**<Subtracts the value, clamping to zero */
398401
} LLVMAtomicRMWBinOp;
399402

400403
typedef enum {

Diff for: llvm/lib/IR/Core.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -3965,6 +3965,10 @@ static AtomicRMWInst::BinOp mapFromLLVMRMWBinOp(LLVMAtomicRMWBinOp BinOp) {
39653965
return AtomicRMWInst::UIncWrap;
39663966
case LLVMAtomicRMWBinOpUDecWrap:
39673967
return AtomicRMWInst::UDecWrap;
3968+
case LLVMAtomicRMWBinOpUSubCond:
3969+
return AtomicRMWInst::USubCond;
3970+
case LLVMAtomicRMWBinOpUSubSat:
3971+
return AtomicRMWInst::USubSat;
39683972
}
39693973

39703974
llvm_unreachable("Invalid LLVMAtomicRMWBinOp value!");
@@ -3991,6 +3995,10 @@ static LLVMAtomicRMWBinOp mapToLLVMRMWBinOp(AtomicRMWInst::BinOp BinOp) {
39913995
return LLVMAtomicRMWBinOpUIncWrap;
39923996
case AtomicRMWInst::UDecWrap:
39933997
return LLVMAtomicRMWBinOpUDecWrap;
3998+
case AtomicRMWInst::USubCond:
3999+
return LLVMAtomicRMWBinOpUSubCond;
4000+
case AtomicRMWInst::USubSat:
4001+
return LLVMAtomicRMWBinOpUSubSat;
39944002
default: break;
39954003
}
39964004

Diff for: llvm/test/Bindings/llvm-c/atomics.ll

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ define void @atomic_rmw_ops(ptr %p, i32 %i, float %f) {
5858
%a.uinc_wrap = atomicrmw uinc_wrap ptr %p, i32 %i acq_rel, align 8
5959
%a.udec_wrap = atomicrmw udec_wrap ptr %p, i32 %i acq_rel, align 8
6060

61+
%a.usub_sat = atomicrmw usub_sat ptr %p, i32 %i acq_rel, align 8
62+
%a.usub_cond = atomicrmw usub_cond ptr %p, i32 %i acq_rel, align 8
63+
6164
ret void
6265
}
6366

0 commit comments

Comments
 (0)