MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / compute_idom

Method compute_idom

cranelift/codegen/src/dominator_tree/simple.rs:309–328  ·  view source on GitHub ↗

Compute the immediate dominator for `block` using the current `idom` states for the reachable nodes.

(&self, block: Block, cfg: &ControlFlowGraph)

Source from the content-addressed store, hash-verified

307 // Compute the immediate dominator for `block` using the current `idom` states for the reachable
308 // nodes.
309 fn compute_idom(&self, block: Block, cfg: &ControlFlowGraph) -> Block {
310 // Get an iterator with just the reachable, already visited predecessors to `block`.
311 // Note that during the first pass, `rpo_number` is 1 for reachable blocks that haven't
312 // been visited yet, 0 for unreachable blocks.
313 let mut reachable_preds = cfg
314 .pred_iter(block)
315 .filter(|&BlockPredecessor { block: pred, .. }| self.nodes[pred].rpo_number > 1)
316 .map(|pred| pred.block);
317
318 // The RPO must visit at least one predecessor before this node.
319 let mut idom = reachable_preds
320 .next()
321 .expect("block node must have one reachable predecessor");
322
323 for pred in reachable_preds {
324 idom = self.common_dominator(idom, pred);
325 }
326
327 idom
328 }
329}
330
331#[cfg(test)]

Callers 1

compute_domtreeMethod · 0.80

Calls 5

pred_iterMethod · 0.80
common_dominatorMethod · 0.80
mapMethod · 0.45
expectMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected