Stop deaggegating MIR.

This commit is contained in:
Camille GILLOT 2023-01-25 18:34:19 +00:00
parent 6a0b218161
commit 134d819072
4 changed files with 0 additions and 132 deletions

View file

@ -1,49 +0,0 @@
use crate::util::expand_aggregate;
use crate::MirPass;
use rustc_hir::def::DefKind;
use rustc_middle::mir::*;
use rustc_middle::ty::TyCtxt;
pub struct Deaggregator;
impl<'tcx> MirPass<'tcx> for Deaggregator {
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
let basic_blocks = body.basic_blocks.as_mut_preserves_cfg();
for bb in basic_blocks {
bb.expand_statements(|stmt| {
// FIXME(eddyb) don't match twice on `stmt.kind` (post-NLL).
let StatementKind::Assign(box (
_, Rvalue::Aggregate(box ref kind, _))
) = stmt.kind else { return None };
// FIXME(#48193) Deaggregate arrays when it's cheaper to do so.
if let AggregateKind::Array(_) = kind {
return None;
}
if let AggregateKind::Adt(def_id, ..) = kind
&& matches!(tcx.def_kind(def_id), DefKind::Enum)
{
return None;
}
let stmt = stmt.replace_nop();
let source_info = stmt.source_info;
let StatementKind::Assign(box (lhs, Rvalue::Aggregate(kind, operands))) = stmt.kind else {
bug!();
};
Some(expand_aggregate(
lhs,
operands.into_iter().map(|op| {
let ty = op.ty(&body.local_decls, tcx);
(op, ty)
}),
*kind,
source_info,
tcx,
))
});
}
}
}

View file

@ -60,7 +60,6 @@ mod coverage;
mod ctfe_limit;
mod dataflow_const_prop;
mod dead_store_elimination;
mod deaggregator;
mod deduce_param_attrs;
mod deduplicate_blocks;
mod deref_separator;
@ -523,9 +522,6 @@ fn run_runtime_lowering_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
&elaborate_box_derefs::ElaborateBoxDerefs,
&generator::StateTransform,
&add_retag::AddRetag,
// Deaggregator is necessary for const prop. We may want to consider implementing
// CTFE support for aggregates.
&deaggregator::Deaggregator,
&Lint(const_prop_lint::ConstProp),
];
pm::run_passes_no_validate(tcx, body, passes, Some(MirPhase::Runtime(RuntimePhase::Initial)));