-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into tf/bring-back-constraint-cache
- Loading branch information
Showing
15 changed files
with
174 additions
and
1,090 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
compiler/noirc_evaluator/src/ssa/opt/bubble_up_constrains.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
Oops, something went wrong.