[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
|
@ -1060,6 +1060,23 @@ impl<'tcx> LocalDecl<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, TyEncodable, TyDecodable, HashStable, TypeFoldable)]
|
||||
pub enum VarDebugInfoContents<'tcx> {
|
||||
/// NOTE(eddyb) There's an unenforced invariant that this `Place` is
|
||||
/// based on a `Local`, not a `Static`, and contains no indexing.
|
||||
Place(Place<'tcx>),
|
||||
Const(Constant<'tcx>),
|
||||
}
|
||||
|
||||
impl<'tcx> Debug for VarDebugInfoContents<'tcx> {
|
||||
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
VarDebugInfoContents::Const(c) => write!(fmt, "{}", c),
|
||||
VarDebugInfoContents::Place(p) => write!(fmt, "{:?}", p),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Debug information pertaining to a user variable.
|
||||
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable)]
|
||||
pub struct VarDebugInfo<'tcx> {
|
||||
|
@ -1071,9 +1088,7 @@ pub struct VarDebugInfo<'tcx> {
|
|||
pub source_info: SourceInfo,
|
||||
|
||||
/// Where the data for this user variable is to be found.
|
||||
/// NOTE(eddyb) There's an unenforced invariant that this `Place` is
|
||||
/// based on a `Local`, not a `Static`, and contains no indexing.
|
||||
pub place: Place<'tcx>,
|
||||
pub value: VarDebugInfoContents<'tcx>,
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue