From: Artem Belevich Date: Wed, 23 Sep 2015 17:44:53 +0000 (+0000) Subject: [CUDA] __global__ functions should always be visible externally. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b7a9667a4192f47243f2fc4bb2665d421c3d52ad;p=clang [CUDA] __global__ functions should always be visible externally. Adjust __global__ functions with DiscardableODR linkage to use StrongODR linkage instead, so they are visible externally. Differential Revision: http://reviews.llvm.org/D13067 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@248400 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index b98e3d4ed9..85add92792 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -8284,13 +8284,13 @@ static GVALinkage basicGVALinkageForFunction(const ASTContext &Context, return GVA_DiscardableODR; } -static GVALinkage adjustGVALinkageForDLLAttribute(GVALinkage L, const Decl *D) { +static GVALinkage adjustGVALinkageForAttributes(GVALinkage L, const Decl *D) { // See http://msdn.microsoft.com/en-us/library/xa0d9ste.aspx // dllexport/dllimport on inline functions. if (D->hasAttr()) { if (L == GVA_DiscardableODR || L == GVA_StrongODR) return GVA_AvailableExternally; - } else if (D->hasAttr()) { + } else if (D->hasAttr() || D->hasAttr()) { if (L == GVA_DiscardableODR) return GVA_StrongODR; } @@ -8298,8 +8298,8 @@ static GVALinkage adjustGVALinkageForDLLAttribute(GVALinkage L, const Decl *D) { } GVALinkage ASTContext::GetGVALinkageForFunction(const FunctionDecl *FD) const { - return adjustGVALinkageForDLLAttribute(basicGVALinkageForFunction(*this, FD), - FD); + return adjustGVALinkageForAttributes(basicGVALinkageForFunction(*this, FD), + FD); } static GVALinkage basicGVALinkageForVariable(const ASTContext &Context, @@ -8355,8 +8355,8 @@ static GVALinkage basicGVALinkageForVariable(const ASTContext &Context, } GVALinkage ASTContext::GetGVALinkageForVariable(const VarDecl *VD) { - return adjustGVALinkageForDLLAttribute(basicGVALinkageForVariable(*this, VD), - VD); + return adjustGVALinkageForAttributes(basicGVALinkageForVariable(*this, VD), + VD); } bool ASTContext::DeclMustBeEmitted(const Decl *D) { diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index ddf189ae12..9cc082152b 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -3351,9 +3351,6 @@ static void handleGlobalAttr(Sema &S, Decl *D, const AttributeList &Attr) { CUDAGlobalAttr(Attr.getRange(), S.Context, Attr.getAttributeSpellingListIndex())); - // Add implicit attribute((used)) so we don't eliminate kernels - // because there is nothing referencing them on device side. - D->addAttr(UsedAttr::CreateImplicit(S.Context)); } static void handleGNUInlineAttr(Sema &S, Decl *D, const AttributeList &Attr) { diff --git a/test/CodeGenCUDA/ptx-kernels.cu b/test/CodeGenCUDA/ptx-kernels.cu index 3a8722a342..6280e604f2 100644 --- a/test/CodeGenCUDA/ptx-kernels.cu +++ b/test/CodeGenCUDA/ptx-kernels.cu @@ -6,11 +6,6 @@ #include "Inputs/cuda.h" -// Make sure that all __global__ functions are added to @llvm.used -// CHECK: @llvm.used = appending global -// CHECK-SAME: @global_function -// CHECK-SAME: @_Z16templated_kernelIiEvT_ - // CHECK-LABEL: define void @device_function extern "C" __device__ void device_function() {} @@ -24,7 +19,7 @@ __global__ void global_function() { // Make sure host-instantiated kernels are preserved on device side. template __global__ void templated_kernel(T param) {} -// CHECK-LABEL: define linkonce_odr void @_Z16templated_kernelIiEvT_ +// CHECK-LABEL: define weak_odr void @_Z16templated_kernelIiEvT_ void host_function() { templated_kernel<<<0,0>>>(0); } // CHECK: !{{[0-9]+}} = !{void ()* @global_function, !"kernel", i32 1}