Fix waffle-util build.

This commit is contained in:
Chris Fallin 2023-02-07 17:31:52 -08:00
parent fd748dd493
commit 2d7e02deb0
2 changed files with 30 additions and 19 deletions

View file

@ -41,6 +41,19 @@ enum Command {
},
}
fn apply_options(opts: &Options, module: &mut Module) -> Result<()> {
if opts.basic_opts || opts.max_ssa {
module.expand_all_funcs()?;
}
if opts.basic_opts {
module.per_func_body(|body| body.optimize());
}
if opts.max_ssa {
module.per_func_body(|body| body.convert_to_max_ssa());
}
Ok(())
}
fn main() -> Result<()> {
let opts = Options::from_args();
@ -50,29 +63,19 @@ fn main() -> Result<()> {
}
let _ = logger.try_init();
match opts.command {
match &opts.command {
Command::PrintIR { wasm } => {
let bytes = std::fs::read(wasm)?;
debug!("Loaded {} bytes of Wasm data", bytes.len());
let mut module = Module::from_wasm_bytes(&bytes[..])?;
if opts.basic_opts {
module.optimize();
}
if opts.max_ssa {
module.convert_to_max_ssa();
}
apply_options(&opts, &mut module)?;
println!("{}", module.display());
}
Command::RoundTrip { input, output } => {
let bytes = std::fs::read(input)?;
debug!("Loaded {} bytes of Wasm data", bytes.len());
let mut module = Module::from_wasm_bytes(&bytes[..])?;
if opts.basic_opts {
module.optimize();
}
if opts.max_ssa {
module.convert_to_max_ssa();
}
apply_options(&opts, &mut module)?;
let produced = module.to_wasm_bytes()?;
std::fs::write(output, &produced[..])?;
}

View file

@ -34,10 +34,7 @@ impl<'a> FuncDecl<'a> {
pub fn optimize(&mut self) {
match self {
FuncDecl::Body(_, body) => {
let cfg = crate::cfg::CFGInfo::new(body);
crate::passes::basic_opt::gvn(body, &cfg);
crate::passes::resolve_aliases::run(body);
crate::passes::empty_blocks::run(body);
body.optimize();
}
_ => {}
}
@ -46,8 +43,7 @@ impl<'a> FuncDecl<'a> {
pub fn convert_to_max_ssa(&mut self) {
match self {
FuncDecl::Body(_, body) => {
let cfg = crate::cfg::CFGInfo::new(body);
crate::passes::maxssa::run(body, &cfg);
body.convert_to_max_ssa();
}
_ => {}
}
@ -115,6 +111,18 @@ impl FunctionBody {
}
}
pub fn optimize(&mut self) {
let cfg = crate::cfg::CFGInfo::new(self);
crate::passes::basic_opt::gvn(self, &cfg);
crate::passes::resolve_aliases::run(self);
crate::passes::empty_blocks::run(self);
}
pub fn convert_to_max_ssa(&mut self) {
let cfg = crate::cfg::CFGInfo::new(self);
crate::passes::maxssa::run(self, &cfg);
}
pub fn add_block(&mut self) -> Block {
let id = self.blocks.push(BlockDef::default());
log::trace!("add_block: block {}", id);