Hold a nesting to the whole construction contract, not just its value flow
Splitting the owned-CFG check leaves a structural half that reads only control flow: construct containment, structured exits, switch merges, back edges, and continue-target ownership. It needs no module-wide type tables, so the nesting structurizer can hold its own output to it before adopting it. Re-auditing the 107 rows the corpus-wide translation census failed on: 17 now translate, and every 'owned switch case exits to a non-structured target' and 'owned edge exits a construct without a structured target' failure is gone -- those functions go back to the state machine instead of shipping a nesting that leaves a construct through an unstructured edge. bugs/fragment-code-size-explosion is unaffected: still 168 loops, 608 dispatch cases, 33 function-scope variables, spirv-val vulkan1.2 PASS.
This commit is contained in:
1 parent
e3914e93c7
commit
2722041b06
2 files changed
+30
-20
No files matched your search
+18
-9
@@ -187,6 +187,14 @@ impl OwnedCfg {
|
||||
value_types: &HashMap<Word, Word>,
|
||||
) -> Result<(), String> {
|
||||
self.check_block_layout(function, definitions, value_types)?;
|
||||
self.check_structure(function)
|
||||
}
|
||||
|
||||
/// The half of [`Self::check`] that reads only control flow: construct containment, structured
|
||||
/// exits, switch merges, back edges, and continue-target ownership. It needs no module-wide
|
||||
/// type tables, so a pass that rewrites a function's blocks can hold its own output to the
|
||||
/// same rules before adopting it.
|
||||
fn check_structure(&self, function: &Function) -> Result<(), String> {
|
||||
if !dominators_precede_blocks(&self.flow_reachable, &self.flow_idom) {
|
||||
return Err(
|
||||
"native emitter: owned block is serialized before one of its dominators"
|
||||
@@ -1025,15 +1033,16 @@ fn definition_sites(function: &Function) -> Result<HashMap<Word, DefinitionSite>
|
||||
Ok(sites)
|
||||
}
|
||||
|
||||
/// Report the first way `function` breaks the owned contract that binds values to control flow:
|
||||
/// a use its definition does not dominate, or an `OpPhi` whose incoming pairs do not match the
|
||||
/// block's predecessors and result type.
|
||||
/// Report the first way `function` breaks the part of the owned contract that a control-flow
|
||||
/// rewrite is answerable for: an unowned or badly nested construct, an unstructured exit, a use its
|
||||
/// definition does not dominate, or an `OpPhi` whose incoming pairs do not match the block's
|
||||
/// predecessors and result type.
|
||||
///
|
||||
/// This is the part of the module contract a control-flow rewrite is answerable for, so a pass
|
||||
/// that reshapes blocks can check its own output before adopting it rather than assume the reshape
|
||||
/// preserved dominance. `value_types` maps result ids to their result types; ids missing from it
|
||||
/// are not type-checked.
|
||||
pub(super) fn owned_function_value_flow_error(
|
||||
/// A pass that reshapes a function's blocks uses this to hold its own output to those rules before
|
||||
/// adopting it, rather than assume the reshape preserved them. Everything left out needs the
|
||||
/// module-wide type tables and is checked once, later, over the whole module. `value_types` maps
|
||||
/// result ids to their result types; ids missing from it are not type-checked.
|
||||
pub(super) fn owned_function_construction_error(
|
||||
function: &Function,
|
||||
value_types: &HashMap<Word, Word>,
|
||||
) -> Option<String> {
|
||||
@@ -1057,7 +1066,7 @@ pub(super) fn owned_function_value_flow_error(
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
cfg.check_structure(function).err()
|
||||
}
|
||||
|
||||
fn build_predecessors(successors: &[Vec<usize>]) -> Vec<Vec<usize>> {
|
||||
|
||||
@@ -70,17 +70,18 @@ pub(crate) fn structure_selected_functions(
|
||||
Some((instruction.result_id?, instruction.result_type?))
|
||||
})
|
||||
}));
|
||||
// The same structural checks the caller uses to select construction in the first
|
||||
// place. A nesting that leaves an unowned selection header or back edge has not
|
||||
// structured the function, so it is discarded rather than shipped.
|
||||
// A nesting is adopted only if it really is a well-formed construction. That is the
|
||||
// same question the caller asked to select construction in the first place, so it
|
||||
// is asked the same way, then extended to everything else a control-flow rewrite
|
||||
// owns: construct nesting, structured exits, and value flow.
|
||||
//
|
||||
// Value flow is checked for the same reason. Keeping ordinary values in registers
|
||||
// is only sound where the nesting really did preserve the paths that made their
|
||||
// definitions dominate their uses, and that does not always hold: an edge staged
|
||||
// through a construct's merge dispatch reaches its destination from that merge
|
||||
// rather than from the block it left. The state machine this pass replaces repaired
|
||||
// such a function incidentally, by demoting every crossing value; nesting keeps
|
||||
// them, so it has to prove the definitions still reach.
|
||||
// Value flow has to be checked because nesting keeps ordinary values in registers.
|
||||
// That is only sound where it preserved the paths that made their definitions
|
||||
// dominate their uses, and it does not always: an edge staged through a construct's
|
||||
// merge dispatch reaches its destination from that merge rather than from the block
|
||||
// it left. The state machine this pass replaces repaired such a function
|
||||
// incidentally, by demoting every crossing value; nesting keeps them, so it has to
|
||||
// prove the definitions still reach.
|
||||
let broken =
|
||||
super::rewrites::blocks_have_unowned_selection_header(&function.blocks)
|
||||
.then(|| "nesting left an unowned construct".to_string())
|
||||
@@ -89,7 +90,7 @@ pub(crate) fn structure_selected_functions(
|
||||
.then(|| "nesting left an unowned back edge".to_string())
|
||||
})
|
||||
.or_else(|| {
|
||||
super::owned_cfg::owned_function_value_flow_error(
|
||||
super::owned_cfg::owned_function_construction_error(
|
||||
function,
|
||||
&value_types,
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user