diff options
author | Yaxun Liu <Yaxun.Liu@amd.com> | 2019-06-26 03:47:37 +0000 |
---|---|---|
committer | Yaxun Liu <Yaxun.Liu@amd.com> | 2019-06-26 03:47:37 +0000 |
commit | c3dfe9082bce468169c3ce94e55258d1bca7e692 (patch) | |
tree | 558271cf0bc2d97b44febb4a0f1c90c799f36106 /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | d325eb3b56d57035141ac5d4dd58feee70e2e969 (diff) | |
download | bcm5719-llvm-c3dfe9082bce468169c3ce94e55258d1bca7e692.tar.gz bcm5719-llvm-c3dfe9082bce468169c3ce94e55258d1bca7e692.zip |
[HIP] Support attribute hip_pinned_shadow
This patch introduces support of hip_pinned_shadow variable for HIP.
A hip_pinned_shadow variable is a global variable with attribute hip_pinned_shadow.
It has external linkage on device side and has no initializer. It has internal
linkage on host side and has initializer or static constructor. It can be accessed
in both device code and host code.
This allows HIP runtime to implement support of HIP texture reference.
Differential Revision: https://reviews.llvm.org/D62738
llvm-svn: 364381
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 87a1d45abf4..b0e3b0bb98d 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2415,7 +2415,8 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) { if (!Global->hasAttr<CUDADeviceAttr>() && !Global->hasAttr<CUDAGlobalAttr>() && !Global->hasAttr<CUDAConstantAttr>() && - !Global->hasAttr<CUDASharedAttr>()) + !Global->hasAttr<CUDASharedAttr>() && + !(LangOpts.HIP && Global->hasAttr<HIPPinnedShadowAttr>())) return; } else { // We need to emit host-side 'shadows' for all global @@ -3781,7 +3782,12 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D, !getLangOpts().CUDAIsDevice && (D->hasAttr<CUDAConstantAttr>() || D->hasAttr<CUDADeviceAttr>() || D->hasAttr<CUDASharedAttr>()); - if (getLangOpts().CUDA && (IsCUDASharedVar || IsCUDAShadowVar)) + // HIP pinned shadow of initialized host-side global variables are also + // left undefined. + bool IsHIPPinnedShadowVar = + getLangOpts().CUDAIsDevice && D->hasAttr<HIPPinnedShadowAttr>(); + if (getLangOpts().CUDA && + (IsCUDASharedVar || IsCUDAShadowVar || IsHIPPinnedShadowVar)) Init = llvm::UndefValue::get(getTypes().ConvertType(ASTTy)); else if (!InitExpr) { // This is a tentative definition; tentative definitions are @@ -3892,7 +3898,8 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D, // global variables become internal definitions. These have to // be internal in order to prevent name conflicts with global // host variables with the same name in a different TUs. - if (D->hasAttr<CUDADeviceAttr>() || D->hasAttr<CUDAConstantAttr>()) { + if (D->hasAttr<CUDADeviceAttr>() || D->hasAttr<CUDAConstantAttr>() || + D->hasAttr<HIPPinnedShadowAttr>()) { Linkage = llvm::GlobalValue::InternalLinkage; // Shadow variables and their properties must be registered @@ -3916,7 +3923,8 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D, } } - GV->setInitializer(Init); + if (!IsHIPPinnedShadowVar) + GV->setInitializer(Init); if (emitter) emitter->finalize(GV); // If it is safe to mark the global 'constant', do so now. |