diff --git a/avm-transpiler/src/opcodes.rs b/avm-transpiler/src/opcodes.rs index a33abd4855e..36bcd8b8268 100644 --- a/avm-transpiler/src/opcodes.rs +++ b/avm-transpiler/src/opcodes.rs @@ -1,7 +1,7 @@ /// All AVM opcodes /// Keep updated with TS, cpp, and docs protocol specs! #[allow(clippy::upper_case_acronyms, dead_code)] -#[derive(PartialEq, Copy, Clone, Debug)] +#[derive(PartialEq, Copy, Clone, Debug, Eq, Hash)] pub enum AvmOpcode { // Compute ADD, diff --git a/avm-transpiler/src/transpile_contract.rs b/avm-transpiler/src/transpile_contract.rs index e684a541d84..fff7ad27522 100644 --- a/avm-transpiler/src/transpile_contract.rs +++ b/avm-transpiler/src/transpile_contract.rs @@ -100,6 +100,7 @@ impl From for TranspiledContractArtifact { let acir_program = function.bytecode; let brillig_bytecode = extract_brillig_from_acir_program(&acir_program); let assert_messages = extract_static_assert_messages(&acir_program); + info!("Extracted Brillig program has {} instructions", brillig_bytecode.len()); // Map Brillig pcs to AVM pcs (index is Brillig PC, value is AVM PC) let brillig_pcs_to_avm_pcs = map_brillig_pcs_to_avm_pcs(brillig_bytecode); @@ -118,7 +119,7 @@ impl From for TranspiledContractArtifact { let _ = encoder.read_to_end(&mut compressed_avm_bytecode); log::info!( - "{}::{}: compressed {} to {} bytes ({}% reduction)", + "{}::{}: bytecode size of {} was compressed to {} ({}% reduction)", contract.name, function.name, avm_bytecode.len(), diff --git a/avm-transpiler/src/utils.rs b/avm-transpiler/src/utils.rs index 19f9468e15c..982a8479546 100644 --- a/avm-transpiler/src/utils.rs +++ b/avm-transpiler/src/utils.rs @@ -2,12 +2,13 @@ use fxhash::FxHashMap as HashMap; use acvm::acir::circuit::brillig::BrilligFunctionId; use acvm::FieldElement; -use log::debug; +use log::{debug, info, trace}; use acvm::acir::brillig::Opcode as BrilligOpcode; use acvm::acir::circuit::{AssertionPayload, Opcode, Program}; use crate::instructions::AvmInstruction; +use crate::opcodes::AvmOpcode; /// Extract the Brillig program from its `Program` wrapper. /// Noir entry point unconstrained functions are compiled to their own list contained @@ -67,16 +68,25 @@ pub fn extract_static_assert_messages(program: &Program) -> HashMa /// Print inputs, outputs, and instructions in a Brillig program pub fn dbg_print_brillig_program(brillig_bytecode: &[BrilligOpcode]) { - debug!("Printing Brillig program..."); + trace!("Printing Brillig program..."); for (i, instruction) in brillig_bytecode.iter().enumerate() { - debug!("\tPC:{0} {1:?}", i, instruction); + trace!("\tPC:{0} {1:?}", i, instruction); } } /// Print each instruction in an AVM program pub fn dbg_print_avm_program(avm_program: &[AvmInstruction]) { - debug!("Printing AVM program..."); + info!("Transpiled AVM program has {} instructions", avm_program.len()); + trace!("Printing AVM program..."); + let mut counts = std::collections::HashMap::::new(); for (i, instruction) in avm_program.iter().enumerate() { - debug!("\tPC:{0}: {1}", i, &instruction.to_string()); + trace!("\tPC:{0}: {1}", i, &instruction.to_string()); + *counts.entry(instruction.opcode).or_insert(0) += 1; + } + debug!("AVM opcode counts:"); + let mut sorted_counts: Vec<_> = counts.into_iter().collect(); + sorted_counts.sort_by_key(|(_, count)| -(*count as isize)); + for (opcode, count) in sorted_counts { + debug!("\t{0:?}: {1}", opcode, count); } }