From 2713240bd050d583410015d07b5e81ff53033da3 Mon Sep 17 00:00:00 2001 From: Chris Fallin Date: Tue, 28 Feb 2023 16:15:44 -0800 Subject: [PATCH] Remove Fuel -- no longer needed --- fuzz/fuzz_targets/differential.rs | 2 +- fuzz/fuzz_targets/opt_diff.rs | 2 +- fuzz/fuzz_targets/roundtrip.rs | 4 ++-- src/bin/waffle-util.rs | 2 +- src/ir/func.rs | 15 +++++++-------- src/lib.rs | 1 - src/passes.rs | 26 -------------------------- src/passes/basic_opt.rs | 17 +++++------------ src/passes/empty_blocks.rs | 9 +++------ src/passes/remove_phis.rs | 6 +----- 10 files changed, 21 insertions(+), 63 deletions(-) diff --git a/fuzz/fuzz_targets/differential.rs b/fuzz/fuzz_targets/differential.rs index c10311e..b72af67 100644 --- a/fuzz/fuzz_targets/differential.rs +++ b/fuzz/fuzz_targets/differential.rs @@ -38,7 +38,7 @@ fuzz_target!( let mut parsed_module = Module::from_wasm_bytes(&orig_bytes[..], &FrontendOptions::default()).unwrap(); parsed_module.expand_all_funcs().unwrap(); - parsed_module.per_func_body(|body| body.optimize(&mut waffle::passes::Fuel::infinite())); + parsed_module.per_func_body(|body| body.optimize()); let roundtrip_bytes = parsed_module.to_wasm_bytes().unwrap(); if let Ok(filename) = std::env::var("FUZZ_DUMP_WASM") { diff --git a/fuzz/fuzz_targets/opt_diff.rs b/fuzz/fuzz_targets/opt_diff.rs index dc25d7d..d910e17 100644 --- a/fuzz/fuzz_targets/opt_diff.rs +++ b/fuzz/fuzz_targets/opt_diff.rs @@ -48,7 +48,7 @@ fuzz_target!( } let mut opt_module = parsed_module.clone(); - opt_module.per_func_body(|body| body.optimize(&mut waffle::Fuel::infinite())); + opt_module.per_func_body(|body| body.optimize()); opt_module.per_func_body(|body| body.convert_to_max_ssa()); let mut opt_ctx = InterpContext::new(&opt_module).unwrap(); diff --git a/fuzz/fuzz_targets/roundtrip.rs b/fuzz/fuzz_targets/roundtrip.rs index ba9f49b..1375a97 100644 --- a/fuzz/fuzz_targets/roundtrip.rs +++ b/fuzz/fuzz_targets/roundtrip.rs @@ -1,7 +1,7 @@ #![no_main] use libfuzzer_sys::fuzz_target; -use waffle::{FrontendError, FrontendOptions, Fuel, Module}; +use waffle::{FrontendError, FrontendOptions, Module}; fuzz_target!(|module: wasm_smith::Module| { let _ = env_logger::try_init(); @@ -26,6 +26,6 @@ fuzz_target!(|module: wasm_smith::Module| { } }; parsed_module.expand_all_funcs().unwrap(); - parsed_module.per_func_body(|body| body.optimize(&mut Fuel::infinite())); + parsed_module.per_func_body(|body| body.optimize()); let _ = parsed_module.to_wasm_bytes(); }); diff --git a/src/bin/waffle-util.rs b/src/bin/waffle-util.rs index fd142a4..5f1c7e3 100644 --- a/src/bin/waffle-util.rs +++ b/src/bin/waffle-util.rs @@ -57,7 +57,7 @@ enum Command { fn apply_options(opts: &Options, module: &mut Module) -> Result<()> { module.expand_all_funcs()?; if opts.basic_opts { - module.per_func_body(|body| body.optimize(&mut waffle::passes::Fuel::infinite())); + module.per_func_body(|body| body.optimize()); } if opts.max_ssa { module.per_func_body(|body| body.convert_to_max_ssa()); diff --git a/src/ir/func.rs b/src/ir/func.rs index d1ea31e..e00df9c 100644 --- a/src/ir/func.rs +++ b/src/ir/func.rs @@ -3,7 +3,6 @@ use crate::cfg::CFGInfo; use crate::entity::{EntityRef, EntityVec, PerEntity}; use crate::frontend::parse_body; use crate::ir::SourceLoc; -use crate::passes::Fuel; use anyhow::Result; use std::ops::Range; @@ -49,11 +48,11 @@ impl<'a> FuncDecl<'a> { } } - pub fn optimize(&mut self, fuel: &mut Fuel) { + pub fn optimize(&mut self) { self.mark_dirty(); match self { FuncDecl::Body(_, _, body) => { - body.optimize(fuel); + body.optimize(); } _ => {} } @@ -163,12 +162,12 @@ impl FunctionBody { } } - pub fn optimize(&mut self, fuel: &mut Fuel) { + pub fn optimize(&mut self) { let cfg = crate::cfg::CFGInfo::new(self); - crate::passes::remove_phis::run(self, &cfg, fuel); - crate::passes::basic_opt::gvn(self, &cfg, fuel); - crate::passes::remove_phis::run(self, &cfg, fuel); - crate::passes::empty_blocks::run(self, fuel); + crate::passes::remove_phis::run(self, &cfg); + crate::passes::basic_opt::gvn(self, &cfg); + crate::passes::remove_phis::run(self, &cfg); + crate::passes::empty_blocks::run(self); } pub fn convert_to_max_ssa(&mut self) { diff --git a/src/lib.rs b/src/lib.rs index 5fe4255..c527f4c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,7 +14,6 @@ mod ir; mod op_traits; mod ops; pub mod passes; -pub use passes::Fuel; mod scoped_map; pub use errors::*; diff --git a/src/passes.rs b/src/passes.rs index 720fd58..c6d4a58 100644 --- a/src/passes.rs +++ b/src/passes.rs @@ -8,29 +8,3 @@ pub mod remove_phis; pub mod resolve_aliases; pub mod ssa; pub mod trace; - -#[derive(Clone, Debug)] -pub struct Fuel { - pub remaining: u64, - pub consumed: u64, -} -impl Fuel { - pub fn consume(&mut self) -> bool { - self.consumed += 1; - if self.remaining == u64::MAX { - return true; - } - if self.remaining == 0 { - false - } else { - self.remaining -= 1; - true - } - } - pub fn infinite() -> Fuel { - Fuel { - consumed: 0, - remaining: u64::MAX, - } - } -} diff --git a/src/passes/basic_opt.rs b/src/passes/basic_opt.rs index 44db018..54433ac 100644 --- a/src/passes/basic_opt.rs +++ b/src/passes/basic_opt.rs @@ -4,28 +4,25 @@ use crate::cfg::CFGInfo; use crate::interp::{const_eval, ConstVal}; use crate::ir::*; use crate::passes::dom_pass::{dom_pass, DomtreePass}; -use crate::passes::Fuel; use crate::scoped_map::ScopedMap; use crate::Operator; -pub fn gvn(body: &mut FunctionBody, cfg: &CFGInfo, fuel: &mut Fuel) { - dom_pass::>( +pub fn gvn(body: &mut FunctionBody, cfg: &CFGInfo) { + dom_pass::( body, cfg, &mut GVNPass { map: ScopedMap::default(), - fuel, }, ); } #[derive(Debug)] -struct GVNPass<'a> { +struct GVNPass { map: ScopedMap, - fuel: &'a mut Fuel, } -impl<'a> DomtreePass for GVNPass<'a> { +impl DomtreePass for GVNPass { fn enter(&mut self, block: Block, body: &mut FunctionBody) { self.map.push_level(); self.optimize(block, body); @@ -43,7 +40,7 @@ fn value_is_pure(value: Value, body: &FunctionBody) -> bool { } } -impl<'a> GVNPass<'a> { +impl GVNPass { fn optimize(&mut self, block: Block, body: &mut FunctionBody) { let mut i = 0; while i < body.blocks[block].insts.len() { @@ -111,10 +108,6 @@ impl<'a> GVNPass<'a> { } if let Some(value) = self.map.get(&value) { - if !self.fuel.consume() { - return; - } - body.set_alias(inst, *value); i -= 1; body.blocks[block].insts.remove(i); diff --git a/src/passes/empty_blocks.rs b/src/passes/empty_blocks.rs index 04e72f5..f64e091 100644 --- a/src/passes/empty_blocks.rs +++ b/src/passes/empty_blocks.rs @@ -1,6 +1,5 @@ //! Pass to remove empty blocks. -use super::Fuel; use crate::entity::EntityRef; use crate::ir::{Block, BlockTarget, FunctionBody, Terminator}; @@ -38,7 +37,7 @@ fn rewrite_target( forwardings[target.block.index()].clone() } -pub fn run(body: &mut FunctionBody, fuel: &mut Fuel) { +pub fn run(body: &mut FunctionBody) { log::trace!( "empty_blocks: running on func:\n{}\n", body.display_verbose("| ", None) @@ -62,10 +61,8 @@ pub fn run(body: &mut FunctionBody, fuel: &mut Fuel) { for block_data in body.blocks.values_mut() { block_data.terminator.update_targets(|target| { if let Some(new_target) = rewrite_target(&forwardings[..], target) { - if fuel.consume() { - log::trace!("empty_blocks: replacing {:?} with {:?}", target, new_target); - *target = new_target; - } + log::trace!("empty_blocks: replacing {:?} with {:?}", target, new_target); + *target = new_target; } }); } diff --git a/src/passes/remove_phis.rs b/src/passes/remove_phis.rs index 6a4b742..9a5d692 100644 --- a/src/passes/remove_phis.rs +++ b/src/passes/remove_phis.rs @@ -1,6 +1,5 @@ //! Remove-useless-phis (blockparams) pass. -use super::Fuel; use crate::cfg::CFGInfo; use crate::ir::*; @@ -30,7 +29,7 @@ fn delete_indices(vec: &mut Vec, indices: &[usize]) { } } -pub fn run(func: &mut FunctionBody, cfg: &CFGInfo, fuel: &mut Fuel) { +pub fn run(func: &mut FunctionBody, cfg: &CFGInfo) { // For every block, collect the arg-lists of preds. If a given // blockparam has all the same values for an arg, replace the // blockparam value with an alias to that one value, and then @@ -73,9 +72,6 @@ pub fn run(func: &mut FunctionBody, cfg: &CFGInfo, fuel: &mut Fuel) { .map(|arglist| func.resolve_alias(arglist[i])), ); if let Some(val) = same { - if !fuel.consume() { - continue; - } if val != blockparam { log::trace!( "deleting blockparam {} from block {}: now {}",