[clang] [NVPTX] Add support for maxclusterrank in launch_bounds (PR #66496)

Jakub Chlanda via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 22 03:05:53 PDT 2023


================
@@ -5607,6 +5607,21 @@ bool Sema::CheckRegparmAttr(const ParsedAttr &AL, unsigned &numParams) {
   return false;
 }
 
+// Helper to get CudaArch.
+static CudaArch getCudaArch(const TargetInfo &TI) {
----------------
jchlanda wrote:

Is that the kind of thing you had in mind:
```diff
diff --git a/clang/lib/Basic/Targets/NVPTX.h b/clang/lib/Basic/Targets/NVPTX.h
index 6fa0b8df97d7..20d76b702a94 100644
--- a/clang/lib/Basic/Targets/NVPTX.h
+++ b/clang/lib/Basic/Targets/NVPTX.h
@@ -181,6 +181,8 @@ public:

   bool hasBitIntType() const override { return true; }
   bool hasBFloat16Type() const override { return true; }
+
+  CudaArch getGPU() const { return GPU; }
 };
 } // namespace targets
 } // namespace clang
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index c4ecaec7728b..636bb0694d36 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -10,6 +10,7 @@
 //
 //===----------------------------------------------------------------------===//

+#include "../Basic/Targets/NVPTX.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTMutationListener.h"
@@ -5609,17 +5610,7 @@ bool Sema::CheckRegparmAttr(const ParsedAttr &AL, unsigned &numParams) {

 // Helper to get CudaArch.
 static CudaArch getCudaArch(const TargetInfo &TI) {
-  if (!TI.hasFeature("ptx")) {
-    return CudaArch::UNKNOWN;
-  }
-  for (const auto &Feature : TI.getTargetOpts().FeatureMap) {
-    if (Feature.getValue()) {
-      CudaArch Arch = StringToCudaArch(Feature.getKey());
-      if (Arch != CudaArch::UNKNOWN)
-        return Arch;
-    }
-  }
-  return CudaArch::UNKNOWN;
+  return static_cast<const targets::NVPTXTargetInfo *>(&TI)->getGPU();
 }

 // Checks whether an argument of launch_bounds attribute is
```

https://github.com/llvm/llvm-project/pull/66496


More information about the cfe-commits mailing list