[mir-opt] Allow debuginfo to be generated for a constant or a Place
Prior to this commit, debuginfo was always generated by mapping a name to a Place. This has the side-effect that `SimplifyLocals` cannot remove locals that are only used for debuginfo because their other uses have been const-propagated. To allow these locals to be removed, we now allow debuginfo to point to a constant value. The `ConstProp` pass detects when debuginfo points to a local with a known constant value and replaces it with the value. This allows the later `SimplifyLocals` pass to remove the local.
This commit is contained in:
parent
b776d1c3e3
commit
01aec8d185
23 changed files with 406 additions and 127 deletions
|
@ -1992,7 +1992,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
self.var_debug_info.push(VarDebugInfo {
|
||||
name,
|
||||
source_info: debug_source_info,
|
||||
place: for_arm_body.into(),
|
||||
value: VarDebugInfoContents::Place(for_arm_body.into()),
|
||||
});
|
||||
let locals = if has_guard.0 {
|
||||
let ref_for_guard = self.local_decls.push(LocalDecl::<'tcx> {
|
||||
|
@ -2011,7 +2011,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
self.var_debug_info.push(VarDebugInfo {
|
||||
name,
|
||||
source_info: debug_source_info,
|
||||
place: ref_for_guard.into(),
|
||||
value: VarDebugInfoContents::Place(ref_for_guard.into()),
|
||||
});
|
||||
LocalsForNode::ForGuard { ref_for_guard, for_arm_body }
|
||||
} else {
|
||||
|
|
|
@ -796,7 +796,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
self.var_debug_info.push(VarDebugInfo {
|
||||
name: ident.name,
|
||||
source_info,
|
||||
place: arg_local.into(),
|
||||
value: VarDebugInfoContents::Place(arg_local.into()),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -860,10 +860,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
self.var_debug_info.push(VarDebugInfo {
|
||||
name,
|
||||
source_info: SourceInfo::outermost(tcx_hir.span(var_id)),
|
||||
place: Place {
|
||||
value: VarDebugInfoContents::Place(Place {
|
||||
local: closure_env_arg,
|
||||
projection: tcx.intern_place_elems(&projs),
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
mutability
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue