@@ -62,11 +62,13 @@ fn prepare_lto(cgcx: &CodegenContext<LlvmCodegenBackend>,
62
62
} ;
63
63
let exported_symbols = cgcx. exported_symbols
64
64
. 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
+ } ;
70
72
info ! ( "{} symbols to preserve in this crate" , symbol_white_list. len( ) ) ;
71
73
72
74
// 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>,
95
97
}
96
98
97
99
for & ( cnum, ref path) in cgcx. each_linked_rlib_for_lto . iter ( ) {
98
- let _timer = cgcx. profile_activity ( format ! ( "load: {}" , path. display( ) ) ) ;
99
100
let exported_symbols = cgcx. exported_symbols
100
101
. 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
+ }
105
109
110
+ let _timer = cgcx. prof . generic_activity ( "LLVM_lto_load_upstream_bitcode" ) ;
106
111
let archive = ArchiveRO :: open ( & path) . expect ( "wanted an rlib" ) ;
107
112
let bytecodes = archive. iter ( ) . filter_map ( |child| {
108
113
child. ok ( ) . and_then ( |c| c. name ( ) . map ( |name| ( name, c) ) )
@@ -189,6 +194,7 @@ fn fat_lto(cgcx: &CodegenContext<LlvmCodegenBackend>,
189
194
symbol_white_list : & [ * const libc:: c_char ] )
190
195
-> Result < LtoModuleCodegen < LlvmCodegenBackend > , FatalError >
191
196
{
197
+ let _timer = cgcx. prof . generic_activity ( "LLVM_fat_lto_build_monolithic_module" ) ;
192
198
info ! ( "going for a fat lto" ) ;
193
199
194
200
// Sort out all our lists of incoming modules into two lists.
@@ -287,6 +293,7 @@ fn fat_lto(cgcx: &CodegenContext<LlvmCodegenBackend>,
287
293
// save and persist everything with the original module.
288
294
let mut linker = Linker :: new ( llmod) ;
289
295
for ( bc_decoded, name) in serialized_modules {
296
+ let _timer = cgcx. prof . generic_activity ( "LLVM_fat_lto_link_module" ) ;
290
297
info ! ( "linking {:?}" , name) ;
291
298
time_ext ( cgcx. time_passes , None , & format ! ( "ll link {:?}" , name) , || {
292
299
let data = bc_decoded. data ( ) ;
@@ -388,6 +395,7 @@ fn thin_lto(cgcx: &CodegenContext<LlvmCodegenBackend>,
388
395
symbol_white_list : & [ * const libc:: c_char ] )
389
396
-> Result < ( Vec < LtoModuleCodegen < LlvmCodegenBackend > > , Vec < WorkProduct > ) , FatalError >
390
397
{
398
+ let _timer = cgcx. prof . generic_activity ( "LLVM_thin_lto_global_analysis" ) ;
391
399
unsafe {
392
400
info ! ( "going for that thin, thin LTO" ) ;
393
401
@@ -601,16 +609,6 @@ impl ModuleBuffer {
601
609
llvm:: LLVMRustModuleBufferCreate ( m)
602
610
} )
603
611
}
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
- }
614
612
}
615
613
616
614
impl ModuleBufferMethods for ModuleBuffer {
@@ -723,7 +721,7 @@ pub unsafe fn optimize_thin_module(
723
721
// Like with "fat" LTO, get some better optimizations if landing pads
724
722
// are disabled by removing all landing pads.
725
723
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 ") ;
727
725
llvm:: LLVMRustMarkAllFunctionsNounwind ( llmod) ;
728
726
save_temp_bitcode ( & cgcx, & module, "thin-lto-after-nounwind" ) ;
729
727
}
@@ -736,26 +734,41 @@ pub unsafe fn optimize_thin_module(
736
734
//
737
735
// You can find some more comments about these functions in the LLVM
738
736
// 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" ) ;
742
744
}
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" ) ;
747
753
}
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" ) ;
752
762
}
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" ) ;
757
771
}
758
- save_temp_bitcode ( cgcx, & module, "thin-lto-after-import" ) ;
759
772
760
773
// Ok now this is a bit unfortunate. This is also something you won't
761
774
// find upstream in LLVM's ThinLTO passes! This is a hack for now to
@@ -786,18 +799,24 @@ pub unsafe fn optimize_thin_module(
786
799
// not too much) but for now at least gets LLVM to emit valid DWARF (or
787
800
// so it appears). Hopefully we can remove this once upstream bugs are
788
801
// 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
+ }
791
807
792
808
// Alright now that we've done everything related to the ThinLTO
793
809
// analysis it's time to run some optimizations! Here we use the same
794
810
// `run_pass_manager` as the "fat" LTO above except that we tell it to
795
811
// populate a thin-specific pass manager, which presumably LLVM treats a
796
812
// 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
+ }
801
820
}
802
821
Ok ( module)
803
822
}
0 commit comments