Skip to content

Commit

Permalink
feat(ssa refactor): experimental-ssa compiler flag (#1289)
Browse files Browse the repository at this point in the history
* feat(ssa refactor): experimental-ssa compiler flag

* move experimental method into ssa_refactor

* check the experimental flag in the driver module

* undo changes to `create_circuit`

---------

Co-authored-by: Kevaundray Wedderburn <[email protected]>
  • Loading branch information
joss-aztec and kevaundray authored May 4, 2023
1 parent b6e606b commit afa6749
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
7 changes: 6 additions & 1 deletion crates/nargo_cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ pub fn start_cli() -> eyre::Result<()> {

// helper function which tests noir programs by trying to generate a proof and verify it
pub fn prove_and_verify(proof_name: &str, program_dir: &Path, show_ssa: bool) -> bool {
let compile_options = CompileOptions { show_ssa, allow_warnings: false, show_output: false };
let compile_options = CompileOptions {
show_ssa,
allow_warnings: false,
show_output: false,
experimental_ssa: false,
};
let proof_dir = program_dir.join(PROOFS_DIR);

match prove_cmd::prove_with_path(
Expand Down
34 changes: 25 additions & 9 deletions crates/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use fm::FileType;
use iter_extended::try_vecmap;
use noirc_abi::FunctionSignature;
use noirc_errors::{reporter, ReportedError};
use noirc_evaluator::create_circuit;
use noirc_evaluator::{create_circuit, ssa_refactor::experimental_create_circuit};
use noirc_frontend::graph::{CrateId, CrateName, CrateType, LOCAL_CRATE};
use noirc_frontend::hir::def_map::{Contract, CrateDefMap};
use noirc_frontend::hir::Context;
Expand Down Expand Up @@ -43,11 +43,15 @@ pub struct CompileOptions {
/// Display output of `println` statements
#[arg(long)]
pub show_output: bool,

/// Compile and optimize using the new experimental SSA pass
#[arg(long)]
pub experimental_ssa: bool,
}

impl Default for CompileOptions {
fn default() -> Self {
Self { show_ssa: false, allow_warnings: false, show_output: true }
Self { show_ssa: false, allow_warnings: false, show_output: true, experimental_ssa: false }
}
}

Expand Down Expand Up @@ -254,13 +258,25 @@ impl Driver {
let np_language = self.language.clone();
let is_opcode_supported = acvm::default_is_opcode_supported(np_language.clone());

match create_circuit(
program,
np_language,
is_opcode_supported,
options.show_ssa,
options.show_output,
) {
let circuit_abi = if options.experimental_ssa {
experimental_create_circuit(
program,
np_language,
is_opcode_supported,
options.show_ssa,
options.show_output,
)
} else {
create_circuit(
program,
np_language,
is_opcode_supported,
options.show_ssa,
options.show_output,
)
};

match circuit_abi {
Ok((circuit, abi)) => Ok(CompiledProgram { circuit, abi }),
Err(err) => {
// The FileId here will be the file id of the file with the main file
Expand Down
16 changes: 16 additions & 0 deletions crates/noirc_evaluator/src/ssa_refactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
//! This module heavily borrows from Cranelift
#![allow(dead_code)]

use crate::errors::RuntimeError;
use acvm::{acir::circuit::Circuit, compiler::transformers::IsOpcodeSupported, Language};
use noirc_abi::Abi;

use noirc_frontend::monomorphization::ast::Program;

use self::acir_gen::Acir;
Expand All @@ -22,3 +26,15 @@ pub mod ssa_gen;
pub fn optimize_into_acir(program: Program) -> Acir {
ssa_gen::generate_ssa(program).into_acir()
}
/// Compiles the Program into ACIR and applies optimizations to the arithmetic gates
/// This is analogous to `ssa:create_circuit` and this method is called when one wants
/// to use the new ssa module to process Noir code.
pub fn experimental_create_circuit(
_program: Program,
_np_language: Language,
_is_opcode_supported: IsOpcodeSupported,
_enable_logging: bool,
_show_output: bool,
) -> Result<(Circuit, Abi), RuntimeError> {
todo!("this is a stub function for the new SSA refactor module")
}

0 comments on commit afa6749

Please sign in to comment.