Struct spirt::cfg::Structurizer
source · pub struct Structurizer<'a> {
cx: &'a Context,
type_bool: Type,
const_true: Const,
const_false: Const,
func_def_body: &'a mut FuncDefBody,
loop_header_to_exit_targets: IndexMap<ControlRegion, IndexSet<ControlRegion, BuildHasherDefault<FxHasher>>, BuildHasherDefault<FxHasher>>,
incoming_edge_counts_including_loop_exits: EntityOrientedDenseMap<ControlRegion, IncomingEdgeCount>,
structurize_region_state: IndexMap<ControlRegion, StructurizeRegionState, BuildHasherDefault<FxHasher>>,
control_region_input_replacements: EntityOrientedDenseMap<ControlRegion, SmallVec<[Value; 2]>>,
}
Expand description
Control-flow “structurizer”, which attempts to convert as much of the CFG as possible into structural control-flow (regions).
See StructurizeRegionState
’s docs for more details on the algorithm.
Fields§
§cx: &'a Context
§type_bool: Type
Scrutinee type for SelectionKind::BoolCond
.
const_true: Const
Scrutinee value for SelectionKind::BoolCond
, for the “then” case.
const_false: Const
Scrutinee value for SelectionKind::BoolCond
, for the “else” case.
func_def_body: &'a mut FuncDefBody
§loop_header_to_exit_targets: IndexMap<ControlRegion, IndexSet<ControlRegion, BuildHasherDefault<FxHasher>>, BuildHasherDefault<FxHasher>>
§incoming_edge_counts_including_loop_exits: EntityOrientedDenseMap<ControlRegion, IncomingEdgeCount>
§structurize_region_state: IndexMap<ControlRegion, StructurizeRegionState, BuildHasherDefault<FxHasher>>
Keyed by the input to structurize_region_from
(the start ControlRegion
),
and describing the state of that partial structurization step.
See also StructurizeRegionState
’s docs.
control_region_input_replacements: EntityOrientedDenseMap<ControlRegion, SmallVec<[Value; 2]>>
Accumulated replacements (caused by target_inputs
s), i.e.:
Value::ControlRegionInput { region, input_idx }
must be replaced
with control_region_input_replacements[region][input_idx]
, as
the original region
cannot have be directly reused.
Implementations§
source§impl<'a> Structurizer<'a>
impl<'a> Structurizer<'a>
pub fn new(cx: &'a Context, func_def_body: &'a mut FuncDefBody) -> Self
pub fn structurize_func(self)
sourcefn apply_value_replacements(self)
fn apply_value_replacements(self)
The last step of structurization is processing bulk replacements
collected while structurizing (like control_region_input_replacements
).
fn claim_or_defer_single_edge( &mut self, target: ControlRegion, target_inputs: SmallVec<[Value; 2]> ) -> PartialControlRegion
fn try_claim_edge_bundle( &mut self, edge_bundle: IncomingEdgeBundle<ControlRegion> ) -> Result<PartialControlRegion, DeferredEdgeBundle<ControlRegion>>
sourcefn structurize_region_from(&mut self, unstructured_region: ControlRegion)
fn structurize_region_from(&mut self, unstructured_region: ControlRegion)
Structurize a region starting from unstructured_region
, and extending
it (by combining the smaller ControlRegion
s) as much as possible into
the CFG (likely everything dominated by unstructured_region
).
The output of this process is stored in, and any other bookkeeping is
done through, self.structurize_region_state[unstructured_region]
.
See also StructurizeRegionState
’s docs.
sourcefn structurize_select(
&mut self,
kind: SelectionKind,
scrutinee: Value,
cases: SmallVec<[PartialControlRegion; 8]>
) -> PartialControlRegion
fn structurize_select( &mut self, kind: SelectionKind, scrutinee: Value, cases: SmallVec<[PartialControlRegion; 8]> ) -> PartialControlRegion
Build a Select
ControlNode
, from partially structured cases
,
merging all of their deferred_{edges,returns}
together.
fn materialize_lazy_cond(&mut self, cond: LazyCond) -> Value
sourcefn repair_unclaimed_region(
&mut self,
unstructured_region: ControlRegion,
partial_control_region: PartialControlRegion
)
fn repair_unclaimed_region( &mut self, unstructured_region: ControlRegion, partial_control_region: PartialControlRegion )
When structurization is only partial, and there remain unclaimed regions,
they have to be reintegrated into the CFG, putting back ControlInst
s
where structurize_region_from
has taken them from.
This function handles one region at a time to make it more manageable,
despite it having a single call site (in a loop in structurize_func
).
sourcefn const_undef(&self, ty: Type) -> Const
fn const_undef(&self, ty: Type) -> Const
Create an undefined constant (as a placeholder where a value needs to be
present, but won’t actually be used), of type ty
.