-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Pass TargetMachine from from Clang to BitcodeWriter
and ThinLTOBitcodeWriter
pass for thin and fat LTO respectively.
#143692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-llvm-analysis @llvm/pr-subscribers-clang-codegen Author: Garvit Gupta (quic-garvgupt) ChangesCurrently in the This patch fixes the above issue. Fixes #112920 Patch is 29.10 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/143692.diff 15 Files Affected:
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 88b3a4943e0d8..077175b2d4f93 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1158,7 +1158,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
return;
}
MPM.addPass(ThinLTOBitcodeWriterPass(
- *OS, ThinLinkOS ? &ThinLinkOS->os() : nullptr));
+ *OS, ThinLinkOS ? &ThinLinkOS->os() : nullptr, false, TM.get()));
} else if (Action == Backend_EmitLL) {
MPM.addPass(PrintModulePass(*OS, "", CodeGenOpts.EmitLLVMUseLists,
/*EmitLTOSummary=*/true));
@@ -1176,7 +1176,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
}
if (Action == Backend_EmitBC) {
MPM.addPass(BitcodeWriterPass(*OS, CodeGenOpts.EmitLLVMUseLists,
- EmitLTOSummary));
+ EmitLTOSummary, false, TM.get()));
} else if (Action == Backend_EmitLL) {
MPM.addPass(PrintModulePass(*OS, "", CodeGenOpts.EmitLLVMUseLists,
EmitLTOSummary));
diff --git a/clang/test/CodeGen/Inputs/macros.s b/clang/test/CodeGen/Inputs/macros.s
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/clang/test/CodeGen/RISCV/include.c b/clang/test/CodeGen/RISCV/include.c
new file mode 100644
index 0000000000000..a46edf24b0af3
--- /dev/null
+++ b/clang/test/CodeGen/RISCV/include.c
@@ -0,0 +1,10 @@
+// RUN: %clang --target=riscv32-unknown-elf -I %S/../Inputs/ -flto %s -c -o %t.full.bc
+// RUN: llvm-dis %t.full.bc -o - | FileCheck %s
+// RUN: %clang --target=riscv32-unknown-elf -I %S/../Inputs/ -flto=thin %s -c -o %t.thin.bc
+// RUN: llvm-dis %t.thin.bc -o - | FileCheck %s
+__asm__(".include \"macros.s\"");
+
+void test() {
+}
+
+// CHECK: module asm ".include \22macros.s\22"
\ No newline at end of file
diff --git a/llvm/include/llvm/Analysis/ModuleSummaryAnalysis.h b/llvm/include/llvm/Analysis/ModuleSummaryAnalysis.h
index 7e78e9b9f2262..25cc2cc9337d2 100644
--- a/llvm/include/llvm/Analysis/ModuleSummaryAnalysis.h
+++ b/llvm/include/llvm/Analysis/ModuleSummaryAnalysis.h
@@ -27,6 +27,7 @@ class Function;
class Module;
class ProfileSummaryInfo;
class StackSafetyInfo;
+class TargetMachine;
/// Direct function to compute a \c ModuleSummaryIndex from a given module.
///
@@ -38,6 +39,7 @@ LLVM_ABI ModuleSummaryIndex buildModuleSummaryIndex(
const Module &M,
std::function<BlockFrequencyInfo *(const Function &F)> GetBFICallback,
ProfileSummaryInfo *PSI,
+ const TargetMachine *TM = nullptr,
std::function<const StackSafetyInfo *(const Function &F)> GetSSICallback =
[](const Function &F) -> const StackSafetyInfo * { return nullptr; });
diff --git a/llvm/include/llvm/Bitcode/BitcodeWriter.h b/llvm/include/llvm/Bitcode/BitcodeWriter.h
index e9b573733451b..3265d15f2e4d7 100644
--- a/llvm/include/llvm/Bitcode/BitcodeWriter.h
+++ b/llvm/include/llvm/Bitcode/BitcodeWriter.h
@@ -29,6 +29,7 @@ namespace llvm {
class BitstreamWriter;
class Module;
class raw_ostream;
+class TargetMachine;
class BitcodeWriter {
std::unique_ptr<BitstreamWriter> Stream;
@@ -45,10 +46,12 @@ class BitcodeWriter {
std::vector<Module *> Mods;
+ const TargetMachine *TM;
public:
/// Create a BitcodeWriter that writes to Buffer.
- LLVM_ABI BitcodeWriter(SmallVectorImpl<char> &Buffer);
- LLVM_ABI BitcodeWriter(raw_ostream &FS);
+ LLVM_ABI BitcodeWriter(SmallVectorImpl<char> &Buffer,
+ const TargetMachine *TM = nullptr);
+ LLVM_ABI BitcodeWriter(raw_ostream &FS, const TargetMachine *TM = nullptr);
LLVM_ABI ~BitcodeWriter();
@@ -135,7 +138,8 @@ LLVM_ABI void WriteBitcodeToFile(const Module &M, raw_ostream &Out,
bool ShouldPreserveUseListOrder = false,
const ModuleSummaryIndex *Index = nullptr,
bool GenerateHash = false,
- ModuleHash *ModHash = nullptr);
+ ModuleHash *ModHash = nullptr,
+ const TargetMachine *TM = nullptr);
/// Write the specified thin link bitcode file (i.e., the minimized bitcode
/// file) to the given raw output stream, where it will be written in a new
@@ -146,7 +150,8 @@ LLVM_ABI void WriteBitcodeToFile(const Module &M, raw_ostream &Out,
/// bitcode file writing.
LLVM_ABI void writeThinLinkBitcodeToFile(const Module &M, raw_ostream &Out,
const ModuleSummaryIndex &Index,
- const ModuleHash &ModHash);
+ const ModuleHash &ModHash,
+ const TargetMachine *TM = nullptr);
/// Write the specified module summary index to the given raw output stream,
/// where it will be written in a new bitcode block. This is used when
diff --git a/llvm/include/llvm/Bitcode/BitcodeWriterPass.h b/llvm/include/llvm/Bitcode/BitcodeWriterPass.h
index 3ce5db4ef1061..ae9fb763d4a64 100644
--- a/llvm/include/llvm/Bitcode/BitcodeWriterPass.h
+++ b/llvm/include/llvm/Bitcode/BitcodeWriterPass.h
@@ -22,6 +22,7 @@ class Module;
class ModulePass;
class Pass;
class raw_ostream;
+class TargetMachine;
/// Create and return a pass that writes the module to the specified
/// ostream. Note that this pass is designed for use with the legacy pass
@@ -31,7 +32,8 @@ class raw_ostream;
/// reproduced when deserialized.
LLVM_ABI ModulePass *
createBitcodeWriterPass(raw_ostream &Str,
- bool ShouldPreserveUseListOrder = false);
+ bool ShouldPreserveUseListOrder = false,
+ const TargetMachine *TM = nullptr);
/// Check whether a pass is a BitcodeWriterPass.
LLVM_ABI bool isBitcodeWriterPass(Pass *P);
@@ -45,6 +47,7 @@ class BitcodeWriterPass : public PassInfoMixin<BitcodeWriterPass> {
bool ShouldPreserveUseListOrder;
bool EmitSummaryIndex;
bool EmitModuleHash;
+ const TargetMachine *TM;
public:
/// Construct a bitcode writer pass around a particular output stream.
@@ -57,9 +60,11 @@ class BitcodeWriterPass : public PassInfoMixin<BitcodeWriterPass> {
explicit BitcodeWriterPass(raw_ostream &OS,
bool ShouldPreserveUseListOrder = false,
bool EmitSummaryIndex = false,
- bool EmitModuleHash = false)
+ bool EmitModuleHash = false,
+ const TargetMachine *TM = nullptr)
: OS(OS), ShouldPreserveUseListOrder(ShouldPreserveUseListOrder),
- EmitSummaryIndex(EmitSummaryIndex), EmitModuleHash(EmitModuleHash) {}
+ EmitSummaryIndex(EmitSummaryIndex), EmitModuleHash(EmitModuleHash),
+ TM(TM) {}
/// Run the bitcode writer pass, and output the module to the selected
/// output stream.
diff --git a/llvm/include/llvm/Object/IRSymtab.h b/llvm/include/llvm/Object/IRSymtab.h
index 0b7d6e0734e82..582945985841c 100644
--- a/llvm/include/llvm/Object/IRSymtab.h
+++ b/llvm/include/llvm/Object/IRSymtab.h
@@ -41,6 +41,7 @@ namespace llvm {
struct BitcodeFileContents;
class StringTableBuilder;
+class TargetMachine;
namespace irsymtab {
@@ -164,8 +165,8 @@ struct Header {
/// Fills in Symtab and StrtabBuilder with a valid symbol and string table for
/// Mods.
LLVM_ABI Error build(ArrayRef<Module *> Mods, SmallVector<char, 0> &Symtab,
- StringTableBuilder &StrtabBuilder,
- BumpPtrAllocator &Alloc);
+ StringTableBuilder &StrtabBuilder, BumpPtrAllocator &Alloc,
+ const TargetMachine *TM = nullptr);
/// This represents a symbol that has been read from a storage::Symbol and
/// possibly a storage::Uncommon.
diff --git a/llvm/include/llvm/Object/ModuleSymbolTable.h b/llvm/include/llvm/Object/ModuleSymbolTable.h
index 564ce76b3feb1..274f20ac225bf 100644
--- a/llvm/include/llvm/Object/ModuleSymbolTable.h
+++ b/llvm/include/llvm/Object/ModuleSymbolTable.h
@@ -30,6 +30,7 @@ namespace llvm {
class GlobalValue;
class Module;
+class TargetMachine;
class ModuleSymbolTable {
public:
@@ -45,7 +46,7 @@ class ModuleSymbolTable {
public:
ArrayRef<Symbol> symbols() const { return SymTab; }
- LLVM_ABI void addModule(Module *M);
+ LLVM_ABI void addModule(Module *M, const TargetMachine *TM = nullptr);
LLVM_ABI void printSymbolName(raw_ostream &OS, Symbol S) const;
LLVM_ABI uint32_t getSymbolFlags(Symbol S) const;
@@ -57,7 +58,8 @@ class ModuleSymbolTable {
/// and the associated flags.
LLVM_ABI static void CollectAsmSymbols(
const Module &M,
- function_ref<void(StringRef, object::BasicSymbolRef::Flags)> AsmSymbol);
+ function_ref<void(StringRef, object::BasicSymbolRef::Flags)> AsmSymbol,
+ const TargetMachine *TM = nullptr);
/// Parse inline ASM and collect the symvers directives that are defined in
/// the current module.
diff --git a/llvm/include/llvm/Transforms/IPO/ThinLTOBitcodeWriter.h b/llvm/include/llvm/Transforms/IPO/ThinLTOBitcodeWriter.h
index a21db26f1edbc..d0d34b65d148a 100644
--- a/llvm/include/llvm/Transforms/IPO/ThinLTOBitcodeWriter.h
+++ b/llvm/include/llvm/Transforms/IPO/ThinLTOBitcodeWriter.h
@@ -22,20 +22,23 @@
namespace llvm {
class Module;
class raw_ostream;
+class TargetMachine;
class ThinLTOBitcodeWriterPass
: public PassInfoMixin<ThinLTOBitcodeWriterPass> {
raw_ostream &OS;
raw_ostream *ThinLinkOS;
const bool ShouldPreserveUseListOrder;
+ const TargetMachine *TM;
public:
// Writes bitcode to OS. Also write thin link file to ThinLinkOS, if
// it's not nullptr.
ThinLTOBitcodeWriterPass(raw_ostream &OS, raw_ostream *ThinLinkOS,
- bool ShouldPreserveUseListOrder = false)
+ bool ShouldPreserveUseListOrder = false,
+ const TargetMachine* TM = nullptr)
: OS(OS), ThinLinkOS(ThinLinkOS),
- ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {}
+ ShouldPreserveUseListOrder(ShouldPreserveUseListOrder), TM(TM) {}
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
diff --git a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
index a317ac471a231..8d5ac051c0dd1 100644
--- a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -934,7 +934,7 @@ static void setLiveRoot(ModuleSummaryIndex &Index, StringRef Name) {
ModuleSummaryIndex llvm::buildModuleSummaryIndex(
const Module &M,
std::function<BlockFrequencyInfo *(const Function &F)> GetBFICallback,
- ProfileSummaryInfo *PSI,
+ ProfileSummaryInfo *PSI, const TargetMachine *TM,
std::function<const StackSafetyInfo *(const Function &F)> GetSSICallback) {
assert(PSI);
bool EnableSplitLTOUnit = false;
@@ -1031,7 +1031,7 @@ ModuleSummaryIndex llvm::buildModuleSummaryIndex(
SmallVector<ValueInfo, 0>{});
Index.addGlobalValueSummary(*GV, std::move(Summary));
}
- });
+ }, TM);
}
bool IsThinLTO = true;
@@ -1144,8 +1144,8 @@ ModuleSummaryIndex llvm::buildModuleSummaryIndex(
AnalysisKey ModuleSummaryIndexAnalysis::Key;
-ModuleSummaryIndex
-ModuleSummaryIndexAnalysis::run(Module &M, ModuleAnalysisManager &AM) {
+ModuleSummaryIndex ModuleSummaryIndexAnalysis::run(Module &M,
+ ModuleAnalysisManager &AM) {
ProfileSummaryInfo &PSI = AM.getResult<ProfileSummaryAnalysis>(M);
auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
bool NeedSSI = needsParamAccessSummary(M);
@@ -1155,7 +1155,7 @@ ModuleSummaryIndexAnalysis::run(Module &M, ModuleAnalysisManager &AM) {
return &FAM.getResult<BlockFrequencyAnalysis>(
*const_cast<Function *>(&F));
},
- &PSI,
+ &PSI, nullptr,
[&FAM, NeedSSI](const Function &F) -> const StackSafetyInfo * {
return NeedSSI ? &FAM.getResult<StackSafetyAnalysis>(
const_cast<Function &>(F))
@@ -1190,7 +1190,7 @@ bool ModuleSummaryIndexWrapperPass::runOnModule(Module &M) {
*const_cast<Function *>(&F))
.getBFI());
},
- PSI,
+ PSI, nullptr,
[&](const Function &F) -> const StackSafetyInfo * {
return NeedSSI ? &getAnalysis<StackSafetyInfoWrapperPass>(
const_cast<Function &>(F))
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 628b939af19ce..fa9ad8f762384 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -5357,13 +5357,14 @@ static void writeBitcodeHeader(BitstreamWriter &Stream) {
Stream.Emit(0xD, 4);
}
-BitcodeWriter::BitcodeWriter(SmallVectorImpl<char> &Buffer)
- : Stream(new BitstreamWriter(Buffer)) {
+BitcodeWriter::BitcodeWriter(SmallVectorImpl<char> &Buffer,
+ const TargetMachine *TM)
+ : Stream(new BitstreamWriter(Buffer)), TM(TM) {
writeBitcodeHeader(*Stream);
}
-BitcodeWriter::BitcodeWriter(raw_ostream &FS)
- : Stream(new BitstreamWriter(FS, FlushThreshold)) {
+BitcodeWriter::BitcodeWriter(raw_ostream &FS, const TargetMachine *TM)
+ : Stream(new BitstreamWriter(FS, FlushThreshold)), TM(TM) {
writeBitcodeHeader(*Stream);
}
@@ -5405,7 +5406,7 @@ void BitcodeWriter::writeSymtab() {
// module is malformed (e.g. it contains an invalid alias). Writing a symbol
// table is not required for correctness, but we still want to be able to
// write malformed modules to bitcode files, so swallow the error.
- if (Error E = irsymtab::build(Mods, Symtab, StrtabBuilder, Alloc)) {
+ if (Error E = irsymtab::build(Mods, Symtab, StrtabBuilder, Alloc, TM)) {
consumeError(std::move(E));
return;
}
@@ -5465,7 +5466,8 @@ void BitcodeWriter::writeIndex(
void llvm::WriteBitcodeToFile(const Module &M, raw_ostream &Out,
bool ShouldPreserveUseListOrder,
const ModuleSummaryIndex *Index,
- bool GenerateHash, ModuleHash *ModHash) {
+ bool GenerateHash, ModuleHash *ModHash,
+ const TargetMachine *TM) {
auto Write = [&](BitcodeWriter &Writer) {
Writer.writeModule(M, ShouldPreserveUseListOrder, Index, GenerateHash,
ModHash);
@@ -5486,7 +5488,7 @@ void llvm::WriteBitcodeToFile(const Module &M, raw_ostream &Out,
emitDarwinBCHeaderAndTrailer(Buffer, TT);
Out.write(Buffer.data(), Buffer.size());
} else {
- BitcodeWriter Writer(Out);
+ BitcodeWriter Writer(Out, TM);
Write(Writer);
}
}
@@ -5672,11 +5674,12 @@ void BitcodeWriter::writeThinLinkBitcode(const Module &M,
// writing the per-module index file for ThinLTO.
void llvm::writeThinLinkBitcodeToFile(const Module &M, raw_ostream &Out,
const ModuleSummaryIndex &Index,
- const ModuleHash &ModHash) {
+ const ModuleHash &ModHash,
+ const TargetMachine* TM) {
SmallVector<char, 0> Buffer;
Buffer.reserve(256 * 1024);
- BitcodeWriter Writer(Buffer);
+ BitcodeWriter Writer(Buffer, TM);
Writer.writeThinLinkBitcode(M, Index, ModHash);
Writer.writeSymtab();
Writer.writeStrtab();
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp
index fb393d33df3b2..fda117efbcae4 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp
@@ -11,7 +11,10 @@
//===----------------------------------------------------------------------===//
#include "llvm/Bitcode/BitcodeWriterPass.h"
+#include "llvm/Analysis/BlockFrequencyInfo.h"
#include "llvm/Analysis/ModuleSummaryAnalysis.h"
+#include "llvm/Analysis/ProfileSummaryInfo.h"
+#include "llvm/Analysis/StackSafetyAnalysis.h"
#include "llvm/Bitcode/BitcodeWriter.h"
#include "llvm/IR/PassManager.h"
#include "llvm/InitializePasses.h"
@@ -23,48 +26,66 @@ PreservedAnalyses BitcodeWriterPass::run(Module &M, ModuleAnalysisManager &AM) {
if (M.IsNewDbgInfoFormat)
M.removeDebugIntrinsicDeclarations();
- const ModuleSummaryIndex *Index =
- EmitSummaryIndex ? &(AM.getResult<ModuleSummaryIndexAnalysis>(M))
- : nullptr;
- WriteBitcodeToFile(M, OS, ShouldPreserveUseListOrder, Index, EmitModuleHash);
+ ProfileSummaryInfo &PSI = AM.getResult<ProfileSummaryAnalysis>(M);
+ auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
+ bool NeedSSI = needsParamAccessSummary(M);
+ std::unique_ptr<ModuleSummaryIndex> NewIndex = nullptr;
+ if (EmitSummaryIndex) {
+ NewIndex = std::make_unique<ModuleSummaryIndex>(buildModuleSummaryIndex(
+ M,
+ [&FAM](const Function &F) {
+ return &FAM.getResult<BlockFrequencyAnalysis>(
+ *const_cast<Function *>(&F));
+ },
+ &PSI, TM,
+ [&FAM, NeedSSI](const Function &F) -> const StackSafetyInfo * {
+ return NeedSSI ? &FAM.getResult<StackSafetyAnalysis>(
+ const_cast<Function &>(F))
+ : nullptr;
+ }));
+ }
+ WriteBitcodeToFile(M, OS, ShouldPreserveUseListOrder, NewIndex.get(),
+ EmitModuleHash, /*ModHash=*/nullptr, TM);
return PreservedAnalyses::all();
}
namespace {
- class WriteBitcodePass : public ModulePass {
- raw_ostream &OS; // raw_ostream to print on
- bool ShouldPreserveUseListOrder;
+class WriteBitcodePass : public ModulePass {
+ raw_ostream &OS; // raw_ostream to print on
+ bool ShouldPreserveUseListOrder;
+ const TargetMachine *TM;
- public:
- static char ID; // Pass identification, replacement for typeid
- WriteBitcodePass() : ModulePass(ID), OS(dbgs()) {
- initializeWriteBitcodePassPass(*PassRegistry::getPassRegistry());
- }
+public:
+ static char ID; // Pass identification, replacement for typeid
+ WriteBitcodePass() : ModulePass(ID), OS(dbgs()) {
+ initializeWriteBitcodePassPass(*PassRegistry::getPassRegistry());
+ }
- explicit WriteBitcodePass(raw_ostream &o, bool ShouldPreserveUseListOrder)
- : ModulePass(ID), OS(o),
- ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {
- initializeWriteBitcodePassPass(*PassRegistry::getPassRegistry());
- }
+ explicit WriteBitcodePass(raw_ostream &O, bool ShouldPreserveUseListOrder,
+ const TargetMachine *TM = nullptr)
+ : ModulePass(ID), OS(O),
+ ShouldPreserveUseListOrder(ShouldPreserveUseListOrder), TM(TM) {
+ initializeWriteBitcodePassPass(*PassRegistry::getPassRegistry());
+ }
- StringRef getPassName() const override { return "Bitcode Writer"; }
+ StringRef getPassName() const override { return "Bitcode Writer"; }
- bool runOnModule(Module &M) override {
- ScopedDbgInfoFormatSetter FormatSetter(M, M.IsNewDbgInfoFormat);
- if (M.IsNewDbgInfoFormat)
- M.removeDebugIntrinsicDeclarations();
+ bool runOnModule(Module &M) override {
+ ScopedDbgInfoFormatSetter FormatSetter(M, M.IsNewDbgInfoFormat);
+ if (M.IsNewDbgInfoFormat)
+ M.removeDebugIntrinsicDeclarations();
- WriteBitcodeToFile(M, OS, ShouldPreserveUseListOrder, /*Index=*/nullptr,
- /*EmitModuleHash=*/false);
+ WriteBitcodeToFile(M, OS, ShouldPreserveUseListOrder, /*Index=*/nullptr,
+ /*GenerateHash=*/false,/*ModHash=*/nullptr, TM);
- return false;
- }
- void getAnalysisUsage(AnalysisUsage &AU) const override {
- AU.setPreservesAll();
- }
- };
-}
+ return false;
+ }
+ void getAnalysisUsage(AnalysisUsage &AU) const override {
+ AU.setPreservesAll();
+ }
+};
+} // namespace
char WriteBitcodePass::ID = 0;
INITIALIZE_PASS_BEGIN(WriteBitcodePass, "write-bitcode", "Write Bitcode", false,
@@ -74,8 +95,9 @@ INITIALIZE_PASS_END(WriteBitcodePass, "write-bitcode", "Write Bitcode", false,
...
[truncated]
|
@llvm/pr-subscribers-clang Author: Garvit Gupta (quic-garvgupt) ChangesCurrently in the This patch fixes the above issue. Fixes #112920 Patch is 29.10 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/143692.diff 15 Files Affected:
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 88b3a4943e0d8..077175b2d4f93 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1158,7 +1158,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
return;
}
MPM.addPass(ThinLTOBitcodeWriterPass(
- *OS, ThinLinkOS ? &ThinLinkOS->os() : nullptr));
+ *OS, ThinLinkOS ? &ThinLinkOS->os() : nullptr, false, TM.get()));
} else if (Action == Backend_EmitLL) {
MPM.addPass(PrintModulePass(*OS, "", CodeGenOpts.EmitLLVMUseLists,
/*EmitLTOSummary=*/true));
@@ -1176,7 +1176,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
}
if (Action == Backend_EmitBC) {
MPM.addPass(BitcodeWriterPass(*OS, CodeGenOpts.EmitLLVMUseLists,
- EmitLTOSummary));
+ EmitLTOSummary, false, TM.get()));
} else if (Action == Backend_EmitLL) {
MPM.addPass(PrintModulePass(*OS, "", CodeGenOpts.EmitLLVMUseLists,
EmitLTOSummary));
diff --git a/clang/test/CodeGen/Inputs/macros.s b/clang/test/CodeGen/Inputs/macros.s
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/clang/test/CodeGen/RISCV/include.c b/clang/test/CodeGen/RISCV/include.c
new file mode 100644
index 0000000000000..a46edf24b0af3
--- /dev/null
+++ b/clang/test/CodeGen/RISCV/include.c
@@ -0,0 +1,10 @@
+// RUN: %clang --target=riscv32-unknown-elf -I %S/../Inputs/ -flto %s -c -o %t.full.bc
+// RUN: llvm-dis %t.full.bc -o - | FileCheck %s
+// RUN: %clang --target=riscv32-unknown-elf -I %S/../Inputs/ -flto=thin %s -c -o %t.thin.bc
+// RUN: llvm-dis %t.thin.bc -o - | FileCheck %s
+__asm__(".include \"macros.s\"");
+
+void test() {
+}
+
+// CHECK: module asm ".include \22macros.s\22"
\ No newline at end of file
diff --git a/llvm/include/llvm/Analysis/ModuleSummaryAnalysis.h b/llvm/include/llvm/Analysis/ModuleSummaryAnalysis.h
index 7e78e9b9f2262..25cc2cc9337d2 100644
--- a/llvm/include/llvm/Analysis/ModuleSummaryAnalysis.h
+++ b/llvm/include/llvm/Analysis/ModuleSummaryAnalysis.h
@@ -27,6 +27,7 @@ class Function;
class Module;
class ProfileSummaryInfo;
class StackSafetyInfo;
+class TargetMachine;
/// Direct function to compute a \c ModuleSummaryIndex from a given module.
///
@@ -38,6 +39,7 @@ LLVM_ABI ModuleSummaryIndex buildModuleSummaryIndex(
const Module &M,
std::function<BlockFrequencyInfo *(const Function &F)> GetBFICallback,
ProfileSummaryInfo *PSI,
+ const TargetMachine *TM = nullptr,
std::function<const StackSafetyInfo *(const Function &F)> GetSSICallback =
[](const Function &F) -> const StackSafetyInfo * { return nullptr; });
diff --git a/llvm/include/llvm/Bitcode/BitcodeWriter.h b/llvm/include/llvm/Bitcode/BitcodeWriter.h
index e9b573733451b..3265d15f2e4d7 100644
--- a/llvm/include/llvm/Bitcode/BitcodeWriter.h
+++ b/llvm/include/llvm/Bitcode/BitcodeWriter.h
@@ -29,6 +29,7 @@ namespace llvm {
class BitstreamWriter;
class Module;
class raw_ostream;
+class TargetMachine;
class BitcodeWriter {
std::unique_ptr<BitstreamWriter> Stream;
@@ -45,10 +46,12 @@ class BitcodeWriter {
std::vector<Module *> Mods;
+ const TargetMachine *TM;
public:
/// Create a BitcodeWriter that writes to Buffer.
- LLVM_ABI BitcodeWriter(SmallVectorImpl<char> &Buffer);
- LLVM_ABI BitcodeWriter(raw_ostream &FS);
+ LLVM_ABI BitcodeWriter(SmallVectorImpl<char> &Buffer,
+ const TargetMachine *TM = nullptr);
+ LLVM_ABI BitcodeWriter(raw_ostream &FS, const TargetMachine *TM = nullptr);
LLVM_ABI ~BitcodeWriter();
@@ -135,7 +138,8 @@ LLVM_ABI void WriteBitcodeToFile(const Module &M, raw_ostream &Out,
bool ShouldPreserveUseListOrder = false,
const ModuleSummaryIndex *Index = nullptr,
bool GenerateHash = false,
- ModuleHash *ModHash = nullptr);
+ ModuleHash *ModHash = nullptr,
+ const TargetMachine *TM = nullptr);
/// Write the specified thin link bitcode file (i.e., the minimized bitcode
/// file) to the given raw output stream, where it will be written in a new
@@ -146,7 +150,8 @@ LLVM_ABI void WriteBitcodeToFile(const Module &M, raw_ostream &Out,
/// bitcode file writing.
LLVM_ABI void writeThinLinkBitcodeToFile(const Module &M, raw_ostream &Out,
const ModuleSummaryIndex &Index,
- const ModuleHash &ModHash);
+ const ModuleHash &ModHash,
+ const TargetMachine *TM = nullptr);
/// Write the specified module summary index to the given raw output stream,
/// where it will be written in a new bitcode block. This is used when
diff --git a/llvm/include/llvm/Bitcode/BitcodeWriterPass.h b/llvm/include/llvm/Bitcode/BitcodeWriterPass.h
index 3ce5db4ef1061..ae9fb763d4a64 100644
--- a/llvm/include/llvm/Bitcode/BitcodeWriterPass.h
+++ b/llvm/include/llvm/Bitcode/BitcodeWriterPass.h
@@ -22,6 +22,7 @@ class Module;
class ModulePass;
class Pass;
class raw_ostream;
+class TargetMachine;
/// Create and return a pass that writes the module to the specified
/// ostream. Note that this pass is designed for use with the legacy pass
@@ -31,7 +32,8 @@ class raw_ostream;
/// reproduced when deserialized.
LLVM_ABI ModulePass *
createBitcodeWriterPass(raw_ostream &Str,
- bool ShouldPreserveUseListOrder = false);
+ bool ShouldPreserveUseListOrder = false,
+ const TargetMachine *TM = nullptr);
/// Check whether a pass is a BitcodeWriterPass.
LLVM_ABI bool isBitcodeWriterPass(Pass *P);
@@ -45,6 +47,7 @@ class BitcodeWriterPass : public PassInfoMixin<BitcodeWriterPass> {
bool ShouldPreserveUseListOrder;
bool EmitSummaryIndex;
bool EmitModuleHash;
+ const TargetMachine *TM;
public:
/// Construct a bitcode writer pass around a particular output stream.
@@ -57,9 +60,11 @@ class BitcodeWriterPass : public PassInfoMixin<BitcodeWriterPass> {
explicit BitcodeWriterPass(raw_ostream &OS,
bool ShouldPreserveUseListOrder = false,
bool EmitSummaryIndex = false,
- bool EmitModuleHash = false)
+ bool EmitModuleHash = false,
+ const TargetMachine *TM = nullptr)
: OS(OS), ShouldPreserveUseListOrder(ShouldPreserveUseListOrder),
- EmitSummaryIndex(EmitSummaryIndex), EmitModuleHash(EmitModuleHash) {}
+ EmitSummaryIndex(EmitSummaryIndex), EmitModuleHash(EmitModuleHash),
+ TM(TM) {}
/// Run the bitcode writer pass, and output the module to the selected
/// output stream.
diff --git a/llvm/include/llvm/Object/IRSymtab.h b/llvm/include/llvm/Object/IRSymtab.h
index 0b7d6e0734e82..582945985841c 100644
--- a/llvm/include/llvm/Object/IRSymtab.h
+++ b/llvm/include/llvm/Object/IRSymtab.h
@@ -41,6 +41,7 @@ namespace llvm {
struct BitcodeFileContents;
class StringTableBuilder;
+class TargetMachine;
namespace irsymtab {
@@ -164,8 +165,8 @@ struct Header {
/// Fills in Symtab and StrtabBuilder with a valid symbol and string table for
/// Mods.
LLVM_ABI Error build(ArrayRef<Module *> Mods, SmallVector<char, 0> &Symtab,
- StringTableBuilder &StrtabBuilder,
- BumpPtrAllocator &Alloc);
+ StringTableBuilder &StrtabBuilder, BumpPtrAllocator &Alloc,
+ const TargetMachine *TM = nullptr);
/// This represents a symbol that has been read from a storage::Symbol and
/// possibly a storage::Uncommon.
diff --git a/llvm/include/llvm/Object/ModuleSymbolTable.h b/llvm/include/llvm/Object/ModuleSymbolTable.h
index 564ce76b3feb1..274f20ac225bf 100644
--- a/llvm/include/llvm/Object/ModuleSymbolTable.h
+++ b/llvm/include/llvm/Object/ModuleSymbolTable.h
@@ -30,6 +30,7 @@ namespace llvm {
class GlobalValue;
class Module;
+class TargetMachine;
class ModuleSymbolTable {
public:
@@ -45,7 +46,7 @@ class ModuleSymbolTable {
public:
ArrayRef<Symbol> symbols() const { return SymTab; }
- LLVM_ABI void addModule(Module *M);
+ LLVM_ABI void addModule(Module *M, const TargetMachine *TM = nullptr);
LLVM_ABI void printSymbolName(raw_ostream &OS, Symbol S) const;
LLVM_ABI uint32_t getSymbolFlags(Symbol S) const;
@@ -57,7 +58,8 @@ class ModuleSymbolTable {
/// and the associated flags.
LLVM_ABI static void CollectAsmSymbols(
const Module &M,
- function_ref<void(StringRef, object::BasicSymbolRef::Flags)> AsmSymbol);
+ function_ref<void(StringRef, object::BasicSymbolRef::Flags)> AsmSymbol,
+ const TargetMachine *TM = nullptr);
/// Parse inline ASM and collect the symvers directives that are defined in
/// the current module.
diff --git a/llvm/include/llvm/Transforms/IPO/ThinLTOBitcodeWriter.h b/llvm/include/llvm/Transforms/IPO/ThinLTOBitcodeWriter.h
index a21db26f1edbc..d0d34b65d148a 100644
--- a/llvm/include/llvm/Transforms/IPO/ThinLTOBitcodeWriter.h
+++ b/llvm/include/llvm/Transforms/IPO/ThinLTOBitcodeWriter.h
@@ -22,20 +22,23 @@
namespace llvm {
class Module;
class raw_ostream;
+class TargetMachine;
class ThinLTOBitcodeWriterPass
: public PassInfoMixin<ThinLTOBitcodeWriterPass> {
raw_ostream &OS;
raw_ostream *ThinLinkOS;
const bool ShouldPreserveUseListOrder;
+ const TargetMachine *TM;
public:
// Writes bitcode to OS. Also write thin link file to ThinLinkOS, if
// it's not nullptr.
ThinLTOBitcodeWriterPass(raw_ostream &OS, raw_ostream *ThinLinkOS,
- bool ShouldPreserveUseListOrder = false)
+ bool ShouldPreserveUseListOrder = false,
+ const TargetMachine* TM = nullptr)
: OS(OS), ThinLinkOS(ThinLinkOS),
- ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {}
+ ShouldPreserveUseListOrder(ShouldPreserveUseListOrder), TM(TM) {}
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
diff --git a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
index a317ac471a231..8d5ac051c0dd1 100644
--- a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -934,7 +934,7 @@ static void setLiveRoot(ModuleSummaryIndex &Index, StringRef Name) {
ModuleSummaryIndex llvm::buildModuleSummaryIndex(
const Module &M,
std::function<BlockFrequencyInfo *(const Function &F)> GetBFICallback,
- ProfileSummaryInfo *PSI,
+ ProfileSummaryInfo *PSI, const TargetMachine *TM,
std::function<const StackSafetyInfo *(const Function &F)> GetSSICallback) {
assert(PSI);
bool EnableSplitLTOUnit = false;
@@ -1031,7 +1031,7 @@ ModuleSummaryIndex llvm::buildModuleSummaryIndex(
SmallVector<ValueInfo, 0>{});
Index.addGlobalValueSummary(*GV, std::move(Summary));
}
- });
+ }, TM);
}
bool IsThinLTO = true;
@@ -1144,8 +1144,8 @@ ModuleSummaryIndex llvm::buildModuleSummaryIndex(
AnalysisKey ModuleSummaryIndexAnalysis::Key;
-ModuleSummaryIndex
-ModuleSummaryIndexAnalysis::run(Module &M, ModuleAnalysisManager &AM) {
+ModuleSummaryIndex ModuleSummaryIndexAnalysis::run(Module &M,
+ ModuleAnalysisManager &AM) {
ProfileSummaryInfo &PSI = AM.getResult<ProfileSummaryAnalysis>(M);
auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
bool NeedSSI = needsParamAccessSummary(M);
@@ -1155,7 +1155,7 @@ ModuleSummaryIndexAnalysis::run(Module &M, ModuleAnalysisManager &AM) {
return &FAM.getResult<BlockFrequencyAnalysis>(
*const_cast<Function *>(&F));
},
- &PSI,
+ &PSI, nullptr,
[&FAM, NeedSSI](const Function &F) -> const StackSafetyInfo * {
return NeedSSI ? &FAM.getResult<StackSafetyAnalysis>(
const_cast<Function &>(F))
@@ -1190,7 +1190,7 @@ bool ModuleSummaryIndexWrapperPass::runOnModule(Module &M) {
*const_cast<Function *>(&F))
.getBFI());
},
- PSI,
+ PSI, nullptr,
[&](const Function &F) -> const StackSafetyInfo * {
return NeedSSI ? &getAnalysis<StackSafetyInfoWrapperPass>(
const_cast<Function &>(F))
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 628b939af19ce..fa9ad8f762384 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -5357,13 +5357,14 @@ static void writeBitcodeHeader(BitstreamWriter &Stream) {
Stream.Emit(0xD, 4);
}
-BitcodeWriter::BitcodeWriter(SmallVectorImpl<char> &Buffer)
- : Stream(new BitstreamWriter(Buffer)) {
+BitcodeWriter::BitcodeWriter(SmallVectorImpl<char> &Buffer,
+ const TargetMachine *TM)
+ : Stream(new BitstreamWriter(Buffer)), TM(TM) {
writeBitcodeHeader(*Stream);
}
-BitcodeWriter::BitcodeWriter(raw_ostream &FS)
- : Stream(new BitstreamWriter(FS, FlushThreshold)) {
+BitcodeWriter::BitcodeWriter(raw_ostream &FS, const TargetMachine *TM)
+ : Stream(new BitstreamWriter(FS, FlushThreshold)), TM(TM) {
writeBitcodeHeader(*Stream);
}
@@ -5405,7 +5406,7 @@ void BitcodeWriter::writeSymtab() {
// module is malformed (e.g. it contains an invalid alias). Writing a symbol
// table is not required for correctness, but we still want to be able to
// write malformed modules to bitcode files, so swallow the error.
- if (Error E = irsymtab::build(Mods, Symtab, StrtabBuilder, Alloc)) {
+ if (Error E = irsymtab::build(Mods, Symtab, StrtabBuilder, Alloc, TM)) {
consumeError(std::move(E));
return;
}
@@ -5465,7 +5466,8 @@ void BitcodeWriter::writeIndex(
void llvm::WriteBitcodeToFile(const Module &M, raw_ostream &Out,
bool ShouldPreserveUseListOrder,
const ModuleSummaryIndex *Index,
- bool GenerateHash, ModuleHash *ModHash) {
+ bool GenerateHash, ModuleHash *ModHash,
+ const TargetMachine *TM) {
auto Write = [&](BitcodeWriter &Writer) {
Writer.writeModule(M, ShouldPreserveUseListOrder, Index, GenerateHash,
ModHash);
@@ -5486,7 +5488,7 @@ void llvm::WriteBitcodeToFile(const Module &M, raw_ostream &Out,
emitDarwinBCHeaderAndTrailer(Buffer, TT);
Out.write(Buffer.data(), Buffer.size());
} else {
- BitcodeWriter Writer(Out);
+ BitcodeWriter Writer(Out, TM);
Write(Writer);
}
}
@@ -5672,11 +5674,12 @@ void BitcodeWriter::writeThinLinkBitcode(const Module &M,
// writing the per-module index file for ThinLTO.
void llvm::writeThinLinkBitcodeToFile(const Module &M, raw_ostream &Out,
const ModuleSummaryIndex &Index,
- const ModuleHash &ModHash) {
+ const ModuleHash &ModHash,
+ const TargetMachine* TM) {
SmallVector<char, 0> Buffer;
Buffer.reserve(256 * 1024);
- BitcodeWriter Writer(Buffer);
+ BitcodeWriter Writer(Buffer, TM);
Writer.writeThinLinkBitcode(M, Index, ModHash);
Writer.writeSymtab();
Writer.writeStrtab();
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp
index fb393d33df3b2..fda117efbcae4 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp
@@ -11,7 +11,10 @@
//===----------------------------------------------------------------------===//
#include "llvm/Bitcode/BitcodeWriterPass.h"
+#include "llvm/Analysis/BlockFrequencyInfo.h"
#include "llvm/Analysis/ModuleSummaryAnalysis.h"
+#include "llvm/Analysis/ProfileSummaryInfo.h"
+#include "llvm/Analysis/StackSafetyAnalysis.h"
#include "llvm/Bitcode/BitcodeWriter.h"
#include "llvm/IR/PassManager.h"
#include "llvm/InitializePasses.h"
@@ -23,48 +26,66 @@ PreservedAnalyses BitcodeWriterPass::run(Module &M, ModuleAnalysisManager &AM) {
if (M.IsNewDbgInfoFormat)
M.removeDebugIntrinsicDeclarations();
- const ModuleSummaryIndex *Index =
- EmitSummaryIndex ? &(AM.getResult<ModuleSummaryIndexAnalysis>(M))
- : nullptr;
- WriteBitcodeToFile(M, OS, ShouldPreserveUseListOrder, Index, EmitModuleHash);
+ ProfileSummaryInfo &PSI = AM.getResult<ProfileSummaryAnalysis>(M);
+ auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
+ bool NeedSSI = needsParamAccessSummary(M);
+ std::unique_ptr<ModuleSummaryIndex> NewIndex = nullptr;
+ if (EmitSummaryIndex) {
+ NewIndex = std::make_unique<ModuleSummaryIndex>(buildModuleSummaryIndex(
+ M,
+ [&FAM](const Function &F) {
+ return &FAM.getResult<BlockFrequencyAnalysis>(
+ *const_cast<Function *>(&F));
+ },
+ &PSI, TM,
+ [&FAM, NeedSSI](const Function &F) -> const StackSafetyInfo * {
+ return NeedSSI ? &FAM.getResult<StackSafetyAnalysis>(
+ const_cast<Function &>(F))
+ : nullptr;
+ }));
+ }
+ WriteBitcodeToFile(M, OS, ShouldPreserveUseListOrder, NewIndex.get(),
+ EmitModuleHash, /*ModHash=*/nullptr, TM);
return PreservedAnalyses::all();
}
namespace {
- class WriteBitcodePass : public ModulePass {
- raw_ostream &OS; // raw_ostream to print on
- bool ShouldPreserveUseListOrder;
+class WriteBitcodePass : public ModulePass {
+ raw_ostream &OS; // raw_ostream to print on
+ bool ShouldPreserveUseListOrder;
+ const TargetMachine *TM;
- public:
- static char ID; // Pass identification, replacement for typeid
- WriteBitcodePass() : ModulePass(ID), OS(dbgs()) {
- initializeWriteBitcodePassPass(*PassRegistry::getPassRegistry());
- }
+public:
+ static char ID; // Pass identification, replacement for typeid
+ WriteBitcodePass() : ModulePass(ID), OS(dbgs()) {
+ initializeWriteBitcodePassPass(*PassRegistry::getPassRegistry());
+ }
- explicit WriteBitcodePass(raw_ostream &o, bool ShouldPreserveUseListOrder)
- : ModulePass(ID), OS(o),
- ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {
- initializeWriteBitcodePassPass(*PassRegistry::getPassRegistry());
- }
+ explicit WriteBitcodePass(raw_ostream &O, bool ShouldPreserveUseListOrder,
+ const TargetMachine *TM = nullptr)
+ : ModulePass(ID), OS(O),
+ ShouldPreserveUseListOrder(ShouldPreserveUseListOrder), TM(TM) {
+ initializeWriteBitcodePassPass(*PassRegistry::getPassRegistry());
+ }
- StringRef getPassName() const override { return "Bitcode Writer"; }
+ StringRef getPassName() const override { return "Bitcode Writer"; }
- bool runOnModule(Module &M) override {
- ScopedDbgInfoFormatSetter FormatSetter(M, M.IsNewDbgInfoFormat);
- if (M.IsNewDbgInfoFormat)
- M.removeDebugIntrinsicDeclarations();
+ bool runOnModule(Module &M) override {
+ ScopedDbgInfoFormatSetter FormatSetter(M, M.IsNewDbgInfoFormat);
+ if (M.IsNewDbgInfoFormat)
+ M.removeDebugIntrinsicDeclarations();
- WriteBitcodeToFile(M, OS, ShouldPreserveUseListOrder, /*Index=*/nullptr,
- /*EmitModuleHash=*/false);
+ WriteBitcodeToFile(M, OS, ShouldPreserveUseListOrder, /*Index=*/nullptr,
+ /*GenerateHash=*/false,/*ModHash=*/nullptr, TM);
- return false;
- }
- void getAnalysisUsage(AnalysisUsage &AU) const override {
- AU.setPreservesAll();
- }
- };
-}
+ return false;
+ }
+ void getAnalysisUsage(AnalysisUsage &AU) const override {
+ AU.setPreservesAll();
+ }
+};
+} // namespace
char WriteBitcodePass::ID = 0;
INITIALIZE_PASS_BEGIN(WriteBitcodePass, "write-bitcode", "Write Bitcode", false,
@@ -74,8 +95,9 @@ INITIALIZE_PASS_END(WriteBitcodePass, "write-bitcode", "Write Bitcode", false,
...
[truncated]
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
`ThinLTOBitcodeWriter` pass for thin and fat LTO respectively. Currently in the `initializeRecordStreamer` function in the ModuleSymbolTable file, MCTargetOptions are initalized again even though they get populated in BackendUtil.cpp. Because of this, during lto, `IASSearchPaths` field of MCOptions which holds all include paths gets override and thus compiler is not able to locate files included using `.include` asm directive. This patch fixes the above issue. Fixes llvm#112920 Change-Id: I099a940a46c3d8403207bc5f06fede2010163c34
Gentle Ping! |
}); | ||
function_ref<void(StringRef, BasicSymbolRef::Flags)> AsmSymbol, | ||
const TargetMachine *TM) { | ||
initializeRecordStreamer( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why all the reformatting in this function? There are a bunch of lines reformatted in this file that seem unnecessary from a line length perspective from the new TM parameter.
@@ -89,6 +93,8 @@ initializeRecordStreamer(const Module &M, | |||
std::unique_ptr<MCAsmInfo> MAI(T->createMCAsmInfo(*MRI, TT.str(), MCOptions)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the MCOptions from TM be passed down to createMCAsmInfo?
class WriteBitcodePass : public ModulePass { | ||
raw_ostream &OS; // raw_ostream to print on | ||
bool ShouldPreserveUseListOrder; | ||
class WriteBitcodePass : public ModulePass { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't do unnecessary reformatting. Are you doing clang format on the entire file or just on the changed lines?
@@ -1158,7 +1158,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline( | |||
return; | |||
} | |||
MPM.addPass(ThinLTOBitcodeWriterPass( | |||
*OS, ThinLinkOS ? &ThinLinkOS->os() : nullptr)); | |||
*OS, ThinLinkOS ? &ThinLinkOS->os() : nullptr, false, TM.get())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please document constant parameters: https://llvm.org/docs/CodingStandards.html#comment-formatting
M.removeDebugIntrinsicDeclarations(); | ||
|
||
FunctionAnalysisManager &FAM = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than doing all this restructuring of the current callers of ModuleSummaryIndexAnalysis, can you just change that analysis pass to take the TM? E.g. see CustomizedAnalysis in llvm-project/llvm/unittests/IR
/PassManagerTest.cpp, and its invocation here
In the initializeRecordStreamer function within the ModuleSymbolTable file, MCTargetOptions are re-initialized, even though they are already populated in BackendUtil.cpp. As a result, during LTO (Link Time Optimization), the IASSearchPaths field of MCOptions—which stores all include paths—is overwritten. This causes the compiler to fail in locating files included via the .include assembly directive.
This patch fixes the above issue.
Fixes #112920