From e1c8878b33a6a1908248f42069e407105618167e Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Mon, 14 Sep 2020 08:46:34 -0700 Subject: [PATCH] cranelift_codegen::souper_harvest: Move preopt out of `Context`, into `clif-util` This allows for more flexibility of when/where to harvest LHS candidates. For example, we could choose to harvest candidates that overlap with and supercede our current preopt peepholes. This commit also makes sure that we compute the CFG before running preopt, when harvesting LHS candidates via `clif-util souper-harvest`. --- cranelift/codegen/src/context.rs | 2 -- cranelift/src/souper_harvest.rs | 6 +++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cranelift/codegen/src/context.rs b/cranelift/codegen/src/context.rs index 81b9dcbd23..842a48ab21 100644 --- a/cranelift/codegen/src/context.rs +++ b/cranelift/codegen/src/context.rs @@ -457,10 +457,8 @@ impl Context { #[cfg(feature = "souper-harvest")] pub fn souper_harvest( &mut self, - isa: &dyn TargetIsa, out: &mut std::sync::mpsc::Sender, ) -> CodegenResult<()> { - self.preopt(isa)?; do_souper_harvest(&self.func, out); Ok(()) } diff --git a/cranelift/src/souper_harvest.rs b/cranelift/src/souper_harvest.rs index 4167611b72..6c15547ae1 100644 --- a/cranelift/src/souper_harvest.rs +++ b/cranelift/src/souper_harvest.rs @@ -71,7 +71,11 @@ pub fn run(target: &str, input: &str, output: &str, flag_set: &[String]) -> Resu let mut ctx = Context::new(); ctx.func = func; - ctx.souper_harvest(fisa.isa.unwrap(), send) + ctx.compute_cfg(); + ctx.preopt(fisa.isa.unwrap()) + .map_err(|e| format!("failed to run preopt: {}", e))?; + + ctx.souper_harvest(send) .map_err(|e| format!("failed to run souper harvester: {}", e))?; Ok(())