From 3922dd72fe98ecc8866d448fe1e637971a46341a Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Wed, 7 Feb 2018 14:36:03 +0200 Subject: [PATCH] rustc_mir: use the "idiomatic" optimization gating in the deaggregator. --- src/librustc_mir/transform/deaggregator.rs | 27 +++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/librustc_mir/transform/deaggregator.rs b/src/librustc_mir/transform/deaggregator.rs index eccb0d231b89..ea27d789248b 100644 --- a/src/librustc_mir/transform/deaggregator.rs +++ b/src/librustc_mir/transform/deaggregator.rs @@ -21,23 +21,28 @@ impl MirPass for Deaggregator { tcx: TyCtxt<'a, 'tcx, 'tcx>, source: MirSource, mir: &mut Mir<'tcx>) { - let node_path = tcx.item_path_str(source.def_id); - debug!("running on: {:?}", node_path); - // we only run when mir_opt_level > 2 - if tcx.sess.opts.debugging_opts.mir_opt_level <= 2 { - return; - } - // Don't run on constant MIR, because trans might not be able to // evaluate the modified MIR. // FIXME(eddyb) Remove check after miri is merged. let id = tcx.hir.as_local_node_id(source.def_id).unwrap(); match (tcx.hir.body_owner_kind(id), source.promoted) { - (hir::BodyOwnerKind::Fn, None) => {}, - _ => return + (_, Some(_)) | + (hir::BodyOwnerKind::Const, _) | + (hir::BodyOwnerKind::Static(_), _) => return, + + (hir::BodyOwnerKind::Fn, _) => { + if tcx.is_const_fn(source.def_id) { + // Don't run on const functions, as, again, trans might not be able to evaluate + // the optimized IR. + return + } + } + } + + // We only run when the MIR optimization level is > 2. + if tcx.sess.opts.debugging_opts.mir_opt_level <= 2 { + return; } - // In fact, we might not want to trigger in other cases. - // Ex: when we could use SROA. See issue #35259 for bb in mir.basic_blocks_mut() { let mut curr: usize = 0;