Auto merge of #73210 - wesleywiser:consts_in_debuginfo, r=oli-obk
[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:
commit
e99a89c7c0
16 changed files with 398 additions and 79 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>,
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -829,16 +829,20 @@ macro_rules! make_mir_visitor {
|
|||
let VarDebugInfo {
|
||||
name: _,
|
||||
source_info,
|
||||
place,
|
||||
value,
|
||||
} = var_debug_info;
|
||||
|
||||
self.visit_source_info(source_info);
|
||||
let location = START_BLOCK.start_location();
|
||||
self.visit_place(
|
||||
place,
|
||||
PlaceContext::NonUse(NonUseContext::VarDebugInfo),
|
||||
location,
|
||||
);
|
||||
match value {
|
||||
VarDebugInfoContents::Const(c) => self.visit_constant(c, location),
|
||||
VarDebugInfoContents::Place(place) =>
|
||||
self.visit_place(
|
||||
place,
|
||||
PlaceContext::NonUse(NonUseContext::VarDebugInfo),
|
||||
location
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
fn super_source_scope(&mut self,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue