[llvm] [NVPTX] Add syncscope support for cmpxchg (PR #140812)
Alex MacLean via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 3 10:59:33 PDT 2025
================
@@ -41,6 +41,27 @@ def AS_match {
}];
}
+multiclass nvvm_ternary_atomic_op_scoped<SDPatternOperator frag> {
+ defvar frag_pat = (frag node:$ptr, node:$cmp, node:$val);
+ def NAME#_cta: PatFrag<!setdagop(frag_pat, ops),
+ (!cast<SDPatternOperator>(NAME) node:$ptr, node:$cmp, node:$val), [{
+ return Scopes[cast<MemSDNode>(N)->getSyncScopeID()] == NVPTX::Scope::Block;
+ }]>;
+ def NAME#_cluster : PatFrag<!setdagop(frag_pat, ops),
+ (!cast<SDPatternOperator>(NAME) node:$ptr, node:$cmp, node:$val), [{
+ return Scopes[cast<MemSDNode>(N)->getSyncScopeID()] == NVPTX::Scope::Cluster;
+ }]>;
+ def NAME#_gpu: PatFrag<!setdagop(frag_pat, ops),
+ (!cast<SDPatternOperator>(NAME) node:$ptr, node:$cmp, node:$val), [{
+ return Scopes[cast<MemSDNode>(N)->getSyncScopeID()] == NVPTX::Scope::Device;
+ }]>;
+ def NAME#_sys: PatFrag<!setdagop(frag_pat, ops),
+ (!cast<SDPatternOperator>(NAME) node:$ptr, node:$cmp, node:$val), [{
+ return Scopes[cast<MemSDNode>(N)->getSyncScopeID()] == NVPTX::Scope::System;
+ }]>;
+}
----------------
AlexMaclean wrote:
Given how target-specific these scopes are, I don't think a general solution like this would make much sense. What you have now allows you to reference the scopes by their names while it sounds like this solution would include the scope numbers in the pattern names. This seems a lot less readable. Since the definitions of these patterns are rather small and simple I see no need to combine them all into one place. That being said, I am still curious if any other target has done anything like this, perhaps there is a standard method of handling scopes we should emulate?
https://github.com/llvm/llvm-project/pull/140812
More information about the llvm-commits
mailing list