@@ -21,23 +21,6 @@ pub(crate) struct CodegenedFunction {
2121 func_debug_cx : Option < FunctionDebugContext > ,
2222}
2323
24- #[ cfg_attr( not( feature = "jit" ) , allow( dead_code) ) ]
25- pub ( crate ) fn codegen_and_compile_fn < ' tcx > (
26- tcx : TyCtxt < ' tcx > ,
27- cx : & mut crate :: CodegenCx ,
28- cached_context : & mut Context ,
29- module : & mut dyn Module ,
30- instance : Instance < ' tcx > ,
31- ) {
32- let _inst_guard =
33- crate :: PrintOnPanic ( || format ! ( "{:?} {}" , instance, tcx. symbol_name( instance) . name) ) ;
34-
35- let cached_func = std:: mem:: replace ( & mut cached_context. func , Function :: new ( ) ) ;
36- let codegened_func = codegen_fn ( tcx, cx, cached_func, module, instance) ;
37-
38- compile_fn ( cx, cached_context, module, codegened_func) ;
39- }
40-
4124pub ( crate ) fn codegen_fn < ' tcx > (
4225 tcx : TyCtxt < ' tcx > ,
4326 cx : & mut crate :: CodegenCx ,
@@ -47,6 +30,9 @@ pub(crate) fn codegen_fn<'tcx>(
4730) -> CodegenedFunction {
4831 debug_assert ! ( !instance. substs. needs_infer( ) ) ;
4932
33+ let symbol_name = tcx. symbol_name ( instance) . name . to_string ( ) ;
34+ let _timer = tcx. prof . generic_activity_with_arg ( "codegen fn" , & * symbol_name) ;
35+
5036 let mir = tcx. instance_mir ( instance. def ) ;
5137 let _mir_guard = crate :: PrintOnPanic ( || {
5238 let mut buf = Vec :: new ( ) ;
@@ -58,7 +44,6 @@ pub(crate) fn codegen_fn<'tcx>(
5844 } ) ;
5945
6046 // Declare function
61- let symbol_name = tcx. symbol_name ( instance) . name . to_string ( ) ;
6247 let sig = get_function_sig ( tcx, module. target_config ( ) . default_call_conv , instance) ;
6348 let func_id = module. declare_function ( & symbol_name, Linkage :: Local , & sig) . unwrap ( ) ;
6449
@@ -112,7 +97,7 @@ pub(crate) fn codegen_fn<'tcx>(
11297 next_ssa_var : 0 ,
11398 } ;
11499
115- tcx. sess . time ( "codegen clif ir" , || codegen_fn_body ( & mut fx, start_block) ) ;
100+ tcx. prof . generic_activity ( "codegen clif ir" ) . run ( || codegen_fn_body ( & mut fx, start_block) ) ;
116101 fx. bcx . seal_all_blocks ( ) ;
117102 fx. bcx . finalize ( ) ;
118103
@@ -146,6 +131,9 @@ pub(crate) fn compile_fn(
146131 module : & mut dyn Module ,
147132 codegened_func : CodegenedFunction ,
148133) {
134+ let _timer =
135+ cx. profiler . generic_activity_with_arg ( "compile function" , & * codegened_func. symbol_name ) ;
136+
149137 let clif_comments = codegened_func. clif_comments ;
150138
151139 // Store function in context
@@ -191,9 +179,30 @@ pub(crate) fn compile_fn(
191179 } ;
192180
193181 // Define function
194- cx. profiler . verbose_generic_activity ( "define function" ) . run ( || {
182+ cx. profiler . generic_activity ( "define function" ) . run ( || {
195183 context. want_disasm = cx. should_write_ir ;
196184 module. define_function ( codegened_func. func_id , context) . unwrap ( ) ;
185+
186+ if cx. profiler . enabled ( ) {
187+ let mut recording_args = false ;
188+ cx. profiler
189+ . generic_activity_with_arg_recorder (
190+ "define function (clif pass timings)" ,
191+ |recorder| {
192+ let pass_times = cranelift_codegen:: timing:: take_current ( ) ;
193+ // Replace newlines with | as measureme doesn't allow control characters like
194+ // newlines inside strings.
195+ recorder. record_arg ( format ! ( "{}" , pass_times) . replace ( "\n " , " | " ) ) ;
196+ recording_args = true ;
197+ } ,
198+ )
199+ . run ( || {
200+ if recording_args {
201+ // Wait a tiny bit to ensure chrome's profiler doesn't hide the event
202+ std:: thread:: sleep ( std:: time:: Duration :: from_nanos ( 2 ) )
203+ }
204+ } ) ;
205+ }
197206 } ) ;
198207
199208 if cx. should_write_ir {
@@ -220,7 +229,7 @@ pub(crate) fn compile_fn(
220229 let isa = module. isa ( ) ;
221230 let debug_context = & mut cx. debug_context ;
222231 let unwind_context = & mut cx. unwind_context ;
223- cx. profiler . verbose_generic_activity ( "generate debug info" ) . run ( || {
232+ cx. profiler . generic_activity ( "generate debug info" ) . run ( || {
224233 if let Some ( debug_context) = debug_context {
225234 codegened_func. func_debug_cx . unwrap ( ) . finalize (
226235 debug_context,
@@ -237,7 +246,7 @@ pub(crate) fn verify_func(
237246 writer : & crate :: pretty_clif:: CommentWriter ,
238247 func : & Function ,
239248) {
240- tcx. sess . time ( "verify clif ir" , || {
249+ tcx. prof . generic_activity ( "verify clif ir" ) . run ( || {
241250 let flags = cranelift_codegen:: settings:: Flags :: new ( cranelift_codegen:: settings:: builder ( ) ) ;
242251 match cranelift_codegen:: verify_function ( & func, & flags) {
243252 Ok ( _) => { }
@@ -273,7 +282,10 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
273282 fx. bcx . ins ( ) . trap ( TrapCode :: UnreachableCodeReached ) ;
274283 return ;
275284 }
276- fx. tcx . sess . time ( "codegen prelude" , || crate :: abi:: codegen_fn_prelude ( fx, start_block) ) ;
285+ fx. tcx
286+ . prof
287+ . generic_activity ( "codegen prelude" )
288+ . run ( || crate :: abi:: codegen_fn_prelude ( fx, start_block) ) ;
277289
278290 for ( bb, bb_data) in fx. mir . basic_blocks . iter_enumerated ( ) {
279291 let block = fx. get_block ( bb) ;
@@ -434,7 +446,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
434446 cleanup : _,
435447 from_hir_call : _,
436448 } => {
437- fx. tcx . sess . time ( "codegen call" , || {
449+ fx. tcx . prof . generic_activity ( "codegen call" ) . run ( || {
438450 crate :: abi:: codegen_terminator_call (
439451 fx,
440452 mir:: SourceInfo { span : * fn_span, ..source_info } ,
0 commit comments