Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 31 additions & 14 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,15 @@ extern "C" LLVMRustResult LLVMRustOptimize(
MPM.addPass(ThinLTOBitcodeWriterPass(
ThinLTODataOS, ThinLTOSummaryBufferRef ? &ThinLinkDataOS : nullptr));
} else {
MPM.addPass(BitcodeWriterPass(ThinLTODataOS));
// Force Full LTO summary for embedded bitcode under Fat LTO.
//
// Note the bitcode writer will only emit the full LTO block ID if the "ThinLTO"
// metadata is defined and explicitly set to zero. Otherwise, the thin LTO block
// ID will be emitted.
auto *Zero = ConstantInt::get(Type::getInt32Ty(TheModule->getContext()), 0);
TheModule->addModuleFlag(Module::Error, "ThinLTO", Zero);
MPM.addPass(BitcodeWriterPass(ThinLTODataOS, /*ShouldPreserveUseListOrder=*/false,
/*EmitSummaryIndex=*/true));
}
*ThinLTOBufferRef = ThinLTOBuffer.release();
if (ThinLTOSummaryBufferRef) {
Expand Down Expand Up @@ -1442,23 +1450,32 @@ extern "C" LLVMRustBuffer *LLVMRustModuleSerialize(LLVMModuleRef M,
{
auto OS = raw_string_ostream(Ret->data);
{
PassBuilder PB;
LoopAnalysisManager LAM;
FunctionAnalysisManager FAM;
CGSCCAnalysisManager CGAM;
ModuleAnalysisManager MAM;
PB.registerModuleAnalyses(MAM);
PB.registerCGSCCAnalyses(CGAM);
PB.registerFunctionAnalyses(FAM);
PB.registerLoopAnalyses(LAM);
PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);

ModulePassManager MPM;
if (is_thin) {
PassBuilder PB;
LoopAnalysisManager LAM;
FunctionAnalysisManager FAM;
CGSCCAnalysisManager CGAM;
ModuleAnalysisManager MAM;
PB.registerModuleAnalyses(MAM);
PB.registerCGSCCAnalyses(CGAM);
PB.registerFunctionAnalyses(FAM);
PB.registerLoopAnalyses(LAM);
PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
ModulePassManager MPM;
MPM.addPass(ThinLTOBitcodeWriterPass(OS, nullptr));
MPM.run(*unwrap(M), MAM);
} else {
WriteBitcodeToFile(*unwrap(M), OS);
// Force Full LTO summary for embedded bitcode under Fat LTO.
//
// Note the bitcode writer will only emit the full LTO block ID if the "ThinLTO"
// metadata is defined and explicitly set to zero. Otherwise, the thin LTO block
// ID will be emitted.
auto *Zero = ConstantInt::get(Type::getInt32Ty(unwrap(M)->getContext()), 0);
unwrap(M)->addModuleFlag(Module::Error, "ThinLTO", Zero);
MPM.addPass(BitcodeWriterPass(OS, /*ShouldPreserveUseListOrder=*/false,
/*EmitSummaryIndex=*/true));
}
MPM.run(*unwrap(M), MAM);
}
}
return Ret.release();
Expand Down
1 change: 1 addition & 0 deletions tests/run-make/fat-lto-module-summary/foo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub fn foo() {}
10 changes: 10 additions & 0 deletions tests/run-make/fat-lto-module-summary/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use run_make_support::{llvm_bcanalyzer, rustc};

fn main() {
rustc().input("foo.rs").crate_type("lib").arg("-Clto=fat").arg("--emit=llvm-bc").run();

llvm_bcanalyzer()
.input("foo.bc")
.run()
.assert_stdout_contains("FULL_LTO_GLOBALVAL_SUMMARY_BLOCK");
}
Loading