-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Introduce debuginfo to statements in MIR #142771
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: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
15c968a
to
6b013d4
Compare
This comment has been minimized.
This comment has been minimized.
6b013d4
to
51576e7
Compare
This comment has been minimized.
This comment has been minimized.
@bors2 try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Introduce debuginfo to statements in MIR Not ready for reviewing. Something known: - [ ] Retain debuginfo when concatenating bbs - [ ] Document about when to drop debuginfos (don't be worse than the optimized LLVM IR) - [ ] Missing tests r? ghost
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (eb83156): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 2.3%, secondary 3.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 3.2%, secondary 2.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.5%, secondary 0.3%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 691.482s -> 692.445s (0.14%) |
51576e7
to
e72c3ae
Compare
@bors2 try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Introduce debuginfo to statements in MIR Not ready for reviewing. Something known: - [ ] Retain debuginfo when concatenating bbs - [ ] Document about when to drop debuginfos (don't be worse than the optimized LLVM IR) - [ ] Missing tests r? ghost
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (77d5c6a): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 2.4%, secondary 3.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 2.1%, secondary 0.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.5%, secondary 0.3%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 690.617s -> 691.47s (0.12%) |
☔ The latest upstream changes (presumably #142870) made this pull request unmergeable. Please resolve the merge conflicts. |
Finished benchmarking commit (61f71d4): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 2.0%, secondary 4.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary -0.6%, secondary 3.9%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.5%, secondary 0.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 467.629s -> 469.243s (0.35%) |
compiler/rustc_middle/src/mir/mod.rs
Outdated
let retain = f(stmt); | ||
if retain { | ||
if !debuginfos.is_empty() { | ||
if !stmt.debuginfos.is_empty() { |
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.
Is this check worth it?
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.
No. I have removed the second check.
compiler/rustc_middle/src/mir/mod.rs
Outdated
self.statements.retain_mut(|stmt| f(stmt)); | ||
return; | ||
} | ||
let mut debuginfos = Vec::new(); |
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.
Do you mind adding a comment saying so?
@@ -15,17 +15,33 @@ use crate::ty::CoroutineArgsExt; | |||
pub struct Statement<'tcx> { | |||
pub source_info: SourceInfo, | |||
pub kind: StatementKind<'tcx>, | |||
pub debuginfos: Vec<StmtDebugInfo<'tcx>>, |
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.
Could you add a comment explaining that those debuginfo are executed before the primary statement?
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.
Added:
/// Some debuginfos appearing before the primary statement.
location: Location | ||
) { | ||
self.super_statement_debuginfos(stmt_debuginfo, location); | ||
} |
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.
Do we really need this method?
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.
I'm not sure but I removed.
compiler/rustc_middle/src/mir/mod.rs
Outdated
@@ -1342,6 +1342,10 @@ pub struct BasicBlockData<'tcx> { | |||
/// List of statements in this block. | |||
pub statements: Vec<Statement<'tcx>>, | |||
|
|||
/// All debuginfos happen before the statement. | |||
/// Put debuginfos here when the last statement is eliminated. | |||
pub after_last_stmt_debuginfos: Vec<StmtDebugInfo<'tcx>>, |
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.
Is it after the last statement, or before the terminator? Why isn't it inside Terminator
?
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.
We have some passes that change the terminator, which means we also must hand debuginfos. I think this will make things more complicated.
I expect these debuginfos to be handled in simplifycfg as much as possible.
LocalRef::Operand(operand_ref) => match operand_ref.val { | ||
OperandValue::Immediate(v) => { | ||
Some(PlaceRef::new_sized(v, operand_ref.layout)) | ||
let assign_ref = if let Some(place) = place { |
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.
Use place.and_then(|place|
to keep the previous logic?
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.
I have removed the Option
.
@@ -958,5 +969,5 @@ impl RawPtrKind { | |||
|
|||
#[derive(Clone, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)] | |||
pub enum StmtDebugInfo<'tcx> { | |||
AssignRef(Local, Place<'tcx>), | |||
AssignRef(Local, Option<Place<'tcx>>), |
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.
I'm not convinced by the benefit of allowing None
here. Do you mind splitting this change from other tweaks to DSE, so we can see what it does in isolation?
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.
Is 048f7eb what you're looking for?
self.always_used.contains(local) | ||
); | ||
// To keep things simple, we don't handle debugging information here, these are in DSE. | ||
self.always_used.contains(local) || self.use_count[local] != 0 |
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.
I'd rather keep handling debuginfo in this general SimplifyLocals
. It runs much more often than DSE.
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.
Perhaps, but I don't want to make this PR any more complicated, and I'm concerned about the compile time.
@@ -718,6 +717,7 @@ pub(crate) fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<' | |||
&strip_debuginfo::StripDebugInfo, | |||
©_prop::CopyProp, | |||
&dead_store_elimination::DeadStoreElimination::Final, | |||
&match_branches::MatchBranchSimplification, |
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.
Do you mind submitting this change in a separate PR?
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.
I will drop this at the next update.
@@ -254,20 +244,20 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> { | |||
current = target; | |||
} | |||
let last = current; | |||
*changed |= *start != last; |
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.
Do you mind submitting this bugfix in a standalone PR?
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 may not be the best phase, but we do need a CFG simplification. A potential improvement would be to implement a trivial simplification.
Add a test case with the same local. ``` // DBG: _1 = &_2 _1 = &_3 ```
Add a test case with the same local.
Add a assertion for unsupported debug information.
Add a semicolon.
use `?` use `successors.all`
Add a test case for identical successors.
…buginfos Add a test case for a invalid place on debuginfos
…buginfos - duplicate the StmtDebugInfo arm, a None and a Some version - iter projections for invalid place
94ddfe6
to
224fbe9
Compare
This comment has been minimized.
This comment has been minimized.
fix tidy checks failed
I'll squash the fixups during the next rebase. 🙏 |
The job Click to see the possible cause of the failure (guessed by this bot)
|
…hain-changed, r=cjgillot simplifycfg: Mark as changed when start is modified in collapse goto chain Split from rust-lang#142771. r? cjgillot
mir: Do not modify NonUse in `super_projection_elem` Split from rust-lang#142771. r? cjgillot
The PR introduces support for debug information within dead statements. Currently, only the reference statement is supported, which is sufficient to fix #128081.
I don't modify Stable MIR, as I don't think we need debug information when using it.
This PR represents the debug information for the dead reference statement via
#dbg_value
. For example,let _foo_b = &foo.b
becomes#dbg_value(ptr %foo, !22, !DIExpression(DW_OP_plus_uconst, 4, DW_OP_stack_value), !26)
. You can see this here: https://rust.godbolt.org/z/d43js6adv.The general principle for handling debug information is to never provide less debug information than the optimized LLVM IR.
The current rules for dropping debug information in this PR are:
For the perf result:
I expected this to introduce some regressions; however, the results mixed the effects of inlining. Looking at the doc profile, this is a clear optimization. One potential regression I'm investigating is
serde-1.0.219-debug-full
.