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 @@ -84,6 +84,7 @@ #include "llvm/Transforms/Utils/CanonicalizeAliases.h" #include "llvm/Transforms/Utils/Debugify.h" #include "llvm/Transforms/Utils/EntryExitInstrumenter.h" +#include "llvm/Transforms/Utils/ModuleUtils.h" #include "llvm/Transforms/Utils/NameAnonGlobals.h" #include "llvm/Transforms/Utils/SymbolRewriter.h" #include @@ -1775,6 +1776,6 @@ SmallString<128> SectionName( {".llvm.offloading.", std::get<1>(FilenameAndSection)}); - llvm::EmbedBufferInModule(*M, **ObjectOrErr, SectionName); + llvm::embedBufferInModule(*M, **ObjectOrErr, SectionName); } } diff --git a/llvm/include/llvm/Bitcode/BitcodeWriter.h b/llvm/include/llvm/Bitcode/BitcodeWriter.h --- a/llvm/include/llvm/Bitcode/BitcodeWriter.h +++ b/llvm/include/llvm/Bitcode/BitcodeWriter.h @@ -165,11 +165,6 @@ bool EmbedCmdline, const std::vector &CmdArgs); - /// Embeds the memory buffer \p Buf into the module \p M as a global using the - /// section name \p SectionName. - void EmbedBufferInModule(Module &M, MemoryBufferRef Buf, - StringRef SectionName); - } // end namespace llvm #endif // LLVM_BITCODE_BITCODEWRITER_H diff --git a/llvm/include/llvm/Transforms/Utils/ModuleUtils.h b/llvm/include/llvm/Transforms/Utils/ModuleUtils.h --- a/llvm/include/llvm/Transforms/Utils/ModuleUtils.h +++ b/llvm/include/llvm/Transforms/Utils/ModuleUtils.h @@ -15,6 +15,7 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/MemoryBuffer.h" #include // for std::pair namespace llvm { @@ -106,6 +107,10 @@ /// unique identifier for this module, so we return the empty string. std::string getUniqueModuleId(Module *M); +/// Embed the memory buffer \p Buf into the module \p M as a global using the +/// section name \p SectionName. +void embedBufferInModule(Module &M, MemoryBufferRef Buf, StringRef SectionName); + class CallInst; namespace VFABI { /// Overwrite the Vector Function ABI variants attribute with the names provide diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -69,7 +69,6 @@ #include "llvm/Support/MathExtras.h" #include "llvm/Support/SHA1.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/Transforms/Utils/ModuleUtils.h" #include #include #include @@ -4974,19 +4973,3 @@ llvm::ConstantArray::get(ATy, UsedArray), "llvm.compiler.used"); NewUsed->setSection("llvm.metadata"); } - -void llvm::EmbedBufferInModule(llvm::Module &M, llvm::MemoryBufferRef Buf, - StringRef SectionName) { - ArrayRef ModuleData = - ArrayRef(Buf.getBufferStart(), Buf.getBufferSize()); - - // Embed the buffer into the module. - llvm::Constant *ModuleConstant = - llvm::ConstantDataArray::get(M.getContext(), ModuleData); - llvm::GlobalVariable *GV = new llvm::GlobalVariable( - M, ModuleConstant->getType(), true, llvm::GlobalValue::PrivateLinkage, - ModuleConstant, "llvm.embedded.object"); - GV->setSection(SectionName); - - appendToCompilerUsed(M, GV); -} diff --git a/llvm/lib/Bitcode/Writer/CMakeLists.txt b/llvm/lib/Bitcode/Writer/CMakeLists.txt --- a/llvm/lib/Bitcode/Writer/CMakeLists.txt +++ b/llvm/lib/Bitcode/Writer/CMakeLists.txt @@ -11,7 +11,6 @@ Analysis Core MC - TransformUtils Object Support ) diff --git a/llvm/lib/Transforms/Utils/ModuleUtils.cpp b/llvm/lib/Transforms/Utils/ModuleUtils.cpp --- a/llvm/lib/Transforms/Utils/ModuleUtils.cpp +++ b/llvm/lib/Transforms/Utils/ModuleUtils.cpp @@ -264,3 +264,19 @@ CI->addFnAttr( Attribute::get(M->getContext(), MappingsAttrName, Buffer.str())); } + +void llvm::embedBufferInModule(llvm::Module &M, llvm::MemoryBufferRef Buf, + StringRef SectionName) { + ArrayRef ModuleData = + ArrayRef(Buf.getBufferStart(), Buf.getBufferSize()); + + // Embed the buffer into the module. + llvm::Constant *ModuleConstant = + llvm::ConstantDataArray::get(M.getContext(), ModuleData); + llvm::GlobalVariable *GV = new llvm::GlobalVariable( + M, ModuleConstant->getType(), true, llvm::GlobalValue::PrivateLinkage, + ModuleConstant, "llvm.embedded.object"); + GV->setSection(SectionName); + + appendToCompilerUsed(M, GV); +} diff --git a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel --- a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel @@ -904,7 +904,6 @@ "include/llvm/Bitcode/BitcodeWriter.h", "include/llvm/Bitcode/BitcodeWriterPass.h", "include/llvm/Bitcode/LLVMBitCodes.h", - "include/llvm/Transforms/Utils/ModuleUtils.h", ], copts = llvm_copts, deps = [