Author: Michael Liao Date: 2021-08-09T13:27:40-04:00 New Revision: 6ec36d18ec7b29b471bbe50502beb5b35de3975c
URL: https://github.com/llvm/llvm-project/commit/6ec36d18ec7b29b471bbe50502beb5b35de3975c DIFF: https://github.com/llvm/llvm-project/commit/6ec36d18ec7b29b471bbe50502beb5b35de3975c.diff LOG: [cuda] Mark builtin texture/surface reference variable as 'externally_initialized'. - They need to be preserved even if there's no reference within the device code as the host code may need to initialize them based on the application logic. Reviewed By: tra Differential Revision: https://reviews.llvm.org/D107718 Added: Modified: clang/lib/CodeGen/CodeGenModule.cpp clang/test/CodeGenCUDA/surface.cu clang/test/CodeGenCUDA/texture.cu Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 49a1396b58e3a..13520861fe9b6 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -4438,7 +4438,9 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D, if (GV && LangOpts.CUDA) { if (LangOpts.CUDAIsDevice) { if (Linkage != llvm::GlobalValue::InternalLinkage && - (D->hasAttr<CUDADeviceAttr>() || D->hasAttr<CUDAConstantAttr>())) + (D->hasAttr<CUDADeviceAttr>() || D->hasAttr<CUDAConstantAttr>() || + D->getType()->isCUDADeviceBuiltinSurfaceType() || + D->getType()->isCUDADeviceBuiltinTextureType())) GV->setExternallyInitialized(true); } else { getCUDARuntime().internalizeDeviceSideVar(D, Linkage); diff --git a/clang/test/CodeGenCUDA/surface.cu b/clang/test/CodeGenCUDA/surface.cu index 0bf17091081b1..eedae5473fcfc 100644 --- a/clang/test/CodeGenCUDA/surface.cu +++ b/clang/test/CodeGenCUDA/surface.cu @@ -19,7 +19,7 @@ struct __attribute__((device_builtin_surface_type)) surface<void, dim> : public }; // On the device side, surface references are represented as `i64` handles. -// DEVICE: @surf ={{.*}} addrspace(1) global i64 undef, align 4 +// DEVICE: @surf ={{.*}} addrspace(1) externally_initialized global i64 undef, align 4 // On the host side, they remain in the original type. // HOST: @surf = internal global %struct.surface // HOST: @0 = private unnamed_addr constant [5 x i8] c"surf\00" diff --git a/clang/test/CodeGenCUDA/texture.cu b/clang/test/CodeGenCUDA/texture.cu index 8a966194340aa..0bb8cd48dcaa7 100644 --- a/clang/test/CodeGenCUDA/texture.cu +++ b/clang/test/CodeGenCUDA/texture.cu @@ -19,8 +19,8 @@ struct __attribute__((device_builtin_texture_type)) texture : public textureRefe }; // On the device side, texture references are represented as `i64` handles. -// DEVICE: @tex ={{.*}} addrspace(1) global i64 undef, align 4 -// DEVICE: @norm ={{.*}} addrspace(1) global i64 undef, align 4 +// DEVICE: @tex ={{.*}} addrspace(1) externally_initialized global i64 undef, align 4 +// DEVICE: @norm ={{.*}} addrspace(1) externally_initialized global i64 undef, align 4 // On the host side, they remain in the original type. // HOST: @tex = internal global %struct.texture // HOST: @norm = internal global %struct.texture _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits