[llvm] [C API] Add usub_cond and usub_sat atomic ops to C API (PR #109532)

Benji Smith via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 21 08:53:05 PDT 2024


https://github.com/Benjins created https://github.com/llvm/llvm-project/pull/109532

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

>From cbf7f3cea6ba429e296d83da21de68a2b95e0dea Mon Sep 17 00:00:00 2001
From: Benji Smith <benjsith at gmail.com>
Date: Sat, 21 Sep 2024 11:42:45 -0400
Subject: [PATCH] [C API] Add usub_cond and usub_sat atomic ops to C API

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
---
 llvm/docs/ReleaseNotes.rst           | 1 +
 llvm/include/llvm-c/Core.h           | 3 +++
 llvm/lib/IR/Core.cpp                 | 8 ++++++++
 llvm/test/Bindings/llvm-c/atomics.ll | 3 +++
 4 files changed, 15 insertions(+)

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
 }
 



More information about the llvm-commits mailing list