Skip to content

Commit

Permalink
fix(ssa refactor): safe to query cfg for single block programs (#1401)
Browse files Browse the repository at this point in the history
* fix(ssa refactor): safe to query cfg for single block programs

* chore(ssa refactor): fix comment wording
  • Loading branch information
joss-aztec committed May 25, 2023
1 parent 809aa3a commit e2a23b3
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion crates/noirc_evaluator/src/ssa_refactor/ir/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ pub(crate) struct ControlFlowGraph {
impl ControlFlowGraph {
/// Allocate and compute the control flow graph for `func`.
pub(crate) fn with_function(func: &Function) -> Self {
let mut cfg = ControlFlowGraph { data: HashMap::new() };
// It is expected to be safe to query the control flow graph for any reachable block,
// therefore we must ensure that a node exists for the entry block, regardless of whether
// it later comes to describe any edges after calling compute.
let entry_block = func.entry_block();
let empty_node = CfgNode { predecessors: HashSet::new(), successors: HashSet::new() };
let data = HashMap::from([(entry_block, empty_node)]);

let mut cfg = ControlFlowGraph { data };
cfg.compute(func);
cfg
}
Expand Down

0 comments on commit e2a23b3

Please sign in to comment.