[llvm] 6fa3554 - [NFC][ThinLTO] Change command line passing to EmbedBitcodeInModule
Mircea Trofin via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 28 12:33:50 PDT 2020
Author: Mircea Trofin
Date: 2020-10-28T12:33:39-07:00
New Revision: 6fa35541a0af9d5493e288f574896ee33a8eae92
URL: https://github.com/llvm/llvm-project/commit/6fa35541a0af9d5493e288f574896ee33a8eae92
DIFF: https://github.com/llvm/llvm-project/commit/6fa35541a0af9d5493e288f574896ee33a8eae92.diff
LOG: [NFC][ThinLTO] Change command line passing to EmbedBitcodeInModule
Changing to pass by ref - less null checks to worry about.
Differential Revision: https://reviews.llvm.org/D90330
Added:
Modified:
clang/lib/CodeGen/BackendUtil.cpp
llvm/include/llvm/Bitcode/BitcodeWriter.h
llvm/include/llvm/LTO/LTOBackend.h
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/lib/LTO/LTOBackend.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 0991582005b8..918411b818be 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1625,7 +1625,7 @@ static void runThinLTOBackend(
if (Error E =
thinBackend(Conf, -1, AddStream, *M, *CombinedIndex, ImportList,
ModuleToDefinedGVSummaries[M->getModuleIdentifier()],
- ModuleMap, &CGOpts.CmdArgs)) {
+ ModuleMap, CGOpts.CmdArgs)) {
handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
errs() << "Error running ThinLTO backend: " << EIB.message() << '\n';
});
@@ -1709,5 +1709,5 @@ void clang::EmbedBitcode(llvm::Module *M, const CodeGenOptions &CGOpts,
llvm::EmbedBitcodeInModule(
*M, Buf, CGOpts.getEmbedBitcode() != CodeGenOptions::Embed_Marker,
CGOpts.getEmbedBitcode() != CodeGenOptions::Embed_Bitcode,
- &CGOpts.CmdArgs);
+ CGOpts.CmdArgs);
}
diff --git a/llvm/include/llvm/Bitcode/BitcodeWriter.h b/llvm/include/llvm/Bitcode/BitcodeWriter.h
index 74e9d103b7f3..36c3cb5eb249 100644
--- a/llvm/include/llvm/Bitcode/BitcodeWriter.h
+++ b/llvm/include/llvm/Bitcode/BitcodeWriter.h
@@ -152,14 +152,18 @@ class raw_ostream;
const std::map<std::string, GVSummaryMapTy>
*ModuleToSummariesForIndex = nullptr);
- /// Save a copy of the llvm IR as data in the __LLVM,__bitcode section.
+ /// If EmbedBitcode is set, save a copy of the llvm IR as data in the
+ /// __LLVM,__bitcode section (.llvmbc on non-MacOS).
/// If available, pass the serialized module via the Buf parameter. If not,
/// pass an empty (default-initialized) MemoryBufferRef, and the serialization
/// will be handled by this API. The same behavior happens if the provided Buf
/// is not bitcode (i.e. if it's invalid data or even textual LLVM assembly).
+ /// If EmbedMarker is set, the command line is also exported in
+ /// the corresponding section (__LLVM,_cmdline / .llvmcmd) - even if CmdArgs
+ /// were empty.
void EmbedBitcodeInModule(Module &M, MemoryBufferRef Buf, bool EmbedBitcode,
bool EmbedMarker,
- const std::vector<uint8_t> *CmdArgs);
+ const std::vector<uint8_t> &CmdArgs);
} // end namespace llvm
diff --git a/llvm/include/llvm/LTO/LTOBackend.h b/llvm/include/llvm/LTO/LTOBackend.h
index 63414b5c80dc..db3c8c092ef9 100644
--- a/llvm/include/llvm/LTO/LTOBackend.h
+++ b/llvm/include/llvm/LTO/LTOBackend.h
@@ -45,7 +45,7 @@ Error thinBackend(const Config &C, unsigned Task, AddStreamFn AddStream,
const FunctionImporter::ImportMapTy &ImportList,
const GVSummaryMapTy &DefinedGlobals,
MapVector<StringRef, BitcodeModule> &ModuleMap,
- const std::vector<uint8_t> *CmdArgs = nullptr);
+ const std::vector<uint8_t> &CmdArgs = std::vector<uint8_t>());
Error finalizeOptimizationRemarks(
std::unique_ptr<ToolOutputFile> DiagOutputFile);
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index d64dcd33d1bf..7cfa45812855 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4819,7 +4819,7 @@ static const char *getSectionNameForCommandline(const Triple &T) {
void llvm::EmbedBitcodeInModule(llvm::Module &M, llvm::MemoryBufferRef Buf,
bool EmbedBitcode, bool EmbedMarker,
- const std::vector<uint8_t> *CmdArgs) {
+ const std::vector<uint8_t> &CmdArgs) {
// Save llvm.compiler.used and remove it.
SmallVector<Constant *, 2> UsedArray;
SmallPtrSet<GlobalValue *, 4> UsedGlobals;
@@ -4878,8 +4878,8 @@ void llvm::EmbedBitcodeInModule(llvm::Module &M, llvm::MemoryBufferRef Buf,
// Skip if only bitcode needs to be embedded.
if (EmbedMarker) {
// Embed command-line options.
- ArrayRef<uint8_t> CmdData(const_cast<uint8_t *>(CmdArgs->data()),
- CmdArgs->size());
+ ArrayRef<uint8_t> CmdData(const_cast<uint8_t *>(CmdArgs.data()),
+ CmdArgs.size());
llvm::Constant *CmdConstant =
llvm::ConstantDataArray::get(M.getContext(), CmdData);
GV = new llvm::GlobalVariable(M, CmdConstant->getType(), true,
diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index fc39c1a57c8e..f4da6d87f719 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -358,7 +358,7 @@ static void runOldPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
bool opt(const Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod,
bool IsThinLTO, ModuleSummaryIndex *ExportSummary,
const ModuleSummaryIndex *ImportSummary,
- const std::vector<uint8_t> *CmdArgs = nullptr) {
+ const std::vector<uint8_t> &CmdArgs) {
if (EmbedBitcode == LTOBitcodeEmbedding::EmbedPostMergePreOptimized) {
// FIXME: the motivation for capturing post-merge bitcode and command line
// is replicating the compilation environment from bitcode, without needing
@@ -368,13 +368,14 @@ bool opt(const Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod,
// It's not very clear how the above motivation would map in the
// linker-based case, so we currently don't plumb the command line args in
// that case.
- if (CmdArgs == nullptr)
+ if (CmdArgs.empty())
LLVM_DEBUG(
dbgs() << "Post-(Thin)LTO merge bitcode embedding was requested, but "
"command line arguments are not available");
llvm::EmbedBitcodeInModule(Mod, llvm::MemoryBufferRef(),
/*EmbedBitcode*/ true,
- /*EmbedMarker*/ false, CmdArgs);
+ /*EmbedMarker*/ false,
+ /*Cmdline*/ CmdArgs);
}
// FIXME: Plumb the combined index into the new pass manager.
if (!Conf.OptPipeline.empty())
@@ -397,7 +398,8 @@ void codegen(const Config &Conf, TargetMachine *TM, AddStreamFn AddStream,
if (EmbedBitcode == LTOBitcodeEmbedding::EmbedOptimized)
llvm::EmbedBitcodeInModule(Mod, llvm::MemoryBufferRef(),
/*EmbedBitcode*/ true,
- /*EmbedMarker*/ false, /*CmdArgs*/ nullptr);
+ /*EmbedMarker*/ false,
+ /*CmdArgs*/ std::vector<uint8_t>());
std::unique_ptr<ToolOutputFile> DwoOut;
SmallString<1024> DwoFile(Conf.SplitDwarfOutput);
@@ -522,7 +524,8 @@ Error lto::backend(const Config &C, AddStreamFn AddStream,
if (!C.CodeGenOnly) {
if (!opt(C, TM.get(), 0, *Mod, /*IsThinLTO=*/false,
- /*ExportSummary=*/&CombinedIndex, /*ImportSummary=*/nullptr))
+ /*ExportSummary=*/&CombinedIndex, /*ImportSummary=*/nullptr,
+ /*CmdArgs*/ std::vector<uint8_t>()))
return Error::success();
}
@@ -561,7 +564,7 @@ Error lto::thinBackend(const Config &Conf, unsigned Task, AddStreamFn AddStream,
const FunctionImporter::ImportMapTy &ImportList,
const GVSummaryMapTy &DefinedGlobals,
MapVector<StringRef, BitcodeModule> &ModuleMap,
- const std::vector<uint8_t> *CmdArgs) {
+ const std::vector<uint8_t> &CmdArgs) {
Expected<const Target *> TOrErr = initAndLookupTarget(Conf, Mod);
if (!TOrErr)
return TOrErr.takeError();
More information about the llvm-commits
mailing list