]>
Commit | Line | Data |
---|---|---|
c30ab7b3 | 1 | use rustc::mir::*; |
48663c56 | 2 | use rustc::ty::TyCtxt; |
9fa01778 | 3 | use crate::transform::{MirPass, MirSource}; |
dc9dc135 | 4 | use crate::util::expand_aggregate; |
5bcae85e SL |
5 | |
6 | pub struct Deaggregator; | |
7 | ||
e1599b0c | 8 | impl<'tcx> MirPass<'tcx> for Deaggregator { |
60c5eb7d XL |
9 | fn run_pass( |
10 | &self, tcx: TyCtxt<'tcx>, _source: MirSource<'tcx>, body: &mut BodyAndCache<'tcx> | |
11 | ) { | |
dc9dc135 | 12 | let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut(); |
0531ce1d XL |
13 | let local_decls = &*local_decls; |
14 | for bb in basic_blocks { | |
15 | bb.expand_statements(|stmt| { | |
16 | // FIXME(eddyb) don't match twice on `stmt.kind` (post-NLL). | |
e1599b0c XL |
17 | if let StatementKind::Assign(box(_, ref rhs)) = stmt.kind { |
18 | if let Rvalue::Aggregate(ref kind, _) = *rhs { | |
0531ce1d XL |
19 | // FIXME(#48193) Deaggregate arrays when it's cheaper to do so. |
20 | if let AggregateKind::Array(_) = **kind { | |
21 | return None; | |
22 | } | |
476ff2be | 23 | } else { |
0531ce1d XL |
24 | return None; |
25 | } | |
26 | } else { | |
27 | return None; | |
476ff2be SL |
28 | } |
29 | ||
0531ce1d XL |
30 | let stmt = stmt.replace_nop(); |
31 | let source_info = stmt.source_info; | |
dc9dc135 | 32 | let (lhs, kind, operands) = match stmt.kind { |
e1599b0c | 33 | StatementKind::Assign(box(lhs, rvalue)) => { |
0bf4aa26 XL |
34 | match rvalue { |
35 | Rvalue::Aggregate(kind, operands) => (lhs, kind, operands), | |
36 | _ => bug!() | |
37 | } | |
38 | } | |
0531ce1d | 39 | _ => bug!() |
5bcae85e | 40 | }; |
5bcae85e | 41 | |
dc9dc135 XL |
42 | Some(expand_aggregate( |
43 | lhs, | |
44 | operands.into_iter().map(|op| { | |
0531ce1d | 45 | let ty = op.ty(local_decls, tcx); |
dc9dc135 XL |
46 | (op, ty) |
47 | }), | |
48 | *kind, | |
49 | source_info, | |
e74abb32 | 50 | tcx, |
dc9dc135 | 51 | )) |
0531ce1d | 52 | }); |
5bcae85e | 53 | } |
0531ce1d | 54 | } |
5bcae85e | 55 | } |