-
Notifications
You must be signed in to change notification settings - Fork 13.7k
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. |
mir: Do not modify NonUse in `super_projection_elem` Split from rust-lang#142771. r? cjgillot
7a0c75b
to
458ad93
Compare
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 is looking very good thanks! I'm not certain I'm the best reviewer for the codegen part, so I just left a few questions.
@@ -312,8 +321,11 @@ macro_rules! make_mir_visitor { | |||
index += 1; | |||
} | |||
|
|||
let location = Location { block, statement_index: index }; | |||
for debuginfo in after_last_stmt_debuginfos as & $($mutability)? [_] { |
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.
in &$(mutability)? after_last_stmt_debuginfos
?
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.
Dereferencing does not happen with this syntax.
) -> Option<Place<'tcx>> { | ||
// Compute the place that we are storing to, if any | ||
let destination = match stmt_kind { | ||
StatementKind::Assign(box (place, rvalue)) => (rvalue.is_safe_to_remove() |
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.
Nit, easier for me to understand:
StatementKind::Assign(box (_, rvalue)) if !rvalue.is_safe_to_remove() => None,
StatementKind::Assign(box (place, _)) if stmt_kind.as_debuginfo().is_some() => Some(*place),
and then proceed to reasoning according to debuginfo_locals
.
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 is a little scary for me, their order can be accidentally re-ordered.
@@ -160,19 +160,23 @@ impl<'ll> DebugInfoBuilderMethods for Builder<'_, 'll, '_> { | |||
&mut self, | |||
dbg_var: &'ll DIVariable, | |||
dbg_loc: &'ll DILocation, | |||
variable_alloca: Self::Value, | |||
is_declared: bool, | |||
val: Self::Value, |
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.
Should we just have 2 methods? a dbg_var_addr
and a dbg_var_value
?
pub(crate) fn codegen_stmt_debuginfo(&mut self, bx: &mut Bx, debuginfo: &StmtDebugInfo<'tcx>) { | ||
match debuginfo { | ||
StmtDebugInfo::AssignRef(dest, place) => { | ||
let place_ref = match self.locals[place.local] { |
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 local is poorly named. It represents place.local
, not the while place
. local_ref
?
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.
(Some(place_ref), false) => { | ||
(place_ref.val, place_ref.layout, place.projection.as_slice()) | ||
} | ||
(Some(place_ref), true) => { | ||
let projected_ty = | ||
place_ref.layout.ty.builtin_deref(true).unwrap_or_else(|| { | ||
bug!("deref of non-pointer {:?}", place_ref) | ||
}); | ||
let layout = bx.cx().layout_of(projected_ty); | ||
(place_ref.val, layout, &place.projection[1..]) | ||
} |
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 don't understand the logic here. If this is an indirect place, we change the type but we don't change the val
?
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.
The layout is used to calculate offset with the projection. The function name should be debug_new_ref_to_local
, not debug_new_value_to_local
. I'm looking a better 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.
} | ||
} | ||
|
||
fn debug_new_value_to_local_as_var( |
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.
Should this be inlined? This should allow to compute offsets only once outside the loop.
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.
let ref_v1 = &ref_foo.1; | ||
let ref_v2 = &ref_foo.2; | ||
ref_foo.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.
Do you have an example where we take the address of an Index
projection?
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.
terminator.successors_mut(|successor| { | ||
self.collapse_goto_chain(successor, &mut changed); | ||
}); | ||
if changed && let Some(identical_succ) = identical_succ { |
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.
Should we introduce a more localized chain_changed
variable?
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.
The code has been removed in 8702b70.
let mut succ_debuginfos = | ||
self.basic_blocks[succ].after_last_stmt_debuginfos.clone(); | ||
self.basic_blocks[current].after_last_stmt_debuginfos.extend(&mut succ_debuginfos); | ||
} |
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 there a way to look at pred_count
to avoid a clone?
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.
8702b70. I don't think I should move debuginfos before the terminator. The new change should be clearer and easier to maintain, and it also fixes a case where debuginfos was lost.
use crate::util::is_within_packed; | ||
|
||
/// Performs the optimization on the body | ||
/// | ||
/// The `borrowed` set must be a `DenseBitSet` of all the locals that are ever borrowed in this | ||
/// body. It can be generated via the [`borrowed_locals`] function. | ||
fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { | ||
fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) -> bool { |
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 doc-comment what this bool is?
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 comment has been minimized.
This comment has been minimized.
Sorry I haven't replied to all of them. A little busy... |
a4ce010
to
b0d20dd
Compare
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
b0d20dd
to
39c5bf2
Compare
This comment has been minimized.
This comment has been minimized.
Rename `place_ref` to `local_ref`.
Add `debug_new_val_to_local` Inline `debug_new_value_to_local_as_var`
39c5bf2
to
450c929
Compare
This comment has been minimized.
This comment has been minimized.
`&_1` is only valid if the pass mode is indirect.
Move all debuginfos to the last basic block if each bb has only one predecessor.
Add a test case for the index projection.
450c929
to
84d42cf
Compare
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
.