Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ssa): Unroll small loops in brillig #6505

Merged
merged 32 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5393a44
Extra comments
aakoshh Nov 12, 2024
43f1f25
Use SSA parser in unrolling tests
aakoshh Nov 12, 2024
9dbc2f8
Move functions under Loops and Loop where there is an obvious self
aakoshh Nov 12, 2024
2d14db5
Test getting numeric bounds
aakoshh Nov 12, 2024
49d92d2
Normalise during SSA parsing
aakoshh Nov 13, 2024
16c799e
Trim comments from expected SSA before comparing strings
aakoshh Nov 13, 2024
6e2468e
Collect references before the pre-header
aakoshh Nov 13, 2024
71cccc2
Fix parser test now that the expectation is a normalised SSA
aakoshh Nov 13, 2024
cc0c6c9
Count loads and stores
aakoshh Nov 13, 2024
a9c2c8e
Fix parser test now that the expectation is a normalised SSA
aakoshh Nov 13, 2024
944ae37
Count all instructions
aakoshh Nov 13, 2024
f41ec36
Add method to decide if a loop is small
aakoshh Nov 13, 2024
b35fa25
Unroll small Brillig loops
aakoshh Nov 13, 2024
7ffda95
Fix clippy
aakoshh Nov 13, 2024
4aed51a
Test stats, count duplicate increments
aakoshh Nov 13, 2024
d2adf53
Handle 0..1
aakoshh Nov 13, 2024
7cd33fe
No panic on break and continue
aakoshh Nov 13, 2024
e06f4b3
Merge remote-tracking branch 'origin/master' into 6470-brillig-unroll…
aakoshh Nov 13, 2024
030d794
Fix clippy
aakoshh Nov 13, 2024
7b0face
Remove leftover method after merge
aakoshh Nov 13, 2024
efd763c
Remove leftover const
aakoshh Nov 13, 2024
c78c07c
Merge branch 'master' into 6470-brillig-unroll-small-loops
aakoshh Nov 14, 2024
7cd6f3a
Be more conservative and only assume mem2reg can get rid of load+stor…
aakoshh Nov 14, 2024
a42c643
Merge branch '6470-brillig-unroll-small-loops' of github.com:noir-lan…
aakoshh Nov 14, 2024
176d0fc
Merge branch 'master' into 6470-brillig-unroll-small-loops
aakoshh Nov 18, 2024
4050a85
Fix comments, remove skip_ref_counts
aakoshh Nov 18, 2024
bc84d48
Compare agains original SSA source when testing that nothing is unrolled
aakoshh Nov 18, 2024
8845ca0
Rephrase comment
aakoshh Nov 18, 2024
e3f5a6c
Merge branch 'master' into 6470-brillig-unroll-small-loops
aakoshh Nov 18, 2024
4b481d3
Merge remote-tracking branch 'origin/master' into 6470-brillig-unroll…
aakoshh Nov 19, 2024
6a46f90
Merge branch '6470-brillig-unroll-small-loops' of github.com:noir-lan…
aakoshh Nov 19, 2024
ca32afe
Update SSA after make_array
aakoshh Nov 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions compiler/noirc_evaluator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,22 @@ pub(crate) fn trim_leading_whitespace_from_lines(src: &str) -> String {
}
result
}

/// Trim comments from the lines, ie. content starting with `//`.
#[cfg(test)]
pub(crate) fn trim_comments_from_lines(src: &str) -> String {
let mut result = String::new();
let mut first = true;
for line in src.lines() {
if !first {
result.push('\n');
}
if let Some(comment) = line.find("//") {
result.push_str(line[..comment].trim_end());
} else {
result.push_str(line);
}
first = false;
}
result
}
8 changes: 8 additions & 0 deletions compiler/noirc_evaluator/src/ssa/ir/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ impl RuntimeType {
| RuntimeType::Brillig(InlineType::NoPredicates)
)
}

pub(crate) fn is_brillig(&self) -> bool {
matches!(self, RuntimeType::Brillig(_))
}

pub(crate) fn is_acir(&self) -> bool {
matches!(self, RuntimeType::Acir(_))
}
}

/// A function holds a list of instructions.
Expand Down
1 change: 1 addition & 0 deletions compiler/noirc_evaluator/src/ssa/ir/function_inserter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
///
/// This is optional since caching arrays relies on the inserter inserting strictly
/// in control-flow order. Otherwise, if arrays later in the program are cached first,
/// they may be refered to by instructions earlier in the program.

Check warning on line 28 in compiler/noirc_evaluator/src/ssa/ir/function_inserter.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (refered)
array_cache: Option<ArrayCache>,

/// If this pass is loop unrolling, store the block before the loop to optionally
Expand Down Expand Up @@ -71,6 +71,7 @@
}
}

/// Get an instruction and make sure all the values in it are freshly resolved.
pub(crate) fn map_instruction(&mut self, id: InstructionId) -> (Instruction, CallStack) {
(
self.function.dfg[id].clone().map_values(|id| self.resolve(id)),
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_evaluator/src/ssa/ir/post_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl PostOrder {
}

impl PostOrder {
/// Allocate and compute a function's block post-order. Pos
/// Allocate and compute a function's block post-order.
pub(crate) fn with_function(func: &Function) -> Self {
PostOrder(Self::compute_post_order(func))
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/noirc_evaluator/src/ssa/opt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ pub(crate) fn assert_normalized_ssa_equals(mut ssa: super::Ssa, expected: &str)
panic!("`expected` argument of `assert_ssa_equals` is not valid SSA:\n{:?}", err);
}

use crate::{ssa::Ssa, trim_leading_whitespace_from_lines};
use crate::{ssa::Ssa, trim_comments_from_lines, trim_leading_whitespace_from_lines};

ssa.normalize_ids();

let ssa = ssa.to_string();
let ssa = trim_leading_whitespace_from_lines(&ssa);
let expected = trim_leading_whitespace_from_lines(expected);
let expected = trim_comments_from_lines(&expected);

if ssa != expected {
println!("Expected:\n~~~\n{expected}\n~~~\nGot:\n~~~\n{ssa}\n~~~");
Expand Down
Loading
Loading