Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
7ec6d3a
some purity unit tests showing functionality
vezenovm Aug 8, 2025
61a07ba
new purity test call_to_function_value
vezenovm Aug 8, 2025
427437c
add todo note
vezenovm Aug 8, 2025
737085d
mem2reg: add a test for IfElse
asterite Aug 11, 2025
45c0151
cargo fmt
asterite Aug 11, 2025
5864723
Add two tests showing that block parameters are aliases of its arguments
asterite Aug 13, 2025
76a4f53
add a weight threshold at which we always inline
vezenovm Aug 13, 2025
7f58d98
Merge branch 'group-1-audit' into mv/inline-info-always-inline-weight…
vezenovm Aug 13, 2025
1d4a8bd
just check instruction weight don't incllude transitive weight of calls
vezenovm Aug 13, 2025
0c0a47d
Merge remote-tracking branch 'origin/mv/inline-info-always-inline-wei…
vezenovm Aug 13, 2025
01ebd4f
only inline simple funcs with one block, need a better estimate of we…
vezenovm Aug 13, 2025
acf7c25
t Merge branch 'master' into mv/inline-info-always-inline-weight-thre…
vezenovm Sep 4, 2025
e2fe420
diff cleanup
vezenovm Sep 4, 2025
d674d1e
experiment with explicitly only inlining small functions before prepr…
vezenovm Sep 4, 2025
8ea0d79
do not inline no_pred funcs when inlining simple functions
vezenovm Sep 4, 2025
c56b96a
fmt
TomAFrench Sep 5, 2025
6865f62
snapshots
TomAFrench Sep 5, 2025
7932272
take in weight threshold as compile time value
vezenovm Sep 5, 2025
7e779e3
clippy
vezenovm Sep 5, 2025
22ef95c
clippy and fmt
vezenovm Sep 5, 2025
9c0a330
last clippy and fmt
vezenovm Sep 5, 2025
3eb223f
merge conflicts w/ master
vezenovm Sep 5, 2025
55b6bf7
cleanup and snaps
vezenovm Sep 5, 2025
40ddee1
cleanup tests
vezenovm Sep 5, 2025
7ff212a
remove more unnecessary insturcitons
vezenovm Sep 5, 2025
c59ea26
use const MAX_INSTRUCTIONS=0 to test
vezenovm Sep 5, 2025
1d4e47d
resolve conflicts
vezenovm Sep 5, 2025
7f21b26
Merge branch 'master' into mv/inline-info-always-inline-weight-threshold
vezenovm Sep 8, 2025
0e1ff15
snaps
vezenovm Sep 8, 2025
8bfee25
Update test_programs/gates_report_brillig.sh
vezenovm Sep 8, 2025
f18fb48
bump timeout
vezenovm Sep 8, 2025
8419749
Merge branch 'master' into mv/inline-info-always-inline-weight-threshold
vezenovm Sep 9, 2025
b360114
snaps
vezenovm Sep 9, 2025
cbb2e4a
Merge branch 'master' into mv/inline-info-always-inline-weight-threshold
vezenovm Sep 9, 2025
6f86884
snaps again:
vezenovm Sep 9, 2025
817695b
remove bad unit test and add does_not_inline_function_with_multiple_i…
vezenovm Sep 9, 2025
720a446
bring back inline_functions_that_require_multiple_inlines
vezenovm Sep 9, 2025
4102485
merge conflicts w/master
vezenovm Sep 9, 2025
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
2 changes: 1 addition & 1 deletion .github/benchmark_projects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ projects:
path: noir-projects/noir-protocol-circuits/crates/rollup-base-private
num_runs: 5
timeout: 15
compilation-timeout: 20
compilation-timeout: 25
execution-timeout: 1
compilation-memory-limit: 1600
execution-memory-limit: 650
Expand Down
7 changes: 7 additions & 0 deletions compiler/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use noirc_errors::{CustomDiagnostic, DiagnosticKind};
use noirc_evaluator::brillig::BrilligOptions;
use noirc_evaluator::create_program;
use noirc_evaluator::errors::RuntimeError;
use noirc_evaluator::ssa::opt::inlining::MAX_INSTRUCTIONS;
use noirc_evaluator::ssa::{
SsaEvaluatorOptions, SsaLogging, SsaProgramArtifact, create_program_with_minimal_passes,
};
Expand Down Expand Up @@ -180,6 +181,11 @@ pub struct CompileOptions {
#[arg(long, hide = true, allow_hyphen_values = true, default_value_t = i64::MAX)]
pub inliner_aggressiveness: i64,

/// Setting to decide the maximum weight threshold at which we designate a function
/// as "small" and thus to always be inlined.
#[arg(long, hide = true, allow_hyphen_values = true, default_value_t = MAX_INSTRUCTIONS)]
pub small_function_max_instructions: usize,

/// Setting the maximum acceptable increase in Brillig bytecode size due to
/// unrolling small loops. When left empty, any change is accepted as long
/// as it required fewer SSA instructions.
Expand Down Expand Up @@ -249,6 +255,7 @@ impl CompileOptions {
skip_brillig_constraints_check: !self.silence_warnings
&& self.skip_brillig_constraints_check,
inliner_aggressiveness: self.inliner_aggressiveness,
small_function_max_instruction: self.small_function_max_instructions,
max_bytecode_increase_percent: self.max_bytecode_increase_percent,
skip_passes: self.skip_ssa_pass.clone(),
}
Expand Down
26 changes: 22 additions & 4 deletions compiler/noirc_evaluator/src/ssa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ mod checks;
pub mod function_builder;
pub mod interpreter;
pub mod ir;
pub(crate) mod opt;
pub mod opt;
pub mod parser;
pub mod ssa_gen;
pub(crate) mod validation;
Expand Down Expand Up @@ -90,6 +90,9 @@ pub struct SsaEvaluatorOptions {
/// The higher the value, the more inlined Brillig functions will be.
pub inliner_aggressiveness: i64,

//// The higher the value, the more Brillig functions will be set to always be inlined.
pub small_function_max_instruction: usize,

/// Maximum accepted percentage increase in the Brillig bytecode size after unrolling loops.
/// When `None` the size increase check is skipped altogether and any decrease in the SSA
/// instruction count is accepted.
Expand All @@ -112,11 +115,21 @@ pub fn primary_passes(options: &SsaEvaluatorOptions) -> Vec<SsaPass<'_>> {
SsaPass::new(Ssa::mem2reg, "Mem2Reg"),
SsaPass::new(Ssa::remove_paired_rc, "Removing Paired rc_inc & rc_decs"),
SsaPass::new_try(
move |ssa| ssa.preprocess_functions(options.inliner_aggressiveness),
move |ssa| {
ssa.preprocess_functions(
options.inliner_aggressiveness,
options.small_function_max_instruction,
)
},
"Preprocessing Functions",
),
SsaPass::new_try(
move |ssa| ssa.inline_functions(options.inliner_aggressiveness),
move |ssa| {
ssa.inline_functions(
options.inliner_aggressiveness,
options.small_function_max_instruction,
)
},
"Inlining",
),
// Run mem2reg with the CFG separated into blocks
Expand Down Expand Up @@ -151,7 +164,12 @@ pub fn primary_passes(options: &SsaEvaluatorOptions) -> Vec<SsaPass<'_>> {
// This pass must come immediately following `mem2reg` as the succeeding passes
// may create an SSA which inlining fails to handle.
SsaPass::new_try(
move |ssa| ssa.inline_functions_with_no_predicates(options.inliner_aggressiveness),
move |ssa| {
ssa.inline_functions_with_no_predicates(
options.inliner_aggressiveness,
options.small_function_max_instruction,
)
},
"Inlining",
),
SsaPass::new_try(Ssa::remove_if_else, "Remove IfElse"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ mod test {
SsaEvaluatorOptions,
function_builder::FunctionBuilder,
ir::{basic_block::BasicBlockId, cfg::ControlFlowGraph, map::Id, types::Type},
opt::flatten_cfg::branch_analysis::find_branch_ends,
opt::{flatten_cfg::branch_analysis::find_branch_ends, inlining::MAX_INSTRUCTIONS},
primary_passes,
ssa_gen::Ssa,
},
Expand Down Expand Up @@ -649,6 +649,7 @@ mod test {
skip_brillig_constraints_check: true,
enable_brillig_constraints_check_lookback: false,
inliner_aggressiveness: 0,
small_function_max_instruction: MAX_INSTRUCTIONS,
max_bytecode_increase_percent: None,
skip_passes: Vec::new(),
};
Expand Down
6 changes: 5 additions & 1 deletion compiler/noirc_evaluator/src/ssa/opt/hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ mod tests {
assert_ssa_snapshot,
brillig::BrilligOptions,
errors::RuntimeError,
ssa::{Ssa, SsaBuilder, SsaEvaluatorOptions, SsaLogging, primary_passes},
ssa::{
Ssa, SsaBuilder, SsaEvaluatorOptions, SsaLogging, opt::inlining::MAX_INSTRUCTIONS,
primary_passes,
},
};

fn run_all_passes(ssa: Ssa) -> Result<Ssa, RuntimeError> {
Expand All @@ -20,6 +23,7 @@ mod tests {
enable_brillig_constraints_check_lookback: false,
skip_brillig_constraints_check: true,
inliner_aggressiveness: 0,
small_function_max_instruction: MAX_INSTRUCTIONS,
max_bytecode_increase_percent: None,
skip_passes: Default::default(),
};
Expand Down
13 changes: 2 additions & 11 deletions compiler/noirc_evaluator/src/ssa/opt/inline_simple_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! Functions are still restricted to not be inlined if they are recursive or marked with no predicates.
//!
//! A simple function is defined as the following:
//! - Contains no more than [MAX_INSTRUCTIONS] instructions
//! - Contains no more than a specified [maximum][crate::ssa::opt::inlining::inline_info::MAX_INSTRUCTIONS] instructions
//! - The function only has a single block (e.g. no control flow or conditional branches)
//! - It is not marked with the [no predicates inline type][noirc_frontend::monomorphization::ast::InlineType::NoPredicates]

Expand All @@ -16,19 +16,10 @@ use crate::ssa::{
function::{Function, RuntimeType},
},
opt::brillig_entry_points::get_brillig_entry_points,
opt::inlining::inline_info::MAX_INSTRUCTIONS,
ssa_gen::Ssa,
};

/// The maximum number of instructions chosen below is an expert estimation of a "small" function
/// in our SSA IR. Generally, inlining small functions with no control flow should enable further optimizations
/// in the compiler while avoiding code size bloat.
///
/// For example, a common "simple" function is writing into a mutable reference.
/// When that function has no control flow, it generally means we can expect all loads and stores within the
/// function to be resolved upon inlining. Inlining this type of basic function both reduces the number of
/// loads/stores to be executed and enables the compiler to continue optimizing at the inline site.
const MAX_INSTRUCTIONS: usize = 10;

impl Ssa {
/// See the [`inline_simple_functions`][self] module for more information.
pub(crate) fn inline_simple_functions(mut self: Ssa) -> Result<Ssa, RuntimeError> {
Expand Down
Loading
Loading