diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2018-08-02 17:33:11 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2018-08-02 17:33:11 +0000 |
commit | c7e70c433efc6953dc3888b9fbf9f3512d7da2b0 (patch) | |
tree | 27425930fc0c91650a7f3527fcac8e0f92907b90 /lib/CodeGen/CGOpenMPRuntime.cpp | |
parent | 486754660bb926339aefcf012a3f848592babb8b (diff) |
Diffstat (limited to 'lib/CodeGen/CGOpenMPRuntime.cpp')
-rw-r--r-- | lib/CodeGen/CGOpenMPRuntime.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/CodeGen/CGOpenMPRuntime.cpp b/lib/CodeGen/CGOpenMPRuntime.cpp index 3730b9af12fab..fa850155df4f9 100644 --- a/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/lib/CodeGen/CGOpenMPRuntime.cpp @@ -3750,11 +3750,13 @@ CGOpenMPRuntime::createOffloadingBinaryDescriptorRegistration() { StringRef T = Device.getTriple(); std::string BeginName = getName({"omp_offloading", "img_start", ""}); auto *ImgBegin = new llvm::GlobalVariable( - M, CGM.Int8Ty, /*isConstant=*/true, llvm::GlobalValue::ExternalLinkage, + M, CGM.Int8Ty, /*isConstant=*/true, + llvm::GlobalValue::ExternalWeakLinkage, /*Initializer=*/nullptr, Twine(BeginName).concat(T)); std::string EndName = getName({"omp_offloading", "img_end", ""}); auto *ImgEnd = new llvm::GlobalVariable( - M, CGM.Int8Ty, /*isConstant=*/true, llvm::GlobalValue::ExternalLinkage, + M, CGM.Int8Ty, /*isConstant=*/true, + llvm::GlobalValue::ExternalWeakLinkage, /*Initializer=*/nullptr, Twine(EndName).concat(T)); llvm::Constant *Data[] = {ImgBegin, ImgEnd, HostEntriesBegin, @@ -8109,6 +8111,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; |