diff options
| author | Alexey Bataev <a.bataev@hotmail.com> | 2018-07-31 16:40:15 +0000 |
|---|---|---|
| committer | Alexey Bataev <a.bataev@hotmail.com> | 2018-07-31 16:40:15 +0000 |
| commit | 3823514b56d920f1d55543e164026c8b52330c63 (patch) | |
| tree | f0a1187d92efef86f60f03a5d68a4537982bcdcc /clang/lib/CodeGen | |
| parent | 68c6860434c7a062f6db335676e62aac3dd64dfd (diff) | |
| download | bcm5719-llvm-3823514b56d920f1d55543e164026c8b52330c63.tar.gz bcm5719-llvm-3823514b56d920f1d55543e164026c8b52330c63.zip | |
[OPENMP] Prevent problems with linking of the static variables.
No need to change the linkage, we can avoid the problem using special variable. That points to the original variable and, thus, prevent some of the optimizations that might break the compilation.
llvm-svn: 338399
Diffstat (limited to 'clang/lib/CodeGen')
| -rw-r--r-- | clang/lib/CodeGen/CGOpenMPRuntime.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index 3730b9af12f..060f2ea8f5e 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -8109,6 +8109,19 @@ void CGOpenMPRuntime::registerTargetGlobalVariable(const VarDecl *VD, VarName = CGM.getMangledName(VD); VarSize = CGM.getContext().getTypeSizeInChars(VD->getType()); Linkage = CGM.getLLVMLinkageVarDefinition(VD, /*IsConstant=*/false); + // Temp solution to prevent optimizations of the internal variables. + if (CGM.getLangOpts().OpenMPIsDevice && !VD->isExternallyVisible()) { + std::string RefName = getName({VarName, "ref"}); + if (!CGM.GetGlobalValue(RefName)) { + llvm::Constant *AddrRef = + getOrCreateInternalVariable(Addr->getType(), RefName); + auto *GVAddrRef = cast<llvm::GlobalVariable>(AddrRef); + GVAddrRef->setConstant(/*Val=*/true); + GVAddrRef->setLinkage(llvm::GlobalValue::InternalLinkage); + GVAddrRef->setInitializer(Addr); + CGM.addCompilerUsedGlobal(GVAddrRef); + } + } break; case OMPDeclareTargetDeclAttr::MT_Link: Flags = OffloadEntriesInfoManagerTy::OMPTargetGlobalVarEntryLink; |

