@@ -20,6 +20,7 @@ use rustc_codegen_ssa::back::write::{
20
20
} ;
21
21
use rustc_codegen_ssa:: traits:: * ;
22
22
use rustc_codegen_ssa:: { CompiledModule , ModuleCodegen } ;
23
+ use rustc_data_structures:: fx:: FxHashMap ;
23
24
use rustc_data_structures:: profiling:: SelfProfilerRef ;
24
25
use rustc_data_structures:: small_c_str:: SmallCStr ;
25
26
use rustc_errors:: { FatalError , Handler , Level } ;
@@ -568,10 +569,8 @@ pub(crate) unsafe fn codegen(
568
569
let llcx = & * module. module_llvm . llcx ;
569
570
let tm = & * module. module_llvm . tm ;
570
571
let module_name = module. name . clone ( ) ;
571
- let count = unsafe { llvm:: LLVMRustModuleInstructionStats ( & llmod) } ;
572
- println ! ( "llvm-module: {module_name} = {count}" ) ;
573
572
let module_name = Some ( & module_name[ ..] ) ;
574
- let handlers = DiagnosticHandlers :: new ( cgcx, diag_handler, llcx) ;
573
+ let _handlers = DiagnosticHandlers :: new ( cgcx, diag_handler, llcx) ;
575
574
576
575
if cgcx. msvc_imps_needed {
577
576
create_msvc_imps ( cgcx, llcx, llmod) ;
@@ -763,7 +762,7 @@ pub(crate) unsafe fn codegen(
763
762
EmitObj :: None => { }
764
763
}
765
764
766
- drop ( handlers ) ;
765
+ record_llvm_cgu_instructions_stats ( & cgcx . prof , llmod ) ;
767
766
}
768
767
769
768
// `.dwo` files are only emitted if:
@@ -976,3 +975,23 @@ fn record_artifact_size(
976
975
self_profiler_ref. artifact_size ( artifact_kind, artifact_name. to_string_lossy ( ) , file_size) ;
977
976
}
978
977
}
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