Skip to content

[C API] Add usub_cond and usub_sat atomic ops to C API #109532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions llvm/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions llvm/include/llvm-c/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions llvm/lib/IR/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand All @@ -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;
}

Expand Down
3 changes: 3 additions & 0 deletions llvm/test/Bindings/llvm-c/atomics.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Loading