Skip to content

Commit dfe12b3

Browse files
authored
[C API] Support uinc_wrap/udec_wrap in atomicrmw when accessing the bin op (#87163)
These previously were added in the C++ API in 778cf54, 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.
1 parent f3a8112 commit dfe12b3

File tree

4 files changed

+68
-28
lines changed

4 files changed

+68
-28
lines changed

llvm/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ Changes to the C API
149149

150150
* Deprecated ``LLVMConstNUWNeg`` and ``LLVMBuildNUWNeg``.
151151

152+
* Added ``LLVMAtomicRMWBinOpUIncWrap`` and ``LLVMAtomicRMWBinOpUDecWrap`` to
153+
``LLVMAtomicRMWBinOp`` enum for AtomicRMW instructions.
154+
152155
Changes to the CodeGen infrastructure
153156
-------------------------------------
154157

llvm/include/llvm-c/Core.h

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -361,35 +361,39 @@ typedef enum {
361361
} LLVMAtomicOrdering;
362362

363363
typedef enum {
364-
LLVMAtomicRMWBinOpXchg, /**< Set the new value and return the one old */
365-
LLVMAtomicRMWBinOpAdd, /**< Add a value and return the old one */
366-
LLVMAtomicRMWBinOpSub, /**< Subtract a value and return the old one */
367-
LLVMAtomicRMWBinOpAnd, /**< And a value and return the old one */
368-
LLVMAtomicRMWBinOpNand, /**< Not-And a value and return the old one */
369-
LLVMAtomicRMWBinOpOr, /**< OR a value and return the old one */
370-
LLVMAtomicRMWBinOpXor, /**< Xor a value and return the old one */
371-
LLVMAtomicRMWBinOpMax, /**< Sets the value if it's greater than the
372-
original using a signed comparison and return
373-
the old one */
374-
LLVMAtomicRMWBinOpMin, /**< Sets the value if it's Smaller than the
375-
original using a signed comparison and return
376-
the old one */
377-
LLVMAtomicRMWBinOpUMax, /**< Sets the value if it's greater than the
378-
original using an unsigned comparison and return
379-
the old one */
380-
LLVMAtomicRMWBinOpUMin, /**< Sets the value if it's greater than the
381-
original using an unsigned comparison and return
382-
the old one */
383-
LLVMAtomicRMWBinOpFAdd, /**< Add a floating point value and return the
384-
old one */
385-
LLVMAtomicRMWBinOpFSub, /**< Subtract a floating point value and return the
364+
LLVMAtomicRMWBinOpXchg, /**< Set the new value and return the one old */
365+
LLVMAtomicRMWBinOpAdd, /**< Add a value and return the old one */
366+
LLVMAtomicRMWBinOpSub, /**< Subtract a value and return the old one */
367+
LLVMAtomicRMWBinOpAnd, /**< And a value and return the old one */
368+
LLVMAtomicRMWBinOpNand, /**< Not-And a value and return the old one */
369+
LLVMAtomicRMWBinOpOr, /**< OR a value and return the old one */
370+
LLVMAtomicRMWBinOpXor, /**< Xor a value and return the old one */
371+
LLVMAtomicRMWBinOpMax, /**< Sets the value if it's greater than the
372+
original using a signed comparison and return
373+
the old one */
374+
LLVMAtomicRMWBinOpMin, /**< Sets the value if it's Smaller than the
375+
original using a signed comparison and return
376+
the old one */
377+
LLVMAtomicRMWBinOpUMax, /**< Sets the value if it's greater than the
378+
original using an unsigned comparison and return
379+
the old one */
380+
LLVMAtomicRMWBinOpUMin, /**< Sets the value if it's greater than the
381+
original using an unsigned comparison and return
382+
the old one */
383+
LLVMAtomicRMWBinOpFAdd, /**< Add a floating point value and return the
386384
old one */
387-
LLVMAtomicRMWBinOpFMax, /**< Sets the value if it's greater than the
388-
original using an floating point comparison and
389-
return the old one */
390-
LLVMAtomicRMWBinOpFMin, /**< Sets the value if it's smaller than the
391-
original using an floating point comparison and
392-
return the old one */
385+
LLVMAtomicRMWBinOpFSub, /**< Subtract a floating point value and return the
386+
old one */
387+
LLVMAtomicRMWBinOpFMax, /**< Sets the value if it's greater than the
388+
original using an floating point comparison and
389+
return the old one */
390+
LLVMAtomicRMWBinOpFMin, /**< Sets the value if it's smaller than the
391+
original using an floating point comparison and
392+
return the old one */
393+
LLVMAtomicRMWBinOpUIncWrap, /**< Increments the value, wrapping back to zero
394+
when incremented above input value */
395+
LLVMAtomicRMWBinOpUDecWrap, /**< Decrements the value, wrapping back to
396+
the input value when decremented below zero */
393397
} LLVMAtomicRMWBinOp;
394398

395399
typedef enum {

llvm/lib/IR/Core.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3769,6 +3769,10 @@ static AtomicRMWInst::BinOp mapFromLLVMRMWBinOp(LLVMAtomicRMWBinOp BinOp) {
37693769
case LLVMAtomicRMWBinOpFSub: return AtomicRMWInst::FSub;
37703770
case LLVMAtomicRMWBinOpFMax: return AtomicRMWInst::FMax;
37713771
case LLVMAtomicRMWBinOpFMin: return AtomicRMWInst::FMin;
3772+
case LLVMAtomicRMWBinOpUIncWrap:
3773+
return AtomicRMWInst::UIncWrap;
3774+
case LLVMAtomicRMWBinOpUDecWrap:
3775+
return AtomicRMWInst::UDecWrap;
37723776
}
37733777

37743778
llvm_unreachable("Invalid LLVMAtomicRMWBinOp value!");
@@ -3791,6 +3795,10 @@ static LLVMAtomicRMWBinOp mapToLLVMRMWBinOp(AtomicRMWInst::BinOp BinOp) {
37913795
case AtomicRMWInst::FSub: return LLVMAtomicRMWBinOpFSub;
37923796
case AtomicRMWInst::FMax: return LLVMAtomicRMWBinOpFMax;
37933797
case AtomicRMWInst::FMin: return LLVMAtomicRMWBinOpFMin;
3798+
case AtomicRMWInst::UIncWrap:
3799+
return LLVMAtomicRMWBinOpUIncWrap;
3800+
case AtomicRMWInst::UDecWrap:
3801+
return LLVMAtomicRMWBinOpUDecWrap;
37943802
default: break;
37953803
}
37963804

llvm/test/Bindings/llvm-c/atomics.ll

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,31 @@ define void @atomic_load_store(ptr %word) {
3636
ret void
3737
}
3838

39+
define void @atomic_rmw_ops(ptr %p, i32 %i, float %f) {
40+
; Test all atomicrmw operations
41+
%a.xchg = atomicrmw xchg ptr %p, i32 %i acq_rel, align 8
42+
%a.add = atomicrmw add ptr %p, i32 %i acq_rel, align 8
43+
%a.sub = atomicrmw sub ptr %p, i32 %i acq_rel, align 8
44+
%a.and = atomicrmw and ptr %p, i32 %i acq_rel, align 8
45+
%a.nand = atomicrmw nand ptr %p, i32 %i acq_rel, align 8
46+
%a.or = atomicrmw or ptr %p, i32 %i acq_rel, align 8
47+
%a.xor = atomicrmw xor ptr %p, i32 %i acq_rel, align 8
48+
%a.max = atomicrmw max ptr %p, i32 %i acq_rel, align 8
49+
%a.min = atomicrmw min ptr %p, i32 %i acq_rel, align 8
50+
%a.umax = atomicrmw umax ptr %p, i32 %i acq_rel, align 8
51+
%a.umin = atomicrmw umin ptr %p, i32 %i acq_rel, align 8
52+
53+
%a.fadd = atomicrmw fadd ptr %p, float %f acq_rel, align 8
54+
%a.fsub = atomicrmw fsub ptr %p, float %f acq_rel, align 8
55+
%a.fmax = atomicrmw fmax ptr %p, float %f acq_rel, align 8
56+
%a.fmin = atomicrmw fmin ptr %p, float %f acq_rel, align 8
57+
58+
%a.uinc_wrap = atomicrmw uinc_wrap ptr %p, i32 %i acq_rel, align 8
59+
%a.udec_wrap = atomicrmw udec_wrap ptr %p, i32 %i acq_rel, align 8
60+
61+
ret void
62+
}
63+
3964
define i32 @main() {
4065
%1 = alloca i32, align 4
4166
%2 = cmpxchg ptr %1, i32 2, i32 3 seq_cst acquire

0 commit comments

Comments
 (0)