diff --git a/src/cfg.rs b/src/cfg.rs index 5b125f71..499ab835 100644 --- a/src/cfg.rs +++ b/src/cfg.rs @@ -7,13 +7,12 @@ use crate::alloc::vec::Vec; -use crate::{domtree, postorder, Block, Function, Inst, ProgPoint, RegAllocError, VecExt}; +use crate::{postorder, Block, Function, Inst, ProgPoint, RegAllocError, VecExt}; use smallvec::{smallvec, SmallVec}; #[derive(Debug, Default)] pub struct CFGInfoCtx { visited: Vec, - block_to_rpo: Vec>, backedge: Vec, } @@ -21,8 +20,6 @@ pub struct CFGInfoCtx { pub struct CFGInfo { /// Postorder traversal of blocks. pub postorder: Vec, - /// Domtree parents, indexed by block. - pub domtree: Vec, /// For each instruction, the block it belongs to. pub insn_block: Vec, /// For each block, the first instruction. @@ -58,15 +55,6 @@ impl CFGInfo { |block| f.block_succs(block), )?; - domtree::calculate( - nb, - |block| f.block_preds(block), - &self.postorder, - &mut ctx.block_to_rpo, - &mut self.domtree, - f.entry_block(), - ); - let insn_block = self.insn_block.repopulate(f.num_insts(), Block::invalid()); let block_entry = self .block_entry @@ -148,8 +136,4 @@ impl CFGInfo { Ok(()) } - - pub fn dominates(&self, a: Block, b: Block) -> bool { - domtree::dominates(&self.domtree[..], a, b) - } } diff --git a/src/ssa.rs b/src/ssa.rs index 29a82cfe..23a788d6 100644 --- a/src/ssa.rs +++ b/src/ssa.rs @@ -8,9 +8,19 @@ use alloc::vec; use crate::cfg::CFGInfo; -use crate::{Block, Function, FxHashSet, Inst, OperandKind, RegAllocError, VReg}; +use crate::{domtree, Block, Function, FxHashSet, Inst, OperandKind, RegAllocError, VReg}; pub fn validate_ssa(f: &F, cfginfo: &CFGInfo) -> Result<(), RegAllocError> { + let mut idom = vec![]; + domtree::calculate( + f.num_blocks(), + |block| f.block_preds(block), + &cfginfo.postorder, + &mut vec![], + &mut idom, + f.entry_block(), + ); + // For every block param and inst def, check that this is the only def. let mut defined_in = vec![Block::invalid(); f.num_vregs()]; for block in 0..f.num_blocks() { @@ -66,7 +76,7 @@ pub fn validate_ssa(f: &F, cfginfo: &CFGInfo) -> Result<(), RegAllo && if def_block == block { local.contains(&operand.vreg()) } else { - cfginfo.dominates(def_block, block) + domtree::dominates(&idom, def_block, block) }; if !okay { trace!("Invalid use {:?}", operand.vreg());