pub struct Optimizer {
level: u8,
stats: OptimizationStats,
inline_threshold: usize,
enabled_passes: OptimizationPasses,
}Expand description
Yul AST optimizer with configurable optimization levels
Fields§
§level: u8§stats: OptimizationStats§inline_threshold: usizeMaximum function size for inlining (in AST nodes)
enabled_passes: OptimizationPassesTrack which optimizations are enabled
Implementations§
§impl Optimizer
impl Optimizer
pub fn with_config(level: u8, inline_threshold: usize) -> Self
pub fn with_config(level: u8, inline_threshold: usize) -> Self
Create optimizer with custom settings
pub fn optimize(&mut self, ast: AstNode) -> Result<AstNode, CompilerError>
pub fn optimize(&mut self, ast: AstNode) -> Result<AstNode, CompilerError>
Run all enabled optimization passes
pub fn get_stats(&self) -> &OptimizationStats
pub fn get_stats(&self) -> &OptimizationStats
Get optimization statistics
fn count_nodes(&self, node: &AstNode) -> usize
fn count_nodes(&self, node: &AstNode) -> usize
Count AST nodes for statistics
§impl Optimizer
impl Optimizer
fn constant_folding(&mut self, ast: AstNode) -> Result<AstNode, CompilerError>
fn fold_constants_recursive(&mut self, node: AstNode) -> AstNode
fn evaluate_constant_expression( &self, name: &str, arguments: &[AstNode], ) -> Option<u64>
fn simplify_identity_ops(
&self,
name: &str,
args: Vec<AstNode>,
line: usize,
column: usize,
) -> Option<AstNode>
fn simplify_identity_ops( &self, name: &str, args: Vec<AstNode>, line: usize, column: usize, ) -> Option<AstNode>
Simplify identity operations like x + 0 = x, x * 1 = x
fn nodes_equal(&self, a: &AstNode, b: &AstNode) -> bool
fn nodes_equal(&self, a: &AstNode, b: &AstNode) -> bool
Check if two AST nodes are structurally equal
fn extract_constant(&self, node: &AstNode) -> Option<u64>
§impl Optimizer
impl Optimizer
fn dead_code_elimination( &mut self, ast: AstNode, ) -> Result<AstNode, CompilerError>
fn eliminate_dead_code_recursive( &mut self, node: AstNode, _after_return: bool, ) -> AstNode
fn process_statement_list(&mut self, statements: Vec<AstNode>) -> Vec<AstNode>
fn process_statement_list(&mut self, statements: Vec<AstNode>) -> Vec<AstNode>
Process a list of statements, removing dead code after terminators
fn is_terminator(&self, node: &AstNode) -> bool
fn is_terminator(&self, node: &AstNode) -> bool
Check if a statement is a control flow terminator
fn is_label(&self, _node: &AstNode) -> bool
fn is_label(&self, _node: &AstNode) -> bool
Check if a node is a label (should be preserved) Note: Labels are not currently supported in this compiler’s AST. This function exists for future extension when label support is added.
fn is_empty_block(&self, node: &AstNode) -> bool
fn is_empty_block(&self, node: &AstNode) -> bool
Check if a block is empty or contains only empty blocks
fn is_pure_expression(&self, node: &AstNode) -> bool
fn is_pure_expression(&self, node: &AstNode) -> bool
Check if an expression has no side effects
fn remove_empty_blocks(&self, node: AstNode) -> AstNode
fn remove_empty_blocks(&self, node: AstNode) -> AstNode
Remove nested empty blocks
§impl Optimizer
impl Optimizer
fn function_inlining(&mut self, ast: AstNode) -> Result<AstNode, CompilerError>
fn count_call_sites(&self, node: &AstNode) -> HashMap<String, usize>
fn count_call_sites(&self, node: &AstNode) -> HashMap<String, usize>
Count how many times each function is called
fn count_calls_recursive( &self, node: &AstNode, counts: &mut HashMap<String, usize>, )
fn collect_inline_candidates( &self, node: &AstNode, candidates: &mut HashMap<String, InlineCandidate>, )
fn is_inlineable_function(&self, body: &AstNode, name: &str) -> bool
fn is_inlineable_function(&self, body: &AstNode, name: &str) -> bool
Check if a function is suitable for inlining
fn contains_call_to(&self, node: &AstNode, target: &str) -> bool
fn contains_call_to(&self, node: &AstNode, target: &str) -> bool
Check if body contains a call to the named function (recursion check)
fn is_simple_function(&self, body: &AstNode) -> bool
fn estimate_inline_cost(&self, body: &AstNode) -> usize
fn estimate_inline_cost(&self, body: &AstNode) -> usize
Estimate the cost of inlining a function body
fn inline_functions_recursive( &mut self, node: AstNode, candidates: &HashMap<String, InlineCandidate>, ) -> AstNode
Auto Trait Implementations§
impl Freeze for Optimizer
impl RefUnwindSafe for Optimizer
impl Send for Optimizer
impl Sync for Optimizer
impl Unpin for Optimizer
impl UnwindSafe for Optimizer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more