94f6cb6941
WaferConfig: unified config controlling all optimizations individually. ForthVM::new_with_config(config) to create VMs with custom optimization settings. All 8 switchable optimizations: peephole, constant_fold, strength_reduce, dce, tail_call, inline (IR passes) + stack_to_local_promotion (codegen). Benchmark framework (crates/core/tests/benchmark_report.rs): - 7 Forth benchmarks: Fibonacci, Factorial, SumRecurse, NestedLoops, GCD, MemFill, Collatz - Correctness verification across all configs (runs in CI) - Full report with 128 optimization combinations (cargo test --ignored) - Measures execution time, compilation time, WASM module bytes - CONSOLIDATE impact comparison Key findings from benchmark report: - Inlining: -77% exec time on Fibonacci, -92% on Collatz - Stack-to-local promotion: -5.5% WASM module size - CONSOLIDATE: -72% exec time on Fibonacci (call_indirect -> direct call) - All optimizations combined: best overall performance
62 lines
1.5 KiB
Rust
62 lines
1.5 KiB
Rust
//! Unified configuration for all WAFER optimizations.
|
|
|
|
use crate::optimizer::OptConfig;
|
|
|
|
/// Codegen-level optimization flags.
|
|
#[derive(Debug, Clone)]
|
|
pub struct CodegenOpts {
|
|
/// Enable stack-to-local promotion for straight-line words.
|
|
pub stack_to_local_promotion: bool,
|
|
}
|
|
|
|
/// Master configuration for all WAFER optimizations.
|
|
#[derive(Debug, Clone)]
|
|
pub struct WaferConfig {
|
|
/// IR-level optimization passes.
|
|
pub opt: OptConfig,
|
|
/// Codegen-level optimizations.
|
|
pub codegen: CodegenOpts,
|
|
}
|
|
|
|
impl WaferConfig {
|
|
/// All optimizations enabled.
|
|
pub fn all() -> Self {
|
|
Self {
|
|
opt: OptConfig {
|
|
peephole: true,
|
|
constant_fold: true,
|
|
tail_call: true,
|
|
strength_reduce: true,
|
|
dce: true,
|
|
inline: true,
|
|
},
|
|
codegen: CodegenOpts {
|
|
stack_to_local_promotion: true,
|
|
},
|
|
}
|
|
}
|
|
|
|
/// All optimizations disabled.
|
|
pub fn none() -> Self {
|
|
Self {
|
|
opt: OptConfig {
|
|
peephole: false,
|
|
constant_fold: false,
|
|
tail_call: false,
|
|
strength_reduce: false,
|
|
dce: false,
|
|
inline: false,
|
|
},
|
|
codegen: CodegenOpts {
|
|
stack_to_local_promotion: false,
|
|
},
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Default for WaferConfig {
|
|
fn default() -> Self {
|
|
Self::all()
|
|
}
|
|
}
|