From 7af964fecf77696e523020a430fd4a0d0d4bc190 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 24 Jun 2020 22:55:12 +0200 Subject: [PATCH] Limit block count --- compiler/rustc_mir/src/transform/dest_prop.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/compiler/rustc_mir/src/transform/dest_prop.rs b/compiler/rustc_mir/src/transform/dest_prop.rs index f9071ab9d802..8080f4a0d650 100644 --- a/compiler/rustc_mir/src/transform/dest_prop.rs +++ b/compiler/rustc_mir/src/transform/dest_prop.rs @@ -115,7 +115,12 @@ use rustc_middle::mir::{ }; use rustc_middle::ty::{self, Ty, TyCtxt}; +// Empirical measurements have resulted in some observations: +// - Running on a body with a single block and 500 locals takes barely any time +// - Running on a body with ~400 blocks and ~300 relevant locals takes "too long" +// ...so we just limit both to somewhat reasonable-ish looking values. const MAX_LOCALS: usize = 500; +const MAX_BLOCKS: usize = 250; pub struct DestinationPropagation; @@ -160,6 +165,15 @@ impl<'tcx> MirPass<'tcx> for DestinationPropagation { ); return; } + if body.basic_blocks().len() > MAX_BLOCKS { + warn!( + "too many blocks in {:?} ({}, max is {}), not optimizing", + source.def_id(), + body.basic_blocks().len(), + MAX_BLOCKS + ); + return; + } let mut conflicts = Conflicts::build(tcx, body, source, &relevant_locals);