Skip to content

Commit

Permalink
Use BTreeMap to store block IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
aakoshh committed Nov 27, 2024
1 parent 7b28c59 commit e17a570
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions compiler/noirc_evaluator/src/ssa/opt/constant_folding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ pub(crate) struct BrilligInfo<'a> {
/// For more information see [`ConstraintSimplificationCache`].
#[derive(Default)]
struct SimplificationCache {
simplifications: HashMap<BasicBlockId, ValueId>,
/// Simplified expressions where we found them.
/// Using a `BTreeMap` for deterministic enumeration.
simplifications: BTreeMap<BasicBlockId, ValueId>,
}

impl SimplificationCache {
Expand All @@ -221,7 +223,9 @@ impl SimplificationCache {
return Some(*value);
}
// Check if there is a dominating block we can take a simplification from.
for (constraining_block, value) in self.simplifications.iter() {
// Going backwards so that we find a constraint closest to what we have already processed
// (assuming block IDs of blocks further down in the SSA are larger).
for (constraining_block, value) in self.simplifications.iter().rev() {
if dom.dominates(*constraining_block, block) {
return Some(*value);
}
Expand Down

0 comments on commit e17a570

Please sign in to comment.