Wasm: implement dead code elimination

This commit is contained in:
Brian Carroll 2022-01-11 21:16:20 +00:00
parent 98400cae1b
commit 8a01c3f98a
6 changed files with 230 additions and 66 deletions

View file

@ -13,7 +13,6 @@ use roc_module::symbol::{Interns, ModuleId, Symbol};
use roc_mono::code_gen_help::CodeGenHelp;
use roc_mono::ir::{Proc, ProcLayout};
use roc_mono::layout::LayoutIds;
use roc_reporting::internal_error;
use crate::backend::WasmBackend;
use crate::wasm_module::{
@ -42,7 +41,7 @@ pub fn build_module<'a>(
procedures: MutMap<(Symbol, ProcLayout<'a>), Proc<'a>>,
) -> Result<std::vec::Vec<u8>, String> {
let (wasm_module, _) = build_module_help(env, interns, preload_bytes, procedures)?;
let mut buffer = std::vec::Vec::with_capacity(4096);
let mut buffer = std::vec::Vec::with_capacity(wasm_module.size());
wasm_module.serialize(&mut buffer);
Ok(buffer)
}
@ -59,6 +58,7 @@ pub fn build_module_help<'a>(
let mut linker_symbols = Vec::with_capacity_in(procedures.len() * 2, env.arena);
let mut exports = Vec::with_capacity_in(4, env.arena);
let mut maybe_main_fn_index = None;
let eliminate_dead_preloads = true;
// Collect the symbols & names for the procedures,
// and filter out procs we're going to inline
@ -146,7 +146,7 @@ pub fn build_module_help<'a>(
backend.build_proc(proc);
}
let module = backend.into_module();
let module = backend.into_module(eliminate_dead_preloads);
let main_function_index = maybe_main_fn_index.unwrap() + fn_index_offset;
Ok((module, main_function_index))
@ -214,10 +214,6 @@ macro_rules! round_up_to_alignment {
};
}
pub fn debug_panic<E: std::fmt::Debug>(error: E) {
internal_error!("{:?}", error);
}
pub struct WasmDebugLogSettings {
proc_start_end: bool,
user_procs_ir: bool,
@ -233,5 +229,5 @@ pub const DEBUG_LOG_SETTINGS: WasmDebugLogSettings = WasmDebugLogSettings {
helper_procs_ir: false && cfg!(debug_assertions),
let_stmt_ir: false && cfg!(debug_assertions),
instructions: false && cfg!(debug_assertions),
keep_test_binary: true && cfg!(debug_assertions),
keep_test_binary: false && cfg!(debug_assertions),
};