Struct Cfg
pub struct Cfg {
pub entry: BlockId,
/* private fields */
}Expand description
The complete CFG for a function.
Fields§
§entry: BlockIdEntry block
Implementations§
§impl Cfg
impl Cfg
pub fn new(
return_type: Type,
num_locals: u32,
num_params: u32,
fn_name: String,
param_modes: Vec<AirParamMode>,
param_types: Vec<Type>,
) -> Cfg
pub fn new( return_type: Type, num_locals: u32, num_params: u32, fn_name: String, param_modes: Vec<AirParamMode>, param_types: Vec<Type>, ) -> Cfg
Create a new CFG.
pub fn record_spawn_target(&mut self, value: CfgValue, target: SpawnTarget)
pub fn record_spawn_target(&mut self, value: CfgValue, target: SpawnTarget)
ADR-0084: record the worker fn + types for a @spawn instruction.
pub fn spawn_target(&self, value: CfgValue) -> Option<&SpawnTarget>
pub fn spawn_target(&self, value: CfgValue) -> Option<&SpawnTarget>
Look up the bookkeeping recorded for a @spawn site, if any.
pub fn return_type(&self) -> Type
pub fn return_type(&self) -> Type
Get the return type.
pub fn num_locals(&self) -> u32
pub fn num_locals(&self) -> u32
Get the number of local variable slots.
pub 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.
pub fn num_params(&self) -> u32
pub fn num_params(&self) -> u32
Get the number of parameter slots.
pub fn param_mode(&self, slot: u32) -> AirParamMode
pub fn param_mode(&self, slot: u32) -> AirParamMode
Get the passing mode for a parameter slot.
pub fn is_param_mut_ref(&self, slot: u32) -> bool
pub fn is_param_mut_ref(&self, slot: u32) -> bool
Get whether a parameter slot is an exclusive mutable borrow per the legacy mode mechanism.
pub fn is_param_ref(&self, slot: u32) -> bool
pub fn is_param_ref(&self, slot: u32) -> bool
Get whether a parameter slot is a shared immutable borrow (legacy
Ref mode or ADR-0062 Ref(T)-typed parameter).
pub fn is_param_by_ref(&self, slot: u32) -> bool
pub fn is_param_by_ref(&self, slot: u32) -> bool
Get whether a parameter slot is passed by reference (inout or borrow,
or an ADR-0062 Ref(T) / MutRef(T) parameter type).
ADR-0056: interface-typed parameters carry their own data pointer
inside the fat-pointer struct, so they are passed by value at the
LLVM ABI level even when the source-level mode is borrow/inout.
The borrow/inout semantics still apply to the underlying data via
the data_ptr field of the fat pointer; the ABI just doesn’t add
another layer of indirection.
pub fn param_modes(&self) -> &[AirParamMode]
pub fn param_modes(&self) -> &[AirParamMode]
Get the parameter modes slice.
pub 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.
pub fn new_block(&mut self) -> BlockId
pub fn new_block(&mut self) -> BlockId
Create a new basic block and return its ID.
pub fn get_block(&self, id: BlockId) -> &BasicBlock
pub fn get_block(&self, id: BlockId) -> &BasicBlock
Get a block by ID.
pub 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.
pub 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.
pub fn get_inst(&self, value: CfgValue) -> &CfgInst
pub fn get_inst(&self, value: CfgValue) -> &CfgInst
Get an instruction by value reference.
pub 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.
pub fn value_count(&self) -> usize
pub fn value_count(&self) -> usize
Get the total number of values (instructions) in the CFG.
pub 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.
pub 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.
pub 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.
pub 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.
pub 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.
pub 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).
pub 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.
pub fn get_place_projections(&self, place: &Place) -> &[Projection]
pub fn get_place_projections(&self, place: &Place) -> &[Projection]
Get projections for a place.
pub 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.
pub fn get_goto_args(&self, term: &Terminator) -> &[CfgValue]
pub fn get_goto_args(&self, term: &Terminator) -> &[CfgValue]
pub 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.
pub 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.
pub 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.
pub 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.
pub 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.
pub fn blocks(&self) -> &[BasicBlock]
pub fn blocks(&self) -> &[BasicBlock]
Get all blocks.
pub fn block_count(&self) -> usize
pub fn block_count(&self) -> usize
Get the number of blocks.
pub fn compute_predecessors(&mut self)
pub fn compute_predecessors(&mut self)
Compute predecessor lists for all blocks.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Cfg
impl RefUnwindSafe for Cfg
impl Send for Cfg
impl Sync for Cfg
impl Unpin for Cfg
impl UnsafeUnpin for Cfg
impl UnwindSafe for Cfg
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
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