[PATCH] D152403: [Clang][CUDA] Disable diagnostics for neon attrs for GPU-side CUDA compilation

Alexander Shaposhnikov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 7 15:42:14 PDT 2023

alexander-shaposhnikov created this revision.
alexander-shaposhnikov added a reviewer: tra.
alexander-shaposhnikov created this object with visibility "All Users".
Herald added subscribers: mattd, carlosgalvezp, yaxunl.
Herald added a project: All.
alexander-shaposhnikov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Disable diagnostics for neon attrs for GPU-side CUDA compilation.

Test plan: ninja check-all

  rG LLVM Github Monorepo



Index: clang/test/SemaCUDA/neon-attrs.cu
--- /dev/null
+++ clang/test/SemaCUDA/neon-attrs.cu
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -triple arm64-linux-gnu -target-feature +neon -x cuda -fsyntax-only -DNO_DIAG -verify %s
+// RUN: %clang_cc1 -triple arm64-linux-gnu -target-feature -neon -x cuda -fsyntax-only -verify %s
+#ifdef NO_DIAG
+// expected-no-diagnostics
+typedef __attribute__((neon_vector_type(4))) float float32x4_t;
+typedef unsigned char poly8_t;
+typedef __attribute__((neon_polyvector_type(8))) poly8_t poly8x8_t;
+typedef __attribute__((neon_vector_type(4))) float float32x4_t;
+// expected-error at -1 {{'neon_vector_type' attribute is not supported on targets missing 'neon' or 'mve'}}
+typedef unsigned char poly8_t;
+typedef __attribute__((neon_polyvector_type(8))) poly8_t poly8x8_t;
+// expected-error at -1 {{'neon_polyvector_type' attribute is not supported on targets missing 'neon' or 'mve'}}
Index: clang/lib/Sema/SemaType.cpp
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -8161,10 +8161,17 @@
 /// match one of the standard Neon vector types.
 static void HandleNeonVectorTypeAttr(QualType &CurType, const ParsedAttr &Attr,
                                      Sema &S, VectorType::VectorKind VecKind) {
+  bool IsTargetCUDAAndHostARM = false;
+  if (S.getLangOpts().CUDAIsDevice) {
+    const TargetInfo *AuxTI = S.getASTContext().getAuxTargetInfo();
+    IsTargetCUDAAndHostARM =
+        !AuxTI || AuxTI->getTriple().isAArch64() || AuxTI->getTriple().isARM();
+  }
   // Target must have NEON (or MVE, whose vectors are similar enough
   // not to need a separate attribute)
   if (!S.Context.getTargetInfo().hasFeature("neon") &&
-      !S.Context.getTargetInfo().hasFeature("mve")) {
+      !S.Context.getTargetInfo().hasFeature("mve") && !IsTargetCUDAAndHostARM) {
     S.Diag(Attr.getLoc(), diag::err_attribute_unsupported)
         << Attr << "'neon' or 'mve'";
@@ -8183,7 +8190,8 @@
   // Only certain element types are supported for Neon vectors.
-  if (!isPermittedNeonBaseType(CurType, VecKind, S)) {
+  if (!isPermittedNeonBaseType(CurType, VecKind, S) &&
+      !IsTargetCUDAAndHostARM) {
     S.Diag(Attr.getLoc(), diag::err_attribute_invalid_vector_type) << CurType;

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152403.529456.patch
Type: text/x-patch
Size: 2457 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230607/03ceeb37/attachment.bin>

More information about the llvm-commits mailing list