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

Method compute_spanning_tree

cranelift/codegen/src/dominator_tree.rs:382–427  ·  view source on GitHub ↗

Reset all internal data structures, build spanning tree and compute a post-order of the control flow graph.

(&mut self, func: &Function)

Source from the content-addressed store, hash-verified

380 /// Reset all internal data structures, build spanning tree
381 /// and compute a post-order of the control flow graph.
382 fn compute_spanning_tree(&mut self, func: &Function) {
383 self.nodes.resize(func.dfg.num_blocks());
384 self.stree.reserve(func.dfg.num_blocks());
385
386 if let Some(block) = func.layout.entry_block() {
387 self.dfs_worklist.push(TraversalEvent::Enter(0, block));
388 }
389
390 loop {
391 match self.dfs_worklist.pop() {
392 Some(TraversalEvent::Enter(parent, block)) => {
393 let node = &mut self.nodes[block];
394 if node.pre_number != NOT_VISITED {
395 continue;
396 }
397
398 self.dfs_worklist.push(TraversalEvent::Exit(block));
399
400 let pre_number = self.stree.push(parent, block);
401 node.pre_number = pre_number;
402
403 // Use the same traversal heuristics as in traversals.rs.
404 self.dfs_worklist.extend(
405 func.block_successors(block)
406 // Heuristic: chase the children in reverse. This puts
407 // the first successor block first in the postorder, all
408 // other things being equal, which tends to prioritize
409 // loop backedges over out-edges, putting the edge-block
410 // closer to the loop body and minimizing live-ranges in
411 // linear instruction space. This heuristic doesn't have
412 // any effect on the computation of dominators, and is
413 // purely for other consumers of the postorder we cache
414 // here.
415 .rev()
416 // A simple optimization: push less items to the stack.
417 .filter(|successor| self.nodes[*successor].pre_number == NOT_VISITED)
418 .map(|successor| TraversalEvent::Enter(pre_number, successor)),
419 );
420 }
421 Some(TraversalEvent::Exit(block)) => {
422 self.postorder.push(block);
423 }
424 None => break,
425 }
426 }
427 }
428
429 /// Eval-link procedure from the paper.
430 /// For a predecessor V of node W returns V if V < W, otherwise the minimum of sdom(U),

Callers 1

computeMethod · 0.80

Calls 10

ExitEnum · 0.85
block_successorsMethod · 0.80
resizeMethod · 0.45
num_blocksMethod · 0.45
reserveMethod · 0.45
entry_blockMethod · 0.45
pushMethod · 0.45
popMethod · 0.45
extendMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected