Skip to content

Commit

Permalink
chore: run two rounds of backpropagation
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Jan 26, 2024
1 parent e6a3a9f commit f8006bb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
9 changes: 9 additions & 0 deletions acvm-repo/acir/src/circuit/directives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,12 @@ pub enum Directive {
sort_by: Vec<u32>, // specify primary index to sort by, then the secondary,... For instance, if tuple is 2 and sort_by is [1,0], then a=[(a0,b0),..] is sorted by bi and then ai.
},
}

impl Directive {
pub fn get_outputs_vec(&self) -> Vec<Witness> {
match self {
Directive::ToLeRadix { b, .. } => b.to_owned(),
Directive::PermutationSort { bits, .. } => bits.to_owned(),
}
}
}
14 changes: 11 additions & 3 deletions acvm-repo/acvm/src/compiler/optimizers/constant_backpropagation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,17 @@ impl ConstantBackpropOptimizer {
}
};

match solve_directives(&mut known_witnesses, &directive) {
Ok(()) => continue,
Err(_) => Opcode::Directive(directive),
if directive
.get_outputs_vec()
.iter()
.all(|output| known_witnesses.contains_key(output))
{
continue;
} else {
match solve_directives(&mut known_witnesses, &directive) {
Ok(()) => continue,
Err(_) => Opcode::Directive(directive),
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions acvm-repo/acvm/src/compiler/optimizers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ pub(super) fn optimize_internal(acir: Circuit) -> (Circuit, Vec<usize>) {
let (acir, acir_opcode_positions) =
range_optimizer.replace_redundant_ranges(acir_opcode_positions);

let (acir, acir_opcode_positions) =
ConstantBackpropOptimizer::backpropagate_constants(acir, acir_opcode_positions);

info!("Number of opcodes after: {}", acir.opcodes.len());

(acir, acir_opcode_positions)
Expand Down

0 comments on commit f8006bb

Please sign in to comment.