[llvm] [NVPTX] Add syncscope support for cmpxchg (PR #140812)
Alex MacLean via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 2 10:07:55 PDT 2025
================
@@ -1927,22 +1996,13 @@ defm INT_PTX_ATOM_XOR_64 : F_ATOMIC_2_AS<I64RT, atomic_load_xor_i64, "xor.b64",
// Define atom.cas for all combinations of size x addrspace x memory order
// supported in PTX *and* on the hardware.
-foreach t = [I32RT, I64RT] in {
- foreach order = ["acquire", "release", "acq_rel", "monotonic"] in {
- defvar cas_order_string = !if(!eq(order, "monotonic"), ".relaxed", "."#order);
- defvar atomic_cmp_swap_pat = !cast<PatFrag>("atomic_cmp_swap_i"#t.Size#_#order);
- // Note that AtomicExpand will convert cmpxchg seq_cst to a cmpxchg monotonic with fences around it.
- // Memory orders are only supported for SM70+, PTX63+- so we have two sets of instruction definitions-
- // for SM70+, and "old" ones which lower to "atom.cas", for earlier archs.
- defm INT_PTX_ATOM_CAS_#t.Size#_#order
- : F_ATOMIC_3_AS<t, atomic_cmp_swap_pat, cas_order_string, "cas.b"#t.Size, [hasSM<70>, hasPTX<63>]>;
- defm INT_PTX_ATOM_CAS_#t.Size#_#order#_old
- : F_ATOMIC_3_AS<t, atomic_cmp_swap_pat, "", "cas.b"#t.Size, []>;
- }
-}
+foreach t = [I16RT, I32RT, I64RT] in {
+ defvar atomic_cmp_swap_pat = !cast<PatFrag>("atomic_cmp_swap_i"#t.Size);
+ defm INT_PTX_ATOM_CAS_#t.Size
+ : F_ATOMIC_3<t, ".cas.b"#t.Size>;
-// Note that 16-bit CAS support in PTX is emulated.
-defm INT_PTX_ATOM_CAS_16 : F_ATOMIC_3_AS<I16RT, atomic_cmp_swap_i16, "", "cas.b16", [hasSM<70>, hasPTX<63>]>;
+ defm INT_PTX_ATOM_CAS_PAT_#t.Size : F_ATOMIC_3_PATTERN<t, "INT_PTX_ATOM_CAS_"#t.Size, atomic_cmp_swap_pat, atomic_cmp_swap>;
----------------
AlexMaclean wrote:
Since you always define `F_ATOMIC_3` and `F_ATOMIC_3_PATTERN` in conjunction, can you combine these into a single `multiclass`?
https://github.com/llvm/llvm-project/pull/140812
More information about the llvm-commits
mailing list