Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion compiler/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ pub fn compile_no_check(
let force_compile = force_compile
|| options.print_acir
|| options.show_brillig
|| options.force_brillig
|| options.show_ssa
|| options.emit_ssa;

Expand All @@ -578,7 +579,7 @@ pub fn compile_no_check(
emit_ssa: if options.emit_ssa { Some(context.package_build_path.clone()) } else { None },
};

let SsaProgramArtifact { program, debug, warnings, names, error_types, .. } =
let SsaProgramArtifact { program, debug, warnings, names, brillig_names, error_types, .. } =
create_program(program, &ssa_evaluator_options)?;

let abi = abi_gen::gen_abi(context, &main_function, return_visibility, error_types);
Expand All @@ -593,5 +594,6 @@ pub fn compile_no_check(
noir_version: NOIR_ARTIFACT_VERSION_STRING.to_string(),
warnings,
names,
brillig_names,
})
}
2 changes: 2 additions & 0 deletions compiler/noirc_driver/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ pub struct CompiledProgram {
pub warnings: Vec<SsaReport>,
/// Names of the functions in the program. These are used for more informative debugging and benchmarking.
pub names: Vec<String>,
/// Names of the unconstrained functions in the program.
pub brillig_names: Vec<String>,
Comment thread
jfecher marked this conversation as resolved.
}
4 changes: 3 additions & 1 deletion compiler/noirc_evaluator/src/brillig/brillig_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ pub(crate) fn convert_ssa_function(
BrilligBlock::compile(&mut function_context, &mut brillig_context, block, &func.dfg);
}

brillig_context.artifact()
let mut artifact = brillig_context.artifact();
artifact.name = func.name().to_string();
artifact
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub(crate) fn directive_invert<F: AcirField>() -> GeneratedBrillig<F> {
],
assert_messages: Default::default(),
locations: Default::default(),
name: "directive_invert".to_string(),
}
}

Expand Down Expand Up @@ -109,5 +110,6 @@ pub(crate) fn directive_quotient<F: AcirField>() -> GeneratedBrillig<F> {
],
assert_messages: Default::default(),
locations: Default::default(),
name: "directive_integer_quotient".to_string(),
}
}
4 changes: 4 additions & 0 deletions compiler/noirc_evaluator/src/brillig/brillig_ir/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub(crate) struct GeneratedBrillig<F> {
pub(crate) byte_code: Vec<BrilligOpcode<F>>,
pub(crate) locations: BTreeMap<OpcodeLocation, CallStack>,
pub(crate) assert_messages: BTreeMap<OpcodeLocation, String>,
pub(crate) name: String,
}

#[derive(Default, Debug, Clone)]
Expand Down Expand Up @@ -49,6 +50,8 @@ pub(crate) struct BrilligArtifact<F> {
locations: BTreeMap<OpcodeLocation, CallStack>,
/// The current call stack. All opcodes that are pushed will be associated with this call stack.
call_stack: CallStack,
/// Name of the function, only used for debugging purposes.
pub(crate) name: String,
}

/// A pointer to a location in the opcode.
Expand Down Expand Up @@ -81,6 +84,7 @@ impl<F: Clone + std::fmt::Debug> BrilligArtifact<F> {
byte_code: self.byte_code,
locations: self.locations,
assert_messages: self.assert_messages,
name: self.name,
}
}

Expand Down
9 changes: 7 additions & 2 deletions compiler/noirc_evaluator/src/ssa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ pub struct SsaProgramArtifact {
pub main_input_witnesses: Vec<Witness>,
pub main_return_witnesses: Vec<Witness>,
pub names: Vec<String>,
pub brillig_names: Vec<String>,
pub error_types: BTreeMap<ErrorSelector, HirType>,
}

Expand All @@ -167,6 +168,7 @@ impl SsaProgramArtifact {
main_input_witnesses: Vec::default(),
main_return_witnesses: Vec::default(),
names: Vec::default(),
brillig_names: Vec::default(),
error_types,
}
}
Expand Down Expand Up @@ -202,8 +204,10 @@ pub fn create_program(
let func_sigs = program.function_signatures.clone();

let recursive = program.recursive;
let ArtifactsAndWarnings((generated_acirs, generated_brillig, error_types), ssa_level_warnings) =
optimize_into_acir(program, options)?;
let ArtifactsAndWarnings(
(generated_acirs, generated_brillig, brillig_function_names, error_types),
ssa_level_warnings,
) = optimize_into_acir(program, options)?;
if options.force_brillig_output {
assert_eq!(
generated_acirs.len(),
Expand Down Expand Up @@ -236,6 +240,7 @@ pub fn create_program(
program_artifact.add_circuit(circuit_artifact, is_main);
is_main = false;
}
program_artifact.brillig_names = brillig_function_names;

Ok(program_artifact)
}
Expand Down
27 changes: 16 additions & 11 deletions compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ impl AcirValue {
pub(crate) type Artifacts = (
Vec<GeneratedAcir<FieldElement>>,
Vec<BrilligBytecode<FieldElement>>,
Vec<String>,
BTreeMap<ErrorSelector, ErrorType>,
);

Expand Down Expand Up @@ -334,11 +335,13 @@ impl Ssa {
}
}

let brillig = vecmap(shared_context.generated_brillig, |brillig| BrilligBytecode {
bytecode: brillig.byte_code,
});
let (brillig_bytecode, brillig_names) = shared_context
.generated_brillig
.into_iter()
.map(|brillig| (BrilligBytecode { bytecode: brillig.byte_code }, brillig.name))
.unzip();

Ok((acirs, brillig, self.error_selector_to_type))
Ok((acirs, brillig_bytecode, brillig_names, self.error_selector_to_type))
}
}

Expand Down Expand Up @@ -955,6 +958,8 @@ impl<'a> Context<'a> {
BrilligFunctionContext::return_values(func),
BrilligFunctionContext::function_id_to_function_label(func.id()),
);
entry_point.name = func.name().to_string();

// Link the entry point with all dependencies
while let Some(unresolved_fn_label) = entry_point.first_unresolved_function_call() {
let artifact = &brillig.find_by_function_label(unresolved_fn_label.clone());
Expand Down Expand Up @@ -2966,7 +2971,7 @@ mod test {

let ssa = builder.finish();

let (acir_functions, _, _) = ssa
let (acir_functions, _, _, _) = ssa
.into_acir(&Brillig::default(), ExpressionWidth::default())
.expect("Should compile manually written SSA into ACIR");
// Expected result:
Expand Down Expand Up @@ -3061,7 +3066,7 @@ mod test {

let ssa = builder.finish();

let (acir_functions, _, _) = ssa
let (acir_functions, _, _, _) = ssa
.into_acir(&Brillig::default(), ExpressionWidth::default())
.expect("Should compile manually written SSA into ACIR");
// The expected result should look very similar to the above test expect that the input witnesses of the `Call`
Expand Down Expand Up @@ -3151,7 +3156,7 @@ mod test {

let ssa = builder.finish();

let (acir_functions, _, _) = ssa
let (acir_functions, _, _, _) = ssa
.into_acir(&Brillig::default(), ExpressionWidth::default())
.expect("Should compile manually written SSA into ACIR");

Expand Down Expand Up @@ -3265,7 +3270,7 @@ mod test {
let ssa = builder.finish();
let brillig = ssa.to_brillig(false);

let (acir_functions, brillig_functions, _) = ssa
let (acir_functions, brillig_functions, _, _) = ssa
.into_acir(&brillig, ExpressionWidth::default())
.expect("Should compile manually written SSA into ACIR");

Expand Down Expand Up @@ -3329,7 +3334,7 @@ mod test {

// The Brillig bytecode we insert for the stdlib is hardcoded so we do not need to provide any
// Brillig artifacts to the ACIR gen pass.
let (acir_functions, brillig_functions, _) = ssa
let (acir_functions, brillig_functions, _, _) = ssa
.into_acir(&Brillig::default(), ExpressionWidth::default())
.expect("Should compile manually written SSA into ACIR");

Expand Down Expand Up @@ -3403,7 +3408,7 @@ mod test {
let brillig = ssa.to_brillig(false);
println!("{}", ssa);

let (acir_functions, brillig_functions, _) = ssa
let (acir_functions, brillig_functions, _, _) = ssa
.into_acir(&brillig, ExpressionWidth::default())
.expect("Should compile manually written SSA into ACIR");

Expand Down Expand Up @@ -3491,7 +3496,7 @@ mod test {
let brillig = ssa.to_brillig(false);
println!("{}", ssa);

let (acir_functions, brillig_functions, _) = ssa
let (acir_functions, brillig_functions, _, _) = ssa
.into_acir(&brillig, ExpressionWidth::default())
.expect("Should compile manually written SSA into ACIR");

Expand Down
48 changes: 43 additions & 5 deletions tooling/nargo_cli/src/cli/info_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ pub(crate) fn run(args: InfoCommand, config: NargoConfig) -> Result<(), CliError
} else {
// Otherwise print human-readable table.
if !info_report.programs.is_empty() {
let mut program_table =
table!([Fm->"Package", Fm->"Function", Fm->"Expression Width", Fm->"ACIR Opcodes"]);
let mut program_table = table!([Fm->"Package", Fm->"Function", Fm->"Expression Width", Fm->"ACIR Opcodes", Fm->"Brillig Opcodes"]);

for program_info in info_report.programs {
let program_rows: Vec<Row> = program_info.into();
Expand Down Expand Up @@ -176,18 +175,31 @@ struct ProgramInfo {
#[serde(skip)]
expression_width: ExpressionWidth,
functions: Vec<FunctionInfo>,
unconstrained_functions_opcodes: usize,
unconstrained_functions: Vec<FunctionInfo>,
}

impl From<ProgramInfo> for Vec<Row> {
fn from(program_info: ProgramInfo) -> Self {
vecmap(program_info.functions, |function| {
let mut main = vecmap(program_info.functions, |function| {
row![
Fm->format!("{}", program_info.package_name),
Fc->format!("{}", function.name),
format!("{:?}", program_info.expression_width),
Fc->format!("{}", function.acir_opcodes),
Fc->format!("{}", program_info.unconstrained_functions_opcodes),
]
})
});
main.extend(vecmap(program_info.unconstrained_functions, |function| {
row![
Fm->format!("{}", program_info.package_name),
Fc->format!("{}", function.name),
format!("N/A", ),
Fc->format!("N/A"),
Fc->format!("{}", function.acir_opcodes),
]
}));
main
}
}

Expand Down Expand Up @@ -235,5 +247,31 @@ fn count_opcodes_and_gates_in_program(
})
.collect();

ProgramInfo { package_name: package.name.to_string(), expression_width, functions }
let opcodes_len: Vec<usize> = compiled_program
.bytecode
.unconstrained_functions
.iter()
.map(|func| func.bytecode.len())
.collect();
let unconstrained_functions_opcodes = compiled_program
.bytecode
.unconstrained_functions
.into_par_iter()
.map(|function| function.bytecode.len())
.sum();
let unconstrained_info: Vec<FunctionInfo> = compiled_program
.brillig_names
.clone()
.iter()
.zip(opcodes_len)
.map(|(name, len)| FunctionInfo { name: name.clone(), acir_opcodes: len })
.collect();

ProgramInfo {
package_name: package.name.to_string(),
expression_width,
functions,
unconstrained_functions_opcodes,
unconstrained_functions: unconstrained_info,
}
}
4 changes: 4 additions & 0 deletions tooling/noirc_artifacts/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub struct ProgramArtifact {
pub file_map: BTreeMap<FileId, DebugFile>,

pub names: Vec<String>,
/// Names of the unconstrained functions in the program.
pub brillig_names: Vec<String>,
}

impl From<CompiledProgram> for ProgramArtifact {
Expand All @@ -49,6 +51,7 @@ impl From<CompiledProgram> for ProgramArtifact {
debug_symbols: ProgramDebugInfo { debug_infos: compiled_program.debug },
file_map: compiled_program.file_map,
names: compiled_program.names,
brillig_names: compiled_program.brillig_names,
}
}
}
Expand All @@ -64,6 +67,7 @@ impl From<ProgramArtifact> for CompiledProgram {
file_map: program.file_map,
warnings: vec![],
names: program.names,
brillig_names: program.brillig_names,
}
}
}
1 change: 1 addition & 0 deletions tooling/profiler/src/cli/gates_flamegraph_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ mod tests {
debug_symbols: ProgramDebugInfo { debug_infos: vec![DebugInfo::default()] },
file_map: BTreeMap::default(),
names: vec!["main".to_string()],
brillig_names: Vec::new(),
};

// Write the artifact to a file
Expand Down
2 changes: 2 additions & 0 deletions tooling/profiler/src/cli/opcodes_flamegraph_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ mod tests {
debug_symbols: ProgramDebugInfo { debug_infos: vec![DebugInfo::default()] },
file_map: BTreeMap::default(),
names: vec!["main".to_string()],
brillig_names: Vec::new(),
};

// Write the artifact to a file
Expand Down Expand Up @@ -228,6 +229,7 @@ mod tests {
debug_symbols: ProgramDebugInfo { debug_infos: vec![DebugInfo::default()] },
file_map: BTreeMap::default(),
names: vec!["main".to_string()],
brillig_names: vec!["main".to_string()],
};

// Write the artifact to a file
Expand Down