Skip to content

Commit

Permalink
Merge 04c8395 into dd70845
Browse files Browse the repository at this point in the history
  • Loading branch information
aakoshh authored Jan 18, 2025
2 parents dd70845 + 04c8395 commit f4ffc76
Show file tree
Hide file tree
Showing 11 changed files with 458 additions and 182 deletions.
5 changes: 5 additions & 0 deletions compiler/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ pub struct CompileOptions {
#[arg(long)]
pub skip_brillig_constraints_check: bool,

/// Flag to turn off preprocessing functions during SSA passes.
#[arg(long)]
pub skip_preprocess_fns: bool,

/// Setting to decide on an inlining strategy for Brillig functions.
/// A more aggressive inliner should generate larger programs but more optimized
/// A less aggressive inliner should generate smaller programs
Expand Down Expand Up @@ -679,6 +683,7 @@ pub fn compile_no_check(
emit_ssa: if options.emit_ssa { Some(context.package_build_path.clone()) } else { None },
skip_underconstrained_check: options.skip_underconstrained_check,
skip_brillig_constraints_check: options.skip_brillig_constraints_check,
skip_preprocess_fns: options.skip_preprocess_fns,
inliner_aggressiveness: options.inliner_aggressiveness,
max_bytecode_increase_percent: options.max_bytecode_increase_percent,
};
Expand Down
18 changes: 15 additions & 3 deletions compiler/noirc_evaluator/src/ssa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ pub struct SsaEvaluatorOptions {
/// Skip the missing Brillig call constraints check
pub skip_brillig_constraints_check: bool,

/// Skip preprocessing functions.
pub skip_preprocess_fns: bool,

/// The higher the value, the more inlined Brillig functions will be.
pub inliner_aggressiveness: i64,

Expand Down Expand Up @@ -150,15 +153,24 @@ pub(crate) fn optimize_into_acir(
/// Run all SSA passes.
fn optimize_all(builder: SsaBuilder, options: &SsaEvaluatorOptions) -> Result<Ssa, RuntimeError> {
Ok(builder
.run_pass(Ssa::remove_unreachable_functions, "Removing Unreachable Functions")
.run_pass(Ssa::remove_unreachable_functions, "Removing Unreachable Functions (1st)")
.run_pass(Ssa::defunctionalize, "Defunctionalization")
.run_pass(Ssa::remove_paired_rc, "Removing Paired rc_inc & rc_decs")
.run_pass(
|ssa| {
if options.skip_preprocess_fns {
return ssa;
}
ssa.preprocess_functions(options.inliner_aggressiveness)
},
"Preprocessing Functions",
)
.run_pass(|ssa| ssa.inline_functions(options.inliner_aggressiveness), "Inlining (1st)")
// Run mem2reg with the CFG separated into blocks
.run_pass(Ssa::mem2reg, "Mem2Reg (1st)")
.run_pass(Ssa::simplify_cfg, "Simplifying (1st)")
.run_pass(Ssa::as_slice_optimization, "`as_slice` optimization")
.run_pass(Ssa::remove_unreachable_functions, "Removing Unreachable Functions")
.run_pass(Ssa::remove_unreachable_functions, "Removing Unreachable Functions (2nd)")
.try_run_pass(
Ssa::evaluate_static_assert_and_assert_constant,
"`static_assert` and `assert_constant`",
Expand Down Expand Up @@ -188,7 +200,7 @@ fn optimize_all(builder: SsaBuilder, options: &SsaEvaluatorOptions) -> Result<Ss
.run_pass(Ssa::fold_constants_using_constraints, "Constraint Folding")
.run_pass(Ssa::make_constrain_not_equal_instructions, "Adding constrain not equal")
.run_pass(Ssa::dead_instruction_elimination, "Dead Instruction Elimination (1st)")
.run_pass(Ssa::simplify_cfg, "Simplifying:")
.run_pass(Ssa::simplify_cfg, "Simplifying (3rd):")
.run_pass(Ssa::array_set_optimization, "Array Set Optimizations")
.finish())
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/noirc_evaluator/src/ssa/opt/defunctionalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ fn create_apply_function(
let mut function_builder = FunctionBuilder::new("apply".to_string(), id);
function_builder.set_globals(globals);

// We want to push for apply functions to be inlined more aggressively.
// We want to push for apply functions to be inlined more aggressively;
// they are expected to be optimized away by constants visible at the call site.
let runtime = match caller_runtime {
RuntimeType::Acir(_) => RuntimeType::Acir(InlineType::InlineAlways),
RuntimeType::Brillig(_) => RuntimeType::Brillig(InlineType::InlineAlways),
Expand Down
1 change: 1 addition & 0 deletions compiler/noirc_evaluator/src/ssa/opt/hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ mod tests {
emit_ssa: None,
skip_underconstrained_check: true,
skip_brillig_constraints_check: true,
skip_preprocess_fns: true,
inliner_aggressiveness: 0,
max_bytecode_increase_percent: None,
};
Expand Down
Loading

0 comments on commit f4ffc76

Please sign in to comment.