@@ -20,6 +20,7 @@ use rustc_codegen_ssa::back::write::{
2020} ;
2121use rustc_codegen_ssa:: traits:: * ;
2222use rustc_codegen_ssa:: { CompiledModule , ModuleCodegen } ;
23+ use rustc_data_structures:: fx:: FxHashMap ;
2324use rustc_data_structures:: profiling:: SelfProfilerRef ;
2425use rustc_data_structures:: small_c_str:: SmallCStr ;
2526use rustc_errors:: { FatalError , Handler , Level } ;
@@ -568,10 +569,8 @@ pub(crate) unsafe fn codegen(
568569 let llcx = & * module. module_llvm . llcx ;
569570 let tm = & * module. module_llvm . tm ;
570571 let module_name = module. name . clone ( ) ;
571- let count = unsafe { llvm:: LLVMRustModuleInstructionStats ( & llmod) } ;
572- println ! ( "llvm-module: {module_name} = {count}" ) ;
573572 let module_name = Some ( & module_name[ ..] ) ;
574- let handlers = DiagnosticHandlers :: new ( cgcx, diag_handler, llcx) ;
573+ let _handlers = DiagnosticHandlers :: new ( cgcx, diag_handler, llcx) ;
575574
576575 if cgcx. msvc_imps_needed {
577576 create_msvc_imps ( cgcx, llcx, llmod) ;
@@ -763,7 +762,7 @@ pub(crate) unsafe fn codegen(
763762 EmitObj :: None => { }
764763 }
765764
766- drop ( handlers ) ;
765+ record_llvm_cgu_instructions_stats ( & cgcx . prof , llmod ) ;
767766 }
768767
769768 // `.dwo` files are only emitted if:
@@ -976,3 +975,23 @@ fn record_artifact_size(
976975 self_profiler_ref. artifact_size ( artifact_kind, artifact_name. to_string_lossy ( ) , file_size) ;
977976 }
978977}
978+
979+ fn record_llvm_cgu_instructions_stats ( prof : & SelfProfilerRef , llmod : & llvm:: Module ) {
980+ if !prof. enabled ( ) {
981+ return ;
982+ }
983+
984+ let raw_stats =
985+ llvm:: build_string ( |s| unsafe { llvm:: LLVMRustModuleInstructionStats ( & llmod, s) } )
986+ . expect ( "cannot get module instruction stats" ) ;
987+ #[ derive( serde:: Deserialize ) ]
988+ struct InstructionsStats {
989+ module : String ,
990+ _functions : FxHashMap < String , u64 > ,
991+ total : u64 ,
992+ }
993+
994+ let InstructionsStats { module, total, .. } =
995+ serde_json:: from_str ( & raw_stats) . expect ( "cannot parse llvm cgu instructions stats" ) ;
996+ prof. artifact_size ( "cgu_instructions" , module, total) ;
997+ }
0 commit comments