From 85dfe19b36ba6e9657612e072c9183ce168fdbbc Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 31 Jan 2022 16:33:56 -0800 Subject: [ModuleUtils] Move EmbedBufferInModule to LLVMTransformsUtils D116542 adds EmbedBufferInModule which introduces a layer violation (https://llvm.org/docs/CodingStandards.html#library-layering). See 2d5f857a1eaf5f7a806d12953c79b96ed8952da8 for detail. EmbedBufferInModule does not use BitcodeWriter functionality and should be moved LLVMTransformsUtils. While here, change the function case to the prevailing convention. It seems that EmbedBufferInModule just follows the steps of EmbedBitcodeInModule. EmbedBitcodeInModule calls WriteBitcodeToFile but has IR update operations which ideally should be refactored to another library. Reviewed By: jhuber6 Differential Revision: https://reviews.llvm.org/D118666 --- llvm/lib/Transforms/Utils/ModuleUtils.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'llvm/lib/Transforms/Utils/ModuleUtils.cpp') diff --git a/llvm/lib/Transforms/Utils/ModuleUtils.cpp b/llvm/lib/Transforms/Utils/ModuleUtils.cpp index 7c9ab7f..d6a6be2 100644 --- a/llvm/lib/Transforms/Utils/ModuleUtils.cpp +++ b/llvm/lib/Transforms/Utils/ModuleUtils.cpp @@ -264,3 +264,16 @@ void VFABI::setVectorVariantNames( CI->addFnAttr( Attribute::get(M->getContext(), MappingsAttrName, Buffer.str())); } + +void llvm::embedBufferInModule(Module &M, MemoryBufferRef Buf, + StringRef SectionName) { + // Embed the buffer into the module. + Constant *ModuleConstant = ConstantDataArray::get( + M.getContext(), makeArrayRef(Buf.getBufferStart(), Buf.getBufferSize())); + GlobalVariable *GV = new GlobalVariable( + M, ModuleConstant->getType(), true, GlobalValue::PrivateLinkage, + ModuleConstant, "llvm.embedded.object"); + GV->setSection(SectionName); + + appendToCompilerUsed(M, GV); +} -- cgit v1.1