pub struct ConstFoldingContext<'a> {
pub variables: &'a mut Arena<Variable>,
/* private fields */
}Fields§
§variables: &'a mut Arena<Variable>The variables arena, mostly used to get the type of variables.
Implementations§
Source§impl<'a> ConstFoldingContext<'a>
impl<'a> ConstFoldingContext<'a>
pub fn new( db: &'a dyn LoweringGroup, function_id: ConcreteFunctionWithBodyId, variables: &'a mut Arena<Variable>, ) -> Self
Sourcepub fn visit_block_start<'b>(
&mut self,
block_id: BlockId,
get_block: impl FnOnce(BlockId) -> &'b Block,
) -> bool
pub fn visit_block_start<'b>( &mut self, block_id: BlockId, get_block: impl FnOnce(BlockId) -> &'b Block, ) -> bool
Determines if a block is reachable from the function start and propagates constant values when the block is reachable via a single goto statement.
Sourcepub fn visit_statement(&mut self, stmt: &mut Statement)
pub fn visit_statement(&mut self, stmt: &mut Statement)
Processes a statement and applies the constant folding optimizations.
This method performs the following operations:
- Updates the
var_infomap with constant values of variables - Replace the input statement with optimized versions when possible
- Updates
self.additional_stmtswith statements that need to be added to the block.
Note: self.visit_block_end must be called after processing all statements
in a block to actually add the additional statements.
Sourcepub fn visit_block_end(&mut self, block_id: BlockId, block: &mut Block)
pub fn visit_block_end(&mut self, block_id: BlockId, block: &mut Block)
Processes the block’s end and incorporates additional statements into the block.
This method handles the following tasks:
- Inserts the accumulated additional statements into the block.
- Converts match endings to goto when applicable.
- Updates self.reachability based on the block’s ending.
Sourcepub fn should_skip_const_folding(&self, db: &dyn LoweringGroup) -> bool
pub fn should_skip_const_folding(&self, db: &dyn LoweringGroup) -> bool
Returns true if const-folding should be skipped for the current function.
Trait Implementations§
Source§impl Deref for ConstFoldingContext<'_>
impl Deref for ConstFoldingContext<'_>
Source§type Target = ConstFoldingLibfuncInfo
type Target = ConstFoldingLibfuncInfo
The resulting type after dereferencing.
Source§fn deref(&self) -> &ConstFoldingLibfuncInfo
fn deref(&self) -> &ConstFoldingLibfuncInfo
Dereferences the value.
Auto Trait Implementations§
impl<'a> Freeze for ConstFoldingContext<'a>
impl<'a> !RefUnwindSafe for ConstFoldingContext<'a>
impl<'a> !Send for ConstFoldingContext<'a>
impl<'a> !Sync for ConstFoldingContext<'a>
impl<'a> Unpin for ConstFoldingContext<'a>
impl<'a> !UnwindSafe for ConstFoldingContext<'a>
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
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
Converts
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>
Converts
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