-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[C API] Support uinc_wrap/udec_wrap in atomicrmw when accessing the bin op #87163
Conversation
…in op 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
@llvm/pr-subscribers-llvm-ir Author: Benji Smith (Benjins) ChangesThese 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 Full diff: https://github.com/llvm/llvm-project/pull/87163.diff 4 Files Affected:
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 7588048334d792..e846514b1b25fc 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -149,6 +149,9 @@ Changes to the C API
* Deprecated ``LLVMConstNUWNeg`` and ``LLVMBuildNUWNeg``.
+* Added ``LLVMAtomicRMWBinOpUIncWrap`` and ``LLVMAtomicRMWBinOpUDecWrap`` 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 254c298abe4b9c..db9322dd81bb57 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/include/llvm-c/Core.h
@@ -390,6 +390,10 @@ typedef enum {
LLVMAtomicRMWBinOpFMin, /**< Sets the value if it's smaller than the
original using an floating point comparison and
return the old one */
+ LLVMAtomicRMWBinOpUIncWrap, /**< Increments the value, wrapping back to zero
+ when incremented above input value */
+ LLVMAtomicRMWBinOpUDecWrap, /**< Decrements the value, wrapping back to
+ the input value when decremented below zero */
} LLVMAtomicRMWBinOp;
typedef enum {
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index 3aee6195725253..9d72e9c4df4580 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -3755,6 +3755,8 @@ static AtomicRMWInst::BinOp mapFromLLVMRMWBinOp(LLVMAtomicRMWBinOp BinOp) {
case LLVMAtomicRMWBinOpFSub: return AtomicRMWInst::FSub;
case LLVMAtomicRMWBinOpFMax: return AtomicRMWInst::FMax;
case LLVMAtomicRMWBinOpFMin: return AtomicRMWInst::FMin;
+ case LLVMAtomicRMWBinOpUIncWrap: return AtomicRMWInst::UIncWrap;
+ case LLVMAtomicRMWBinOpUDecWrap: return AtomicRMWInst::UDecWrap;
}
llvm_unreachable("Invalid LLVMAtomicRMWBinOp value!");
@@ -3777,6 +3779,8 @@ static LLVMAtomicRMWBinOp mapToLLVMRMWBinOp(AtomicRMWInst::BinOp BinOp) {
case AtomicRMWInst::FSub: return LLVMAtomicRMWBinOpFSub;
case AtomicRMWInst::FMax: return LLVMAtomicRMWBinOpFMax;
case AtomicRMWInst::FMin: return LLVMAtomicRMWBinOpFMin;
+ case AtomicRMWInst::UIncWrap: return LLVMAtomicRMWBinOpUIncWrap;
+ case AtomicRMWInst::UDecWrap: return LLVMAtomicRMWBinOpUDecWrap;
default: break;
}
diff --git a/llvm/test/Bindings/llvm-c/atomics.ll b/llvm/test/Bindings/llvm-c/atomics.ll
index e64a29944ef9df..162368c9d98d0e 100644
--- a/llvm/test/Bindings/llvm-c/atomics.ll
+++ b/llvm/test/Bindings/llvm-c/atomics.ll
@@ -36,6 +36,31 @@ define void @atomic_load_store(ptr %word) {
ret void
}
+define void @atomic_rmw_ops(ptr %p, i32 %i, float %f) {
+ ; Test all atomicrmw operations
+ %a.xchg = atomicrmw xchg ptr %p, i32 %i acq_rel, align 8
+ %a.add = atomicrmw add ptr %p, i32 %i acq_rel, align 8
+ %a.sub = atomicrmw sub ptr %p, i32 %i acq_rel, align 8
+ %a.and = atomicrmw and ptr %p, i32 %i acq_rel, align 8
+ %a.nand = atomicrmw nand ptr %p, i32 %i acq_rel, align 8
+ %a.or = atomicrmw or ptr %p, i32 %i acq_rel, align 8
+ %a.xor = atomicrmw xor ptr %p, i32 %i acq_rel, align 8
+ %a.max = atomicrmw max ptr %p, i32 %i acq_rel, align 8
+ %a.min = atomicrmw min ptr %p, i32 %i acq_rel, align 8
+ %a.umax = atomicrmw umax ptr %p, i32 %i acq_rel, align 8
+ %a.umin = atomicrmw umin ptr %p, i32 %i acq_rel, align 8
+
+ %a.fadd = atomicrmw fadd ptr %p, float %f acq_rel, align 8
+ %a.fsub = atomicrmw fsub ptr %p, float %f acq_rel, align 8
+ %a.fmax = atomicrmw fmax ptr %p, float %f acq_rel, align 8
+ %a.fmin = atomicrmw fmin ptr %p, float %f acq_rel, align 8
+
+ %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
+
+ ret void
+}
+
define i32 @main() {
%1 = alloca i32, align 4
%2 = cmpxchg ptr %1, i32 2, i32 3 seq_cst acquire
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
Bumping this for review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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