2019-05-26 08:55:50 +00:00
|
|
|
use crate::util::expand_aggregate;
|
2021-01-01 00:53:25 +00:00
|
|
|
use crate::MirPass;
|
2020-03-29 14:41:09 +00:00
|
|
|
use rustc_middle::mir::*;
|
|
|
|
use rustc_middle::ty::TyCtxt;
|
2016-07-28 00:46:54 +00:00
|
|
|
|
|
|
|
pub struct Deaggregator;
|
|
|
|
|
2019-08-04 20:20:00 +00:00
|
|
|
impl<'tcx> MirPass<'tcx> for Deaggregator {
|
2022-03-06 01:37:04 +00:00
|
|
|
fn phase_change(&self) -> Option<MirPhase> {
|
|
|
|
Some(MirPhase::Deaggregated)
|
|
|
|
}
|
|
|
|
|
2020-10-04 18:01:38 +00:00
|
|
|
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
2022-07-04 02:55:45 +00:00
|
|
|
let (basic_blocks, local_decls, _) =
|
|
|
|
body.basic_blocks_local_decls_mut_and_var_debug_info_no_invalidate();
|
2018-02-16 17:20:18 +00:00
|
|
|
let local_decls = &*local_decls;
|
2018-02-07 13:27:00 +00:00
|
|
|
for bb in basic_blocks {
|
2018-02-16 17:20:18 +00:00
|
|
|
bb.expand_statements(|stmt| {
|
|
|
|
// FIXME(eddyb) don't match twice on `stmt.kind` (post-NLL).
|
2020-08-13 21:59:47 +00:00
|
|
|
match stmt.kind {
|
|
|
|
// FIXME(#48193) Deaggregate arrays when it's cheaper to do so.
|
|
|
|
StatementKind::Assign(box (
|
|
|
|
_,
|
|
|
|
Rvalue::Aggregate(box AggregateKind::Array(_), _),
|
|
|
|
)) => {
|
2018-02-16 17:20:18 +00:00
|
|
|
return None;
|
|
|
|
}
|
2020-08-13 21:59:47 +00:00
|
|
|
StatementKind::Assign(box (_, Rvalue::Aggregate(_, _))) => {}
|
|
|
|
_ => return None,
|
2018-02-16 17:20:18 +00:00
|
|
|
}
|
2018-02-07 13:27:00 +00:00
|
|
|
|
2018-02-16 17:20:18 +00:00
|
|
|
let stmt = stmt.replace_nop();
|
|
|
|
let source_info = stmt.source_info;
|
2022-02-18 23:48:49 +00:00
|
|
|
let StatementKind::Assign(box (lhs, Rvalue::Aggregate(kind, operands))) = stmt.kind else {
|
|
|
|
bug!();
|
2016-08-02 17:46:26 +00:00
|
|
|
};
|
2018-02-07 13:27:00 +00:00
|
|
|
|
2019-05-26 08:55:50 +00:00
|
|
|
Some(expand_aggregate(
|
|
|
|
lhs,
|
|
|
|
operands.into_iter().map(|op| {
|
2018-02-07 13:27:00 +00:00
|
|
|
let ty = op.ty(local_decls, tcx);
|
2019-05-26 08:55:50 +00:00
|
|
|
(op, ty)
|
|
|
|
}),
|
|
|
|
*kind,
|
|
|
|
source_info,
|
2019-10-20 20:11:04 +00:00
|
|
|
tcx,
|
2019-05-26 08:55:50 +00:00
|
|
|
))
|
2018-02-16 17:20:18 +00:00
|
|
|
});
|
2016-07-28 00:46:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|