rust/src/librustc_mir/transform/deaggregator.rs

56 lines
1.9 KiB
Rust
Raw Normal View History

2016-09-19 23:50:00 +03:00
use rustc::mir::*;
use rustc::ty::TyCtxt;
2019-02-08 06:28:15 +09:00
use crate::transform::{MirPass, MirSource};
use crate::util::expand_aggregate;
pub struct Deaggregator;
2019-08-04 16:20:00 -04:00
impl<'tcx> MirPass<'tcx> for Deaggregator {
2019-10-28 18:16:25 -04:00
fn run_pass(
&self, tcx: TyCtxt<'tcx>, _source: MirSource<'tcx>, body_cache: &mut BodyCache<'tcx>
) {
let (basic_blocks, local_decls) = body_cache.basic_blocks_and_local_decls_mut();
let local_decls = &*local_decls;
for bb in basic_blocks {
bb.expand_statements(|stmt| {
// FIXME(eddyb) don't match twice on `stmt.kind` (post-NLL).
if let StatementKind::Assign(box(_, ref rhs)) = stmt.kind {
if let Rvalue::Aggregate(ref kind, _) = *rhs {
// FIXME(#48193) Deaggregate arrays when it's cheaper to do so.
if let AggregateKind::Array(_) = **kind {
return None;
}
} else {
return None;
}
} else {
return None;
}
let stmt = stmt.replace_nop();
let source_info = stmt.source_info;
let (lhs, kind, operands) = match stmt.kind {
StatementKind::Assign(box(lhs, rvalue)) => {
match rvalue {
Rvalue::Aggregate(kind, operands) => (lhs, kind, operands),
_ => bug!()
}
}
_ => bug!()
2016-08-02 10:46:26 -07:00
};
Some(expand_aggregate(
lhs,
operands.into_iter().map(|op| {
let ty = op.ty(local_decls, tcx);
(op, ty)
}),
*kind,
source_info,
2019-10-20 16:11:04 -04:00
tcx,
))
});
}
}
}