diff options
| author | hsmahesha <mahesha.comp@gmail.com> | 2020-03-04 10:53:32 +0530 |
|---|---|---|
| committer | hsmahesha <mahesha.comp@gmail.com> | 2020-03-04 10:54:26 +0530 |
| commit | cac068600e55e489844156d3581b61eeecee7d4e (patch) | |
| tree | 4ec6fb5217518f87962b7594ef4b08d6275e1a64 /clang/lib/CodeGen/CodeGenModule.cpp | |
| parent | 952ad4701cf0d8da79789f6b83ddaa386c60d535 (diff) | |
[HIP] Make sure, unused hip-pinned-shadow global var is kept within device code
Summary:
hip-pinned-shadow global var should remain in the final code object irrespective
of whether it is used or not within the code. Add it to used list, so that it
will not get eliminated when it is unused.
Reviewers: yaxunl, tra, hliao
Reviewed By: yaxunl
Subscribers: hliao, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D75402
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
| -rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index faff623a2973..719cb05d9ec8 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -1916,9 +1916,9 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, llvm::Function *F, } } -void CodeGenModule::addUsedGlobal(llvm::GlobalValue *GV) { - assert(!GV->isDeclaration() && - "Only globals with definition can force usage."); +void CodeGenModule::addUsedGlobal(llvm::GlobalValue *GV, bool SkipCheck) { + assert(SkipCheck || (!GV->isDeclaration() && + "Only globals with definition can force usage.")); LLVMUsed.emplace_back(GV); } @@ -4071,9 +4071,17 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D, } } - if (!IsHIPPinnedShadowVar) + // HIPPinnedShadowVar should remain in the final code object irrespective of + // whether it is used or not within the code. Add it to used list, so that + // it will not get eliminated when it is unused. Also, it is an extern var + // within device code, and it should *not* get initialized within device code. + if (IsHIPPinnedShadowVar) + addUsedGlobal(GV, /*SkipCheck=*/true); + else GV->setInitializer(Init); - if (emitter) emitter->finalize(GV); + + if (emitter) + emitter->finalize(GV); // If it is safe to mark the global 'constant', do so now. GV->setConstant(!NeedsGlobalCtor && !NeedsGlobalDtor && |
