Repository navigation
Outline and deduplicate cold panic and drop paths in MIR and LLVM - #164821
Draft
stephenduong1004 wants to merge 3 commits into
Draft
stephenduong1004 wants to merge 3 commits into
stephenduong1004 wants to merge 3 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Collaborator
|
The job Click to see the possible cause of the failure (guessed by this bot) |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Experimental prototype to outline and deduplicate cold
panic!formatting, cold drop glue, and?(FromResidual::from_residual) paths in MIR and LLVM, as an alternative to the macro-based approach in #115562 / #115670 (reverted in #145304).Reproducer
&scaledand&limitinpanic!forces both out of SSA registers into stackallocas on the hot path, andentrygets 4 inlined copies of ~50 IR instructions offmt::Argumentssetup.scaledandlimitstay in SSA registers on the hot path, the panic block is outlined, and all<T>copies merge into 1 shared.cold.1helper.16 -> 1generic panic helpers (-13.6% compile time on microbenchmarks, -5% to -12.8% on large crates) and64 -> 1inlinedcatch_unwindpayload drops (-5.8% compile time).Why MIR + LLVM Instead of Macro Outlining (#115562 / #115670 / #145304)?
Outlining inside
panic_2021!(#115670, reverted in #145304) could not outline multi-argument formatted panics (panic!("... {}", x)), still borrowed&$argin the hot caller, and created a newconst fnDefIdperpanic!()site (requiring#[rustc_const_panic_str]hacks).Doing this in MIR and LLVM (after borrowck and const-eval) avoids macro/const-eval hacks, preserves
return/?in panic args, keeps hot locals in registers, outlines fullfmt::Argumentssetups, and also covers?and cold drops.What This PR Does
rustc_mir_transform):ColdBlockOutliner: Copies hotCopylocals into a cold temporary before borrowing&xin cold blocks, keepingxin an SSA register and unblocking LLVM outlining.KnownVariantDrops: Specializes sharedDropblocks when predecessors set a known enum variant (e.g.,Result::OkvsErrincatch_unwind), separating hot no-op drops from coldErrdestructors.Inline: Skips MIR inlining into cold blocks (unless#[inline(always)]).rustc_codegen_ssa):find_cold_blocksto ignoreis_cleanupunwind edges and markscatch_unwinderror branches cold.FromResidual::from_residual(?) calls ascold+noinline.PassWrapper.cpp):HotColdSplittingPass(hot-cold-split-threshold=1) after inlining and marks outlined.cold.functionsnoinline.type_name::<T>(),Location) into parameters on.cold.functions soMergeFunctionsPasscan merge generic duplicates.Next Steps
This draft PR is LLM-generated; this is to gather end-to-end
rustc-perfnumbers and design feedback. If the direction makes sense, I'm happy to split this into small, independent PRs for review.