diff --git a/src/executor/contract.rs b/src/executor/contract.rs index 65c81e86f..0d8cce648 100644 --- a/src/executor/contract.rs +++ b/src/executor/contract.rs @@ -215,7 +215,9 @@ impl AotContractExecutor { // Compile the Sierra program. let NativeModule { - module, registry, .. + module, + registry, + metadata, } = context.compile( program, true, @@ -310,6 +312,7 @@ impl AotContractExecutor { GenStatement::Return(_) => continue, } } + stats.sierra_declared_types_freq = metadata.types_frequencies(); } // Generate mappings between the entry point's selectors and their function indexes. diff --git a/src/metadata.rs b/src/metadata.rs index e33656b0c..b57ed2a61 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -9,9 +9,10 @@ //! - Pass extra compilation info to the libfunc generators (ex. //! [TailRecursionMeta](self::tail_recursion)). +use cairo_lang_sierra::ids::ConcreteTypeId; use std::{ any::{Any, TypeId}, - collections::{hash_map::Entry, HashMap}, + collections::{hash_map::Entry, BTreeMap, HashMap}, }; pub mod auto_breakpoint; @@ -32,6 +33,8 @@ pub mod trace_dump; #[derive(Debug)] pub struct MetadataStorage { entries: HashMap>, + /// Number of times each declared type is built + types_freqs: BTreeMap, } impl MetadataStorage { @@ -110,6 +113,14 @@ impl MetadataStorage { .downcast_mut::() .expect("the given type does not match the actual") } + + pub fn increment_frequency(&mut self, type_id: &ConcreteTypeId) { + *self.types_freqs.entry(type_id.id).or_insert(0) += 1; + } + + pub fn types_frequencies(&self) -> BTreeMap { + self.types_freqs.clone() + } } #[cfg(feature = "with-debug-utils")] @@ -117,6 +128,7 @@ impl Default for MetadataStorage { fn default() -> Self { let mut metadata = Self { entries: Default::default(), + types_freqs: Default::default(), }; metadata.insert(debug_utils::DebugUtils::default()); diff --git a/src/statistics.rs b/src/statistics.rs index eb04ffbf5..e75e0035e 100644 --- a/src/statistics.rs +++ b/src/statistics.rs @@ -22,6 +22,8 @@ pub struct Statistics { pub sierra_func_stats: BTreeMap, /// Number of statements for each distinct libfunc. pub sierra_libfunc_frequency: BTreeMap, + /// Number of times a Sierra declared type was built + pub sierra_declared_types_freq: BTreeMap, /// Number of times each circuit gate is used. pub sierra_circuit_gates_count: CircuitGatesStats, /// Number of MLIR operations generated. diff --git a/src/types.rs b/src/types.rs index 6a942b737..ed5e2411d 100644 --- a/src/types.rs +++ b/src/types.rs @@ -160,6 +160,7 @@ impl TypeBuilder for CoreTypeConcrete { metadata: &mut MetadataStorage, self_ty: &ConcreteTypeId, ) -> Result, Self::Error> { + metadata.increment_frequency(self_ty); match self { Self::Array(info) => self::array::build( context,