rust/compiler/rustc_mir_transform/src/deaggregator.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

46 lines
1.6 KiB
Rust
Raw Normal View History

use crate::util::expand_aggregate;
use crate::MirPass;
2020-03-29 09:41:09 -05:00
use rustc_middle::mir::*;
use rustc_middle::ty::TyCtxt;
pub struct Deaggregator;
2019-08-04 15:20:00 -05:00
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).
match stmt.kind {
// FIXME(#48193) Deaggregate arrays when it's cheaper to do so.
StatementKind::Assign(box (
_,
Rvalue::Aggregate(box AggregateKind::Array(_), _),
)) => {
return None;
}
StatementKind::Assign(box (_, Rvalue::Aggregate(_, _))) => {}
_ => return None,
}
let stmt = stmt.replace_nop();
let source_info = stmt.source_info;
2022-02-18 17:48:49 -06:00
let StatementKind::Assign(box (lhs, Rvalue::Aggregate(kind, operands))) = stmt.kind else {
bug!();
2016-08-02 12:46:26 -05:00
};
Some(expand_aggregate(
lhs,
operands.into_iter().map(|op| {
let ty = op.ty(&body.local_decls, tcx);
(op, ty)
}),
*kind,
source_info,
2019-10-20 15:11:04 -05:00
tcx,
))
});
}
}
}