2016-09-19 23:50:00 +03:00
|
|
|
use rustc::mir::*;
|
2019-04-02 16:04:51 -07:00
|
|
|
use rustc::ty::TyCtxt;
|
2019-02-08 06:28:15 +09:00
|
|
|
use crate::transform::{MirPass, MirSource};
|
2019-05-26 09:55:50 +01:00
|
|
|
use crate::util::expand_aggregate;
|
2016-07-27 17:46:54 -07:00
|
|
|
|
|
|
|
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>
|
|
|
|
) {
|
2019-10-26 01:41:17 -04:00
|
|
|
let (basic_blocks, local_decls) = body_cache.basic_blocks_and_local_decls_mut();
|
2018-02-16 19:20:18 +02:00
|
|
|
let local_decls = &*local_decls;
|
2018-02-07 15:27:00 +02:00
|
|
|
for bb in basic_blocks {
|
2018-02-16 19:20:18 +02:00
|
|
|
bb.expand_statements(|stmt| {
|
|
|
|
// FIXME(eddyb) don't match twice on `stmt.kind` (post-NLL).
|
2019-09-11 16:05:45 -03:00
|
|
|
if let StatementKind::Assign(box(_, ref rhs)) = stmt.kind {
|
|
|
|
if let Rvalue::Aggregate(ref kind, _) = *rhs {
|
2018-02-16 19:20:18 +02:00
|
|
|
// FIXME(#48193) Deaggregate arrays when it's cheaper to do so.
|
|
|
|
if let AggregateKind::Array(_) = **kind {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return None;
|
|
|
|
}
|
2018-02-07 15:27:00 +02:00
|
|
|
|
2018-02-16 19:20:18 +02:00
|
|
|
let stmt = stmt.replace_nop();
|
|
|
|
let source_info = stmt.source_info;
|
2019-05-26 09:55:50 +01:00
|
|
|
let (lhs, kind, operands) = match stmt.kind {
|
2019-09-11 16:05:45 -03:00
|
|
|
StatementKind::Assign(box(lhs, rvalue)) => {
|
2018-09-24 11:32:31 +10:00
|
|
|
match rvalue {
|
|
|
|
Rvalue::Aggregate(kind, operands) => (lhs, kind, operands),
|
|
|
|
_ => bug!()
|
|
|
|
}
|
|
|
|
}
|
2018-02-07 15:27:00 +02:00
|
|
|
_ => bug!()
|
2016-08-02 10:46:26 -07:00
|
|
|
};
|
2018-02-07 15:27:00 +02:00
|
|
|
|
2019-05-26 09:55:50 +01:00
|
|
|
Some(expand_aggregate(
|
|
|
|
lhs,
|
|
|
|
operands.into_iter().map(|op| {
|
2018-02-07 15:27:00 +02:00
|
|
|
let ty = op.ty(local_decls, tcx);
|
2019-05-26 09:55:50 +01:00
|
|
|
(op, ty)
|
|
|
|
}),
|
|
|
|
*kind,
|
|
|
|
source_info,
|
2019-10-20 16:11:04 -04:00
|
|
|
tcx,
|
2019-05-26 09:55:50 +01:00
|
|
|
))
|
2018-02-16 19:20:18 +02:00
|
|
|
});
|
2016-07-27 17:46:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|