-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Remove -Zemit-thin-lto flag #152527
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
Remove -Zemit-thin-lto flag #152527
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -566,7 +566,7 @@ extern "C" LLVMRustResult LLVMRustOptimize( | |
| LLVMModuleRef ModuleRef, LLVMTargetMachineRef TMRef, | ||
| LLVMRustPassBuilderOptLevel OptLevelRust, LLVMRustOptStage OptStage, | ||
| bool IsLinkerPluginLTO, bool NoPrepopulatePasses, bool VerifyIR, | ||
| bool LintIR, LLVMRustThinLTOBuffer **ThinLTOBufferRef, bool EmitThinLTO, | ||
| bool LintIR, LLVMRustThinLTOBuffer **ThinLTOBufferRef, | ||
| bool EmitThinLTOSummary, bool MergeFunctions, bool UnrollLoops, | ||
| bool SLPVectorize, bool LoopVectorize, bool DisableSimplifyLibCalls, | ||
| bool EmitLifetimeMarkers, registerEnzymeAndPassPipelineFn EnzymePtr, | ||
|
|
@@ -808,44 +808,35 @@ extern "C" LLVMRustResult LLVMRustOptimize( | |
| } | ||
|
|
||
| ModulePassManager MPM; | ||
| bool NeedThinLTOBufferPasses = EmitThinLTO; | ||
| bool NeedThinLTOBufferPasses = true; | ||
| auto ThinLTOBuffer = std::make_unique<LLVMRustThinLTOBuffer>(); | ||
| raw_string_ostream ThinLTODataOS(ThinLTOBuffer->data); | ||
| raw_string_ostream ThinLinkDataOS(ThinLTOBuffer->thin_link_data); | ||
| bool IsLTO = OptStage == LLVMRustOptStage::ThinLTO || | ||
| OptStage == LLVMRustOptStage::FatLTO; | ||
| if (!NoPrepopulatePasses) { | ||
| for (const auto &C : PipelineStartEPCallbacks) | ||
| PB.registerPipelineStartEPCallback(C); | ||
| for (const auto &C : OptimizerLastEPCallbacks) | ||
| PB.registerOptimizerLastEPCallback(C); | ||
|
|
||
| // The pre-link pipelines don't support O0 and require using | ||
| // buildO0DefaultPipeline() instead. At the same time, the LTO pipelines do | ||
| // support O0 and using them is required. | ||
| if (OptLevel == OptimizationLevel::O0 && !IsLTO) { | ||
| for (const auto &C : PipelineStartEPCallbacks) | ||
| PB.registerPipelineStartEPCallback(C); | ||
| for (const auto &C : OptimizerLastEPCallbacks) | ||
| PB.registerOptimizerLastEPCallback(C); | ||
|
|
||
| // We manually schedule ThinLTOBufferPasses below, so don't pass the value | ||
| // to enable it here. | ||
| MPM = PB.buildO0DefaultPipeline(OptLevel); | ||
| } else { | ||
| for (const auto &C : PipelineStartEPCallbacks) | ||
| PB.registerPipelineStartEPCallback(C); | ||
| for (const auto &C : OptimizerLastEPCallbacks) | ||
| PB.registerOptimizerLastEPCallback(C); | ||
|
|
||
| switch (OptStage) { | ||
| case LLVMRustOptStage::PreLinkNoLTO: | ||
| if (ThinLTOBufferRef) { | ||
| // This is similar to LLVM's `buildFatLTODefaultPipeline`, where the | ||
| // bitcode for embedding is obtained after performing | ||
| // `ThinLTOPreLinkDefaultPipeline`. | ||
| MPM.addPass(PB.buildThinLTOPreLinkDefaultPipeline(OptLevel)); | ||
| if (EmitThinLTO) { | ||
| MPM.addPass(ThinLTOBitcodeWriterPass( | ||
| ThinLTODataOS, EmitThinLTOSummary ? &ThinLinkDataOS : nullptr)); | ||
| } else { | ||
| MPM.addPass(BitcodeWriterPass(ThinLTODataOS)); | ||
| } | ||
| MPM.addPass(ThinLTOBitcodeWriterPass( | ||
| ThinLTODataOS, EmitThinLTOSummary ? &ThinLinkDataOS : nullptr)); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| *ThinLTOBufferRef = ThinLTOBuffer.release(); | ||
| MPM.addPass(PB.buildModuleOptimizationPipeline( | ||
| OptLevel, ThinOrFullLTOPhase::None)); | ||
|
|
@@ -870,6 +861,7 @@ extern "C" LLVMRustResult LLVMRustOptimize( | |
| break; | ||
| case LLVMRustOptStage::FatLTO: | ||
| MPM = PB.buildLTODefaultPipeline(OptLevel, nullptr); | ||
| NeedThinLTOBufferPasses = false; | ||
| break; | ||
| } | ||
| } | ||
|
|
@@ -895,9 +887,11 @@ extern "C" LLVMRustResult LLVMRustOptimize( | |
| MPM.addPass(CanonicalizeAliasesPass()); | ||
| MPM.addPass(NameAnonGlobalPass()); | ||
| } | ||
| // For `-Copt-level=0`, ThinLTO, or LTO. | ||
| // For `-Copt-level=0`, and the pre-link fat/thin LTO stages. | ||
| if (ThinLTOBufferRef && *ThinLTOBufferRef == nullptr) { | ||
| if (EmitThinLTO) { | ||
| // thin lto summaries prevent fat lto, so do not emit them if fat | ||
| // lto is requested. See PR #136840 for background information. | ||
| if (OptStage != LLVMRustOptStage::PreLinkFatLTO) { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't need to check
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then, how is this block "For ... LTO" at all?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LTO runs this function twice. Once on each individual module (PreLinkFatLTO or PreLinkThinLTO). In this case
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, then perhaps the "For" comment can mention that this is only expected in the prelink phase.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| MPM.addPass(ThinLTOBitcodeWriterPass( | ||
| ThinLTODataOS, EmitThinLTOSummary ? &ThinLinkDataOS : nullptr)); | ||
| } else { | ||
|
|
||
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.
This used to be true when fat LTO is not used, so I ensured all fat LTO phases do
NeedThinLTOBufferPasses = falsebelow.