|
@@ -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.
|