Skip to content

Commit bbce734

Browse files
Rollup merge of #152527 - bjorn3:remove_z_emit_thin_lto, r=cuviper
Remove -Zemit-thin-lto flag As far as I can tell it was introduced in #98162 to allow fat LTO with `-Clinker-plugin-lto`. In #136840 a change was made to automatically disable ThinLTO summary generation when `-Clinker-plugin-lto -Clto=fat` is used, so we can safely remove it. Fixes #152490
2 parents 1706756 + c51cd0e commit bbce734

7 files changed

Lines changed: 16 additions & 31 deletions

File tree

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,6 @@ pub(crate) unsafe fn llvm_optimize(
786786
config.verify_llvm_ir,
787787
config.lint_llvm_ir,
788788
thin_lto_buffer,
789-
config.emit_thin_lto,
790789
config.emit_thin_lto_summary,
791790
merge_functions,
792791
unroll_loops,
@@ -1033,7 +1032,7 @@ pub(crate) fn codegen(
10331032
"LLVM_module_codegen_make_bitcode",
10341033
&*module.name,
10351034
);
1036-
ThinBuffer::new(llmod, config.emit_thin_lto)
1035+
ThinBuffer::new(llmod, cgcx.lto != Lto::Fat)
10371036
};
10381037
let data = thin.data();
10391038
let _timer = prof

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2376,7 +2376,6 @@ unsafe extern "C" {
23762376
VerifyIR: bool,
23772377
LintIR: bool,
23782378
ThinLTOBuffer: Option<&mut *mut ThinLTOBuffer>,
2379-
EmitThinLTO: bool,
23802379
EmitThinLTOSummary: bool,
23812380
MergeFunctions: bool,
23822381
UnrollLoops: bool,

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ pub struct ModuleConfig {
100100
pub emit_ir: bool,
101101
pub emit_asm: bool,
102102
pub emit_obj: EmitObj,
103-
pub emit_thin_lto: bool,
104103
pub emit_thin_lto_summary: bool,
105104

106105
// Miscellaneous flags. These are mostly copied from command-line
@@ -211,9 +210,6 @@ impl ModuleConfig {
211210
false
212211
),
213212
emit_obj,
214-
// thin lto summaries prevent fat lto, so do not emit them if fat
215-
// lto is requested. See PR #136840 for background information.
216-
emit_thin_lto: sess.opts.unstable_opts.emit_thin_lto && sess.lto() != Lto::Fat,
217213
emit_thin_lto_summary: if_regular!(
218214
sess.opts.output_types.contains_key(&OutputType::ThinLinkBitcode),
219215
false

compiler/rustc_interface/src/tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,6 @@ fn test_unstable_options_tracking_hash() {
796796
tracked!(dwarf_version, Some(5));
797797
tracked!(embed_metadata, false);
798798
tracked!(embed_source, true);
799-
tracked!(emit_thin_lto, false);
800799
tracked!(emscripten_wasm_eh, false);
801800
tracked!(export_executable_symbols, true);
802801
tracked!(fewer_names, Some(true));

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ extern "C" LLVMRustResult LLVMRustOptimize(
566566
LLVMModuleRef ModuleRef, LLVMTargetMachineRef TMRef,
567567
LLVMRustPassBuilderOptLevel OptLevelRust, LLVMRustOptStage OptStage,
568568
bool IsLinkerPluginLTO, bool NoPrepopulatePasses, bool VerifyIR,
569-
bool LintIR, LLVMRustThinLTOBuffer **ThinLTOBufferRef, bool EmitThinLTO,
569+
bool LintIR, LLVMRustThinLTOBuffer **ThinLTOBufferRef,
570570
bool EmitThinLTOSummary, bool MergeFunctions, bool UnrollLoops,
571571
bool SLPVectorize, bool LoopVectorize, bool DisableSimplifyLibCalls,
572572
bool EmitLifetimeMarkers, registerEnzymeAndPassPipelineFn EnzymePtr,
@@ -808,44 +808,35 @@ extern "C" LLVMRustResult LLVMRustOptimize(
808808
}
809809

810810
ModulePassManager MPM;
811-
bool NeedThinLTOBufferPasses = EmitThinLTO;
811+
bool NeedThinLTOBufferPasses = true;
812812
auto ThinLTOBuffer = std::make_unique<LLVMRustThinLTOBuffer>();
813813
raw_string_ostream ThinLTODataOS(ThinLTOBuffer->data);
814814
raw_string_ostream ThinLinkDataOS(ThinLTOBuffer->thin_link_data);
815815
bool IsLTO = OptStage == LLVMRustOptStage::ThinLTO ||
816816
OptStage == LLVMRustOptStage::FatLTO;
817817
if (!NoPrepopulatePasses) {
818+
for (const auto &C : PipelineStartEPCallbacks)
819+
PB.registerPipelineStartEPCallback(C);
820+
for (const auto &C : OptimizerLastEPCallbacks)
821+
PB.registerOptimizerLastEPCallback(C);
822+
818823
// The pre-link pipelines don't support O0 and require using
819824
// buildO0DefaultPipeline() instead. At the same time, the LTO pipelines do
820825
// support O0 and using them is required.
821826
if (OptLevel == OptimizationLevel::O0 && !IsLTO) {
822-
for (const auto &C : PipelineStartEPCallbacks)
823-
PB.registerPipelineStartEPCallback(C);
824-
for (const auto &C : OptimizerLastEPCallbacks)
825-
PB.registerOptimizerLastEPCallback(C);
826-
827827
// We manually schedule ThinLTOBufferPasses below, so don't pass the value
828828
// to enable it here.
829829
MPM = PB.buildO0DefaultPipeline(OptLevel);
830830
} else {
831-
for (const auto &C : PipelineStartEPCallbacks)
832-
PB.registerPipelineStartEPCallback(C);
833-
for (const auto &C : OptimizerLastEPCallbacks)
834-
PB.registerOptimizerLastEPCallback(C);
835-
836831
switch (OptStage) {
837832
case LLVMRustOptStage::PreLinkNoLTO:
838833
if (ThinLTOBufferRef) {
839834
// This is similar to LLVM's `buildFatLTODefaultPipeline`, where the
840835
// bitcode for embedding is obtained after performing
841836
// `ThinLTOPreLinkDefaultPipeline`.
842837
MPM.addPass(PB.buildThinLTOPreLinkDefaultPipeline(OptLevel));
843-
if (EmitThinLTO) {
844-
MPM.addPass(ThinLTOBitcodeWriterPass(
845-
ThinLTODataOS, EmitThinLTOSummary ? &ThinLinkDataOS : nullptr));
846-
} else {
847-
MPM.addPass(BitcodeWriterPass(ThinLTODataOS));
848-
}
838+
MPM.addPass(ThinLTOBitcodeWriterPass(
839+
ThinLTODataOS, EmitThinLTOSummary ? &ThinLinkDataOS : nullptr));
849840
*ThinLTOBufferRef = ThinLTOBuffer.release();
850841
MPM.addPass(PB.buildModuleOptimizationPipeline(
851842
OptLevel, ThinOrFullLTOPhase::None));
@@ -870,6 +861,7 @@ extern "C" LLVMRustResult LLVMRustOptimize(
870861
break;
871862
case LLVMRustOptStage::FatLTO:
872863
MPM = PB.buildLTODefaultPipeline(OptLevel, nullptr);
864+
NeedThinLTOBufferPasses = false;
873865
break;
874866
}
875867
}
@@ -895,9 +887,11 @@ extern "C" LLVMRustResult LLVMRustOptimize(
895887
MPM.addPass(CanonicalizeAliasesPass());
896888
MPM.addPass(NameAnonGlobalPass());
897889
}
898-
// For `-Copt-level=0`, ThinLTO, or LTO.
890+
// For `-Copt-level=0`, and the pre-link fat/thin LTO stages.
899891
if (ThinLTOBufferRef && *ThinLTOBufferRef == nullptr) {
900-
if (EmitThinLTO) {
892+
// thin lto summaries prevent fat lto, so do not emit them if fat
893+
// lto is requested. See PR #136840 for background information.
894+
if (OptStage != LLVMRustOptStage::PreLinkFatLTO) {
901895
MPM.addPass(ThinLTOBitcodeWriterPass(
902896
ThinLTODataOS, EmitThinLTOSummary ? &ThinLinkDataOS : nullptr));
903897
} else {

compiler/rustc_session/src/options.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2335,8 +2335,6 @@ options! {
23352335
"embed source text in DWARF debug sections (default: no)"),
23362336
emit_stack_sizes: bool = (false, parse_bool, [UNTRACKED],
23372337
"emit a section containing stack size metadata (default: no)"),
2338-
emit_thin_lto: bool = (true, parse_bool, [TRACKED],
2339-
"emit the bc module with thin LTO info (default: yes)"),
23402338
emscripten_wasm_eh: bool = (true, parse_bool, [TRACKED],
23412339
"Use WebAssembly error handling for wasm32-unknown-emscripten"),
23422340
enforce_type_length_limit: bool = (false, parse_bool, [TRACKED],

tests/run-make/issue-84395-lto-embed-bitcode/rmake.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn main() {
1818
.arg("-Clinker-plugin-lto")
1919
.arg(format!("-Clinker={}", env_var("CLANG")))
2020
.arg("-Clink-arg=-Wl,--plugin-opt=-lto-embed-bitcode=optimized")
21-
.arg("-Zemit-thin-lto=no")
21+
.arg("-Clto=fat")
2222
.run();
2323

2424
llvm_objcopy().dump_section(".llvmbc", "test.bc").arg("test").run();

0 commit comments

Comments
 (0)