diff --git a/clang/include/clang/CodeGen/BackendUtil.h b/clang/include/clang/CodeGen/BackendUtil.h --- a/clang/include/clang/CodeGen/BackendUtil.h +++ b/clang/include/clang/CodeGen/BackendUtil.h @@ -45,7 +45,7 @@ void EmbedBitcode(llvm::Module *M, const CodeGenOptions &CGOpts, llvm::MemoryBufferRef Buf); - void EmbedObject(llvm::Module *M, const CodeGenOptions &CGOpts, + void EmbedObject(llvm::Module &M, const CodeGenOptions &CGOpts, DiagnosticsEngine &Diags); } diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -1753,7 +1753,7 @@ CGOpts.CmdArgs); } -void clang::EmbedObject(llvm::Module *M, const CodeGenOptions &CGOpts, +void clang::EmbedObject(llvm::Module &M, const CodeGenOptions &CGOpts, DiagnosticsEngine &Diags) { if (CGOpts.OffloadObjects.empty()) return; @@ -1771,12 +1771,12 @@ if (std::error_code EC = ObjectOrErr.getError()) { auto DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, "could not open '%0' for embedding"); - Diags.Report(DiagID) << std::get<0>(FilenameAndSection); + Diags.Report(DiagID) << FilenameAndSection.first; return; } SmallString<128> SectionName( - {".llvm.offloading.", std::get<1>(FilenameAndSection)}); - llvm::embedBufferInModule(*M, **ObjectOrErr, SectionName); + {".llvm.offloading.", FilenameAndSection.second}); + llvm::embedBufferInModule(M, **ObjectOrErr, SectionName); } } diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -1134,7 +1134,7 @@ TheModule->setTargetTriple(TargetOpts.Triple); } - EmbedObject(TheModule.get(), CodeGenOpts, Diagnostics); + EmbedObject(*TheModule.get(), CodeGenOpts, Diagnostics); EmbedBitcode(TheModule.get(), CodeGenOpts, *MainFile); LLVMContext &Ctx = TheModule->getContext(); diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -43,6 +43,7 @@ #include "clang/Basic/SourceManager.h" #include "clang/Basic/TargetInfo.h" #include "clang/Basic/Version.h" +#include "clang/CodeGen/BackendUtil.h" #include "clang/CodeGen/ConstantInitBuilder.h" #include "clang/Frontend/FrontendDiagnostic.h" #include "llvm/ADT/StringSwitch.h" @@ -587,6 +588,9 @@ EmitModuleLinkOptions(); } + // If there is device offloading code embed it in the host now. + EmbedObject(getModule(), CodeGenOpts, getDiags()); + // On ELF we pass the dependent library specifiers directly to the linker // without manipulating them. This is in contrast to other platforms where // they are mapped to a specific linker option by the compiler. This