pub struct Cfg {
pub entry: BlockId,
/* private fields */
}Expand description
The complete CFG for a function.
Fields§
§entry: BlockIdEntry block
Implementations§
Source§impl Cfg
impl Cfg
Sourcepub fn new(
return_type: Type,
num_locals: u32,
num_params: u32,
fn_name: String,
param_modes: Vec<bool>,
param_types: Vec<Type>,
) -> Self
pub fn new( return_type: Type, num_locals: u32, num_params: u32, fn_name: String, param_modes: Vec<bool>, param_types: Vec<Type>, ) -> Self
Create a new CFG.
Sourcepub fn return_type(&self) -> Type
pub fn return_type(&self) -> Type
Get the return type.
Sourcepub fn num_locals(&self) -> u32
pub fn num_locals(&self) -> u32
Get the number of local variable slots.
Sourcepub fn alloc_temp_local(&mut self) -> u32
pub fn alloc_temp_local(&mut self) -> u32
Allocate a new temporary local slot for spilling computed values.
This is used during CFG construction when a computed value (e.g., method call result) needs to be accessed via a place expression. The value is spilled to this temporary slot.
Returns the slot number for the new local.
Sourcepub fn num_params(&self) -> u32
pub fn num_params(&self) -> u32
Get the number of parameter slots.
Sourcepub fn is_param_inout(&self, slot: u32) -> bool
pub fn is_param_inout(&self, slot: u32) -> bool
Get whether a parameter slot is inout.
Sourcepub fn param_modes(&self) -> &[bool]
pub fn param_modes(&self) -> &[bool]
Get the parameter modes slice.
Sourcepub fn param_type(&self, slot: u32) -> Option<Type>
pub fn param_type(&self, slot: u32) -> Option<Type>
Get the type of a parameter slot.
Returns None if the slot index is out of range.
Sourcepub fn get_block(&self, id: BlockId) -> &BasicBlock
pub fn get_block(&self, id: BlockId) -> &BasicBlock
Get a block by ID.
Sourcepub fn get_block_mut(&mut self, id: BlockId) -> &mut BasicBlock
pub fn get_block_mut(&mut self, id: BlockId) -> &mut BasicBlock
Get a block mutably by ID.
Sourcepub fn add_inst(&mut self, inst: CfgInst) -> CfgValue
pub fn add_inst(&mut self, inst: CfgInst) -> CfgValue
Add an instruction and return its value reference.
Sourcepub fn get_inst_mut(&mut self, value: CfgValue) -> &mut CfgInst
pub fn get_inst_mut(&mut self, value: CfgValue) -> &mut CfgInst
Get a mutable instruction by value reference.
Sourcepub fn value_count(&self) -> usize
pub fn value_count(&self) -> usize
Get the total number of values (instructions) in the CFG.
Sourcepub fn push_extra(
&mut self,
values: impl IntoIterator<Item = CfgValue>,
) -> (u32, u32)
pub fn push_extra( &mut self, values: impl IntoIterator<Item = CfgValue>, ) -> (u32, u32)
Add values to the extra array and return (start, len).
Used for StructInit fields, ArrayInit elements, and Intrinsic args.
Sourcepub fn push_call_args(
&mut self,
args: impl IntoIterator<Item = CfgCallArg>,
) -> (u32, u32)
pub fn push_call_args( &mut self, args: impl IntoIterator<Item = CfgCallArg>, ) -> (u32, u32)
Add call arguments to the call_args array and return (start, len).
Used for Call instruction arguments.
Sourcepub fn get_call_args(&self, start: u32, len: u32) -> &[CfgCallArg]
pub fn get_call_args(&self, start: u32, len: u32) -> &[CfgCallArg]
Get a slice from the call_args array.
Sourcepub fn push_switch_cases(
&mut self,
cases: impl IntoIterator<Item = (i64, BlockId)>,
) -> (u32, u32)
pub fn push_switch_cases( &mut self, cases: impl IntoIterator<Item = (i64, BlockId)>, ) -> (u32, u32)
Add switch cases to the switch_cases array and return (start, len).
Used for Switch terminator cases.
Sourcepub fn get_switch_cases(&self, start: u32, len: u32) -> &[(i64, BlockId)]
pub fn get_switch_cases(&self, start: u32, len: u32) -> &[(i64, BlockId)]
Get a slice from the switch_cases array.
Sourcepub fn push_projections(
&mut self,
projs: impl IntoIterator<Item = Projection>,
) -> (u32, u32)
pub fn push_projections( &mut self, projs: impl IntoIterator<Item = Projection>, ) -> (u32, u32)
Add projections to the projections array and return (start, len).
Used for PlaceRead and PlaceWrite instructions (ADR-0030).
Sourcepub fn get_projections(&self, start: u32, len: u32) -> &[Projection]
pub fn get_projections(&self, start: u32, len: u32) -> &[Projection]
Get a slice from the projections array.
Sourcepub fn get_place_projections(&self, place: &Place) -> &[Projection]
pub fn get_place_projections(&self, place: &Place) -> &[Projection]
Get projections for a place.
Sourcepub fn make_place(
&mut self,
base: PlaceBase,
projs: impl IntoIterator<Item = Projection>,
) -> Place
pub fn make_place( &mut self, base: PlaceBase, projs: impl IntoIterator<Item = Projection>, ) -> Place
Create a place with the given base and projections.
This adds the projections to the projections array and returns a Place that references them.
Sourcepub fn get_goto_args(&self, term: &Terminator) -> &[CfgValue]
pub fn get_goto_args(&self, term: &Terminator) -> &[CfgValue]
Sourcepub fn get_branch_then_args(&self, term: &Terminator) -> &[CfgValue]
pub fn get_branch_then_args(&self, term: &Terminator) -> &[CfgValue]
Get the then branch arguments from a Branch terminator.
§Panics
Panics if the terminator is not a Branch.
Sourcepub fn get_branch_else_args(&self, term: &Terminator) -> &[CfgValue]
pub fn get_branch_else_args(&self, term: &Terminator) -> &[CfgValue]
Get the else branch arguments from a Branch terminator.
§Panics
Panics if the terminator is not a Branch.
Sourcepub fn add_inst_to_block(&mut self, block: BlockId, inst: CfgInst) -> CfgValue
pub fn add_inst_to_block(&mut self, block: BlockId, inst: CfgInst) -> CfgValue
Add an instruction to a block.
Sourcepub fn add_block_param(&mut self, block: BlockId, ty: Type) -> CfgValue
pub fn add_block_param(&mut self, block: BlockId, ty: Type) -> CfgValue
Add a block parameter and return its value.
Sourcepub fn set_terminator(&mut self, block: BlockId, term: Terminator)
pub fn set_terminator(&mut self, block: BlockId, term: Terminator)
Set the terminator for a block.
Sourcepub fn blocks(&self) -> &[BasicBlock]
pub fn blocks(&self) -> &[BasicBlock]
Get all blocks.
Sourcepub fn block_count(&self) -> usize
pub fn block_count(&self) -> usize
Get the number of blocks.
Sourcepub fn compute_predecessors(&mut self)
pub fn compute_predecessors(&mut self)
Compute predecessor lists for all blocks.