@@ -62,11 +62,13 @@ fn prepare_lto(cgcx: &CodegenContext<LlvmCodegenBackend>,
6262 } ;
6363 let exported_symbols = cgcx. exported_symbols
6464 . as_ref ( ) . expect ( "needs exported symbols for LTO" ) ;
65- let mut symbol_white_list = exported_symbols[ & LOCAL_CRATE ]
66- . iter ( )
67- . filter_map ( symbol_filter)
68- . collect :: < Vec < CString > > ( ) ;
69- let _timer = cgcx. profile_activity ( "generate_symbol_white_list_for_thinlto" ) ;
65+ let mut symbol_white_list = {
66+ let _timer = cgcx. prof . generic_activity ( "LLVM_lto_generate_symbol_white_list" ) ;
67+ exported_symbols[ & LOCAL_CRATE ]
68+ . iter ( )
69+ . filter_map ( symbol_filter)
70+ . collect :: < Vec < CString > > ( )
71+ } ;
7072 info ! ( "{} symbols to preserve in this crate" , symbol_white_list. len( ) ) ;
7173
7274 // If we're performing LTO for the entire crate graph, then for each of our
@@ -95,14 +97,17 @@ fn prepare_lto(cgcx: &CodegenContext<LlvmCodegenBackend>,
9597 }
9698
9799 for & ( cnum, ref path) in cgcx. each_linked_rlib_for_lto . iter ( ) {
98- let _timer = cgcx. profile_activity ( format ! ( "load: {}" , path. display( ) ) ) ;
99100 let exported_symbols = cgcx. exported_symbols
100101 . as_ref ( ) . expect ( "needs exported symbols for LTO" ) ;
101- symbol_white_list. extend (
102- exported_symbols[ & cnum]
103- . iter ( )
104- . filter_map ( symbol_filter) ) ;
102+ {
103+ let _timer = cgcx. prof . generic_activity ( "LLVM_lto_generate_symbol_white_list" ) ;
104+ symbol_white_list. extend (
105+ exported_symbols[ & cnum]
106+ . iter ( )
107+ . filter_map ( symbol_filter) ) ;
108+ }
105109
110+ let _timer = cgcx. prof . generic_activity ( "LLVM_lto_load_upstream_bitcode" ) ;
106111 let archive = ArchiveRO :: open ( & path) . expect ( "wanted an rlib" ) ;
107112 let bytecodes = archive. iter ( ) . filter_map ( |child| {
108113 child. ok ( ) . and_then ( |c| c. name ( ) . map ( |name| ( name, c) ) )
@@ -189,6 +194,7 @@ fn fat_lto(cgcx: &CodegenContext<LlvmCodegenBackend>,
189194 symbol_white_list : & [ * const libc:: c_char ] )
190195 -> Result < LtoModuleCodegen < LlvmCodegenBackend > , FatalError >
191196{
197+ let _timer = cgcx. prof . generic_activity ( "LLVM_fat_lto_build_monolithic_module" ) ;
192198 info ! ( "going for a fat lto" ) ;
193199
194200 // Sort out all our lists of incoming modules into two lists.
@@ -287,6 +293,7 @@ fn fat_lto(cgcx: &CodegenContext<LlvmCodegenBackend>,
287293 // save and persist everything with the original module.
288294 let mut linker = Linker :: new ( llmod) ;
289295 for ( bc_decoded, name) in serialized_modules {
296+ let _timer = cgcx. prof . generic_activity ( "LLVM_fat_lto_link_module" ) ;
290297 info ! ( "linking {:?}" , name) ;
291298 time_ext ( cgcx. time_passes , None , & format ! ( "ll link {:?}" , name) , || {
292299 let data = bc_decoded. data ( ) ;
@@ -388,6 +395,7 @@ fn thin_lto(cgcx: &CodegenContext<LlvmCodegenBackend>,
388395 symbol_white_list : & [ * const libc:: c_char ] )
389396 -> Result < ( Vec < LtoModuleCodegen < LlvmCodegenBackend > > , Vec < WorkProduct > ) , FatalError >
390397{
398+ let _timer = cgcx. prof . generic_activity ( "LLVM_thin_lto_global_analysis" ) ;
391399 unsafe {
392400 info ! ( "going for that thin, thin LTO" ) ;
393401
@@ -601,16 +609,6 @@ impl ModuleBuffer {
601609 llvm:: LLVMRustModuleBufferCreate ( m)
602610 } )
603611 }
604-
605- pub fn parse < ' a > (
606- & self ,
607- name : & str ,
608- cx : & ' a llvm:: Context ,
609- handler : & Handler ,
610- ) -> Result < & ' a llvm:: Module , FatalError > {
611- let name = CString :: new ( name) . unwrap ( ) ;
612- parse_module ( cx, & name, self . data ( ) , handler)
613- }
614612}
615613
616614impl ModuleBufferMethods for ModuleBuffer {
@@ -723,7 +721,7 @@ pub unsafe fn optimize_thin_module(
723721 // Like with "fat" LTO, get some better optimizations if landing pads
724722 // are disabled by removing all landing pads.
725723 if cgcx. no_landing_pads {
726- let _timer = cgcx. profile_activity ( "LLVM_remove_landing_pads ") ;
724+ let _timer = cgcx. prof . generic_activity ( "LLVM_thin_lto_remove_landing_pads ") ;
727725 llvm:: LLVMRustMarkAllFunctionsNounwind ( llmod) ;
728726 save_temp_bitcode ( & cgcx, & module, "thin-lto-after-nounwind" ) ;
729727 }
@@ -736,26 +734,41 @@ pub unsafe fn optimize_thin_module(
736734 //
737735 // You can find some more comments about these functions in the LLVM
738736 // bindings we've got (currently `PassWrapper.cpp`)
739- if !llvm:: LLVMRustPrepareThinLTORename ( thin_module. shared . data . 0 , llmod) {
740- let msg = "failed to prepare thin LTO module" ;
741- return Err ( write:: llvm_err ( & diag_handler, msg) )
737+ {
738+ let _timer = cgcx. prof . generic_activity ( "LLVM_thin_lto_rename" ) ;
739+ if !llvm:: LLVMRustPrepareThinLTORename ( thin_module. shared . data . 0 , llmod) {
740+ let msg = "failed to prepare thin LTO module" ;
741+ return Err ( write:: llvm_err ( & diag_handler, msg) )
742+ }
743+ save_temp_bitcode ( cgcx, & module, "thin-lto-after-rename" ) ;
742744 }
743- save_temp_bitcode ( cgcx, & module, "thin-lto-after-rename" ) ;
744- if !llvm:: LLVMRustPrepareThinLTOResolveWeak ( thin_module. shared . data . 0 , llmod) {
745- let msg = "failed to prepare thin LTO module" ;
746- return Err ( write:: llvm_err ( & diag_handler, msg) )
745+
746+ {
747+ let _timer = cgcx. prof . generic_activity ( "LLVM_thin_lto_resolve_weak" ) ;
748+ if !llvm:: LLVMRustPrepareThinLTOResolveWeak ( thin_module. shared . data . 0 , llmod) {
749+ let msg = "failed to prepare thin LTO module" ;
750+ return Err ( write:: llvm_err ( & diag_handler, msg) )
751+ }
752+ save_temp_bitcode ( cgcx, & module, "thin-lto-after-resolve" ) ;
747753 }
748- save_temp_bitcode ( cgcx, & module, "thin-lto-after-resolve" ) ;
749- if !llvm:: LLVMRustPrepareThinLTOInternalize ( thin_module. shared . data . 0 , llmod) {
750- let msg = "failed to prepare thin LTO module" ;
751- return Err ( write:: llvm_err ( & diag_handler, msg) )
754+
755+ {
756+ let _timer = cgcx. prof . generic_activity ( "LLVM_thin_lto_internalize" ) ;
757+ if !llvm:: LLVMRustPrepareThinLTOInternalize ( thin_module. shared . data . 0 , llmod) {
758+ let msg = "failed to prepare thin LTO module" ;
759+ return Err ( write:: llvm_err ( & diag_handler, msg) )
760+ }
761+ save_temp_bitcode ( cgcx, & module, "thin-lto-after-internalize" ) ;
752762 }
753- save_temp_bitcode ( cgcx, & module, "thin-lto-after-internalize" ) ;
754- if !llvm:: LLVMRustPrepareThinLTOImport ( thin_module. shared . data . 0 , llmod) {
755- let msg = "failed to prepare thin LTO module" ;
756- return Err ( write:: llvm_err ( & diag_handler, msg) )
763+
764+ {
765+ let _timer = cgcx. prof . generic_activity ( "LLVM_thin_lto_import" ) ;
766+ if !llvm:: LLVMRustPrepareThinLTOImport ( thin_module. shared . data . 0 , llmod) {
767+ let msg = "failed to prepare thin LTO module" ;
768+ return Err ( write:: llvm_err ( & diag_handler, msg) )
769+ }
770+ save_temp_bitcode ( cgcx, & module, "thin-lto-after-import" ) ;
757771 }
758- save_temp_bitcode ( cgcx, & module, "thin-lto-after-import" ) ;
759772
760773 // Ok now this is a bit unfortunate. This is also something you won't
761774 // find upstream in LLVM's ThinLTO passes! This is a hack for now to
@@ -786,18 +799,24 @@ pub unsafe fn optimize_thin_module(
786799 // not too much) but for now at least gets LLVM to emit valid DWARF (or
787800 // so it appears). Hopefully we can remove this once upstream bugs are
788801 // fixed in LLVM.
789- llvm:: LLVMRustThinLTOPatchDICompileUnit ( llmod, cu1) ;
790- save_temp_bitcode ( cgcx, & module, "thin-lto-after-patch" ) ;
802+ {
803+ let _timer = cgcx. prof . generic_activity ( "LLVM_thin_lto_patch_debuginfo" ) ;
804+ llvm:: LLVMRustThinLTOPatchDICompileUnit ( llmod, cu1) ;
805+ save_temp_bitcode ( cgcx, & module, "thin-lto-after-patch" ) ;
806+ }
791807
792808 // Alright now that we've done everything related to the ThinLTO
793809 // analysis it's time to run some optimizations! Here we use the same
794810 // `run_pass_manager` as the "fat" LTO above except that we tell it to
795811 // populate a thin-specific pass manager, which presumably LLVM treats a
796812 // little differently.
797- info ! ( "running thin lto passes over {}" , module. name) ;
798- let config = cgcx. config ( module. kind ) ;
799- run_pass_manager ( cgcx, & module, config, true ) ;
800- save_temp_bitcode ( cgcx, & module, "thin-lto-after-pm" ) ;
813+ {
814+ let _timer = cgcx. prof . generic_activity ( "LLVM_thin_lto_optimize" ) ;
815+ info ! ( "running thin lto passes over {}" , module. name) ;
816+ let config = cgcx. config ( module. kind ) ;
817+ run_pass_manager ( cgcx, & module, config, true ) ;
818+ save_temp_bitcode ( cgcx, & module, "thin-lto-after-pm" ) ;
819+ }
801820 }
802821 Ok ( module)
803822}
0 commit comments