Skip to content

Commit 0ba9aec

Browse files
committed
[Clang][NVPTX] Permit use of the alias attribute for NVPTX targets
The patch in D155211 added basic support for the `.alias` keyword in PTX. This means we should be able to permit use of this in clang. Reviewed By: tra Differential Revision: https://reviews.llvm.org/D156014
1 parent f0e8bda commit 0ba9aec

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8658,8 +8658,8 @@ def warn_kern_is_inline : Warning<
86588658
def err_variadic_device_fn : Error<
86598659
"CUDA device code does not support variadic functions">;
86608660
def err_va_arg_in_device : Error<
8661-
"CUDA device code does not support va_arg">;
8662-
def err_alias_not_supported_on_nvptx : Error<"CUDA does not support aliases">;
8661+
"CUDA device code does not support va_arg">;
8662+
def err_alias_not_supported_on_nvptx : Error<"CUDA older than 10.0 does not support .alias">;
86638663
def err_cuda_unattributed_constexpr_cannot_overload_device : Error<
86648664
"constexpr function %0 without __host__ or __device__ attributes cannot "
86658665
"overload __device__ function with same signature. Add a __host__ "

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "clang/AST/RecursiveASTVisitor.h"
2424
#include "clang/AST/Type.h"
2525
#include "clang/Basic/CharInfo.h"
26+
#include "clang/Basic/Cuda.h"
2627
#include "clang/Basic/DarwinSDKInfo.h"
2728
#include "clang/Basic/HLSLRuntime.h"
2829
#include "clang/Basic/LangOptions.h"
@@ -1992,8 +1993,12 @@ static void handleAliasAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
19921993
S.Diag(AL.getLoc(), diag::err_alias_not_supported_on_darwin);
19931994
return;
19941995
}
1996+
19951997
if (S.Context.getTargetInfo().getTriple().isNVPTX()) {
1996-
S.Diag(AL.getLoc(), diag::err_alias_not_supported_on_nvptx);
1998+
CudaVersion Version =
1999+
ToCudaVersion(S.Context.getTargetInfo().getSDKVersion());
2000+
if (Version != CudaVersion::UNKNOWN && Version < CudaVersion::CUDA_100)
2001+
S.Diag(AL.getLoc(), diag::err_alias_not_supported_on_nvptx);
19972002
}
19982003

19992004
// Aliases should be on declarations, not definitions.

clang/test/CodeGenCUDA/alias.cu

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,26 @@
44

55
// RUN: %clang_cc1 -fcuda-is-device -triple nvptx-nvidia-cuda -emit-llvm \
66
// RUN: -o - %s | FileCheck %s
7-
// RUN: %clang_cc1 -fcuda-is-device -triple amdgcn -emit-llvm \
7+
// RUN: %clang_cc1 -fcuda-is-device -triple nvptx-nvidia-cuda -emit-llvm -target-sdk-version=10.1 \
8+
// RUN: -o - %s | FileCheck %s
9+
// RUN: %clang_cc1 -fcuda-is-device -triple amdgcn-amd-amdhsa -emit-llvm \
810
// RUN: -o - %s | FileCheck %s
911

1012
#include "Inputs/cuda.h"
1113

12-
// Check that we don't generate an alias from "foo" to the mangled name for
13-
// ns::foo() -- nvptx doesn't support aliases.
14-
15-
namespace ns {
1614
extern "C" {
17-
// CHECK-NOT: @foo = internal alias
18-
__device__ __attribute__((used)) static int foo() { return 0; }
19-
}
15+
__device__ int foo() { return 1; }
2016
}
17+
18+
[[gnu::alias("foo")]] __device__ int alias();
19+
20+
// CHECK: @_Z5aliasv = alias i32 (), ptr @foo
21+
//
22+
// CHECK: define dso_local i32 @foo() #[[ATTR0:[0-9]+]] {
23+
// CHECK-NEXT: entry:
24+
// CHECK: ret i32 1
25+
// CHECK-NEXT: }
26+
27+
// RUN: not %clang_cc1 -fcuda-is-device -triple nvptx-nvidia-cuda -emit-llvm -target-sdk-version=9.0 \
28+
// RUN: -o - %s 2>&1 | FileCheck %s --check-prefix=NO_SUPPORT
29+
// NO_SUPPORT: CUDA older than 10.0 does not support .alias

0 commit comments

Comments
 (0)