Skip to content

Commit

Permalink
Merge branch 'master' into tf/bring-back-constraint-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench authored Jan 17, 2024
2 parents ef2273c + 66f5cdd commit 10b7f20
Show file tree
Hide file tree
Showing 15 changed files with 174 additions and 1,090 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs-dead-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WORKFLOW_NAME: ${{ github.workflow }}
WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/job/${{ github.job }}
WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
with:
update_existing: true
filename: .github/DEAD_LINKS_IN_DOCS.md
14 changes: 5 additions & 9 deletions compiler/noirc_evaluator/src/ssa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub(crate) fn optimize_into_acir(

let ssa_gen_span = span!(Level::TRACE, "ssa_generation");
let ssa_gen_span_guard = ssa_gen_span.enter();
let ssa_builder = SsaBuilder::new(program, print_ssa_passes)?
let ssa = SsaBuilder::new(program, print_ssa_passes)?
.run_pass(Ssa::defunctionalize, "After Defunctionalization:")
.run_pass(Ssa::inline_functions, "After Inlining:")
// Run mem2reg with the CFG separated into blocks
Expand All @@ -62,16 +62,12 @@ pub(crate) fn optimize_into_acir(
// Run mem2reg once more with the flattened CFG to catch any remaining loads/stores
.run_pass(Ssa::mem2reg, "After Mem2Reg:")
.run_pass(Ssa::fold_constants, "After Constant Folding:")
.run_pass(Ssa::dead_instruction_elimination, "After Dead Instruction Elimination:");
.run_pass(Ssa::dead_instruction_elimination, "After Dead Instruction Elimination:")
.run_pass(Ssa::bubble_up_constrains, "After Constraint Bubbling:")
.finish();

let brillig = ssa_builder.to_brillig(print_brillig_trace);
let brillig = ssa.to_brillig(print_brillig_trace);

// Split off any passes the are not necessary for Brillig generation but are necessary for ACIR generation.
// We only need to fill out nested slices as we need to have a known length when dealing with memory operations
// in ACIR gen while this is not necessary in the Brillig IR.
let ssa = ssa_builder
.run_pass(Ssa::fill_internal_slices, "After Fill Internal Slice Dummy Data:")
.finish();
drop(ssa_gen_span_guard);

let last_array_uses = ssa.find_last_array_uses();
Expand Down
353 changes: 57 additions & 296 deletions compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion compiler/noirc_evaluator/src/ssa/ir/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl Type {
}

pub(crate) fn is_nested_slice(&self) -> bool {
if let Type::Slice(element_types) = self {
if let Type::Slice(element_types) | Type::Array(element_types, _) = self {
element_types.as_ref().iter().any(|typ| typ.contains_slice_element())
} else {
false
Expand Down
43 changes: 43 additions & 0 deletions compiler/noirc_evaluator/src/ssa/opt/bubble_up_constrains.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use crate::ssa::{ir::instruction::Instruction, ssa_gen::Ssa};

impl Ssa {
/// A simple SSA pass to go through each instruction and move every `Instruction::Constrain` to immediately
/// after when all of its inputs are available.
#[tracing::instrument(level = "trace", skip(self))]
pub(crate) fn bubble_up_constrains(mut self) -> Ssa {
for function in self.functions.values_mut() {
for block in function.reachable_blocks() {
let instructions = function.dfg[block].take_instructions();
let mut filtered_instructions = Vec::with_capacity(instructions.len());

let dfg = &function.dfg;
for instruction in instructions {
let (lhs, rhs) = match dfg[instruction] {
Instruction::Constrain(lhs, rhs, ..) => (lhs, rhs),
_ => {
filtered_instructions.push(instruction);
continue;
}
};

let index = filtered_instructions
.iter()
.rev()
.position(|instruction_id| {
let results = dfg.instruction_results(*instruction_id).to_vec();
results.contains(&lhs) || results.contains(&rhs)
})
// We iterate through the previous instructions in reverse order so the index is from the
// back of the vector. Subtract from vector length to get correct index.
.map(|reversed_index| filtered_instructions.len() - reversed_index)
.unwrap_or(filtered_instructions.len());

filtered_instructions.insert(index, instruction);
}

*function.dfg[block].instructions_mut() = filtered_instructions;
}
}
self
}
}
Loading

0 comments on commit 10b7f20

Please sign in to comment.