Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,19 @@

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<bool>,
block_to_rpo: Vec<Option<u32>>,
backedge: Vec<u32>,
}

#[derive(Debug, Default)]
pub struct CFGInfo {
/// Postorder traversal of blocks.
pub postorder: Vec<Block>,
/// Domtree parents, indexed by block.
pub domtree: Vec<Block>,
/// For each instruction, the block it belongs to.
pub insn_block: Vec<Block>,
/// For each block, the first instruction.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -148,8 +136,4 @@ impl CFGInfo {

Ok(())
}

pub fn dominates(&self, a: Block, b: Block) -> bool {
domtree::dominates(&self.domtree[..], a, b)
}
}
14 changes: 12 additions & 2 deletions src/ssa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: Function>(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() {
Expand Down Expand Up @@ -66,7 +76,7 @@ pub fn validate_ssa<F: Function>(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());
Expand Down
Loading