summaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGOpenMPRuntime.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/CodeGen/CGOpenMPRuntime.cpp')
-rw-r--r--lib/CodeGen/CGOpenMPRuntime.cpp19
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;