From b9e89885c41f88909bec8a66e1020921d22b90a2 Mon Sep 17 00:00:00 2001 From: Chris Fallin Date: Sat, 8 May 2021 21:48:58 -0700 Subject: [PATCH] Error checking: properly signal a crit-edge requirement failure (used for regalloc.rs fuzzer) --- src/cfg.rs | 20 ++++++++------------ src/ion/mod.rs | 2 +- src/lib.rs | 2 ++ 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/cfg.rs b/src/cfg.rs index 31853f0..f73ca1a 100644 --- a/src/cfg.rs +++ b/src/cfg.rs @@ -5,7 +5,7 @@ //! Lightweight CFG analyses. -use crate::{domtree, postorder, Block, Function, Inst, OperandKind, ProgPoint}; +use crate::{domtree, postorder, Block, Function, Inst, OperandKind, ProgPoint, RegAllocError}; #[derive(Clone, Debug)] pub struct CFGInfo { @@ -37,7 +37,7 @@ pub struct CFGInfo { } impl CFGInfo { - pub fn new(f: &F) -> CFGInfo { + pub fn new(f: &F) -> Result { let postorder = postorder::calculate(f.blocks(), f.entry_block(), |block| f.block_succs(block)); let domtree = domtree::calculate( @@ -74,20 +74,16 @@ impl CFGInfo { if f.block_preds(block).len() > 1 { for (i, &pred) in f.block_preds(block).iter().enumerate() { - // Assert critical edge condition. - assert_eq!( - f.block_succs(pred).len(), - 1, - "Edge {} -> {} is critical", - pred.index(), - block.index(), - ); + // Check critical edge condition. + if f.block_succs(pred).len() > 1 { + return Err(RegAllocError::CritEdge(pred, block)); + } pred_pos[pred.index()] = i; } } } - CFGInfo { + Ok(CFGInfo { postorder, domtree, insn_block, @@ -96,7 +92,7 @@ impl CFGInfo { block_entry, block_exit, pred_pos, - } + }) } pub fn dominates(&self, a: Block, b: Block) -> bool { diff --git a/src/ion/mod.rs b/src/ion/mod.rs index 08ebf32..9d9c3c2 100644 --- a/src/ion/mod.rs +++ b/src/ion/mod.rs @@ -4445,7 +4445,7 @@ impl<'a, F: Function> Env<'a, F> { } pub fn run(func: &F, mach_env: &MachineEnv) -> Result { - let cfginfo = CFGInfo::new(func); + let cfginfo = CFGInfo::new(func)?; let mut env = Env::new(func, mach_env, cfginfo); env.init()?; diff --git a/src/lib.rs b/src/lib.rs index 3dfc41f..6827939 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -958,6 +958,8 @@ impl Output { /// An error that prevents allocation. #[derive(Clone, Debug)] pub enum RegAllocError { + /// Critical edge is not split between given blocks. + CritEdge(Block, Block), /// Invalid SSA for given vreg at given inst: multiple defs or /// illegal use. `inst` may be `Inst::invalid()` if this concerns /// a block param.