@@ -21,23 +21,6 @@ pub(crate) struct CodegenedFunction {
21
21
func_debug_cx : Option < FunctionDebugContext > ,
22
22
}
23
23
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
-
41
24
pub ( crate ) fn codegen_fn < ' tcx > (
42
25
tcx : TyCtxt < ' tcx > ,
43
26
cx : & mut crate :: CodegenCx ,
@@ -47,6 +30,9 @@ pub(crate) fn codegen_fn<'tcx>(
47
30
) -> CodegenedFunction {
48
31
debug_assert ! ( !instance. substs. needs_infer( ) ) ;
49
32
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
+
50
36
let mir = tcx. instance_mir ( instance. def ) ;
51
37
let _mir_guard = crate :: PrintOnPanic ( || {
52
38
let mut buf = Vec :: new ( ) ;
@@ -58,7 +44,6 @@ pub(crate) fn codegen_fn<'tcx>(
58
44
} ) ;
59
45
60
46
// Declare function
61
- let symbol_name = tcx. symbol_name ( instance) . name . to_string ( ) ;
62
47
let sig = get_function_sig ( tcx, module. target_config ( ) . default_call_conv , instance) ;
63
48
let func_id = module. declare_function ( & symbol_name, Linkage :: Local , & sig) . unwrap ( ) ;
64
49
@@ -112,7 +97,7 @@ pub(crate) fn codegen_fn<'tcx>(
112
97
next_ssa_var : 0 ,
113
98
} ;
114
99
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) ) ;
116
101
fx. bcx . seal_all_blocks ( ) ;
117
102
fx. bcx . finalize ( ) ;
118
103
@@ -146,6 +131,9 @@ pub(crate) fn compile_fn(
146
131
module : & mut dyn Module ,
147
132
codegened_func : CodegenedFunction ,
148
133
) {
134
+ let _timer =
135
+ cx. profiler . generic_activity_with_arg ( "compile function" , & * codegened_func. symbol_name ) ;
136
+
149
137
let clif_comments = codegened_func. clif_comments ;
150
138
151
139
// Store function in context
@@ -191,9 +179,30 @@ pub(crate) fn compile_fn(
191
179
} ;
192
180
193
181
// Define function
194
- cx. profiler . verbose_generic_activity ( "define function" ) . run ( || {
182
+ cx. profiler . generic_activity ( "define function" ) . run ( || {
195
183
context. want_disasm = cx. should_write_ir ;
196
184
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
+ }
197
206
} ) ;
198
207
199
208
if cx. should_write_ir {
@@ -220,7 +229,7 @@ pub(crate) fn compile_fn(
220
229
let isa = module. isa ( ) ;
221
230
let debug_context = & mut cx. debug_context ;
222
231
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 ( || {
224
233
if let Some ( debug_context) = debug_context {
225
234
codegened_func. func_debug_cx . unwrap ( ) . finalize (
226
235
debug_context,
@@ -237,7 +246,7 @@ pub(crate) fn verify_func(
237
246
writer : & crate :: pretty_clif:: CommentWriter ,
238
247
func : & Function ,
239
248
) {
240
- tcx. sess . time ( "verify clif ir" , || {
249
+ tcx. prof . generic_activity ( "verify clif ir" ) . run ( || {
241
250
let flags = cranelift_codegen:: settings:: Flags :: new ( cranelift_codegen:: settings:: builder ( ) ) ;
242
251
match cranelift_codegen:: verify_function ( & func, & flags) {
243
252
Ok ( _) => { }
@@ -273,7 +282,10 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
273
282
fx. bcx . ins ( ) . trap ( TrapCode :: UnreachableCodeReached ) ;
274
283
return ;
275
284
}
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) ) ;
277
289
278
290
for ( bb, bb_data) in fx. mir . basic_blocks . iter_enumerated ( ) {
279
291
let block = fx. get_block ( bb) ;
@@ -434,7 +446,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
434
446
cleanup : _,
435
447
from_hir_call : _,
436
448
} => {
437
- fx. tcx . sess . time ( "codegen call" , || {
449
+ fx. tcx . prof . generic_activity ( "codegen call" ) . run ( || {
438
450
crate :: abi:: codegen_terminator_call (
439
451
fx,
440
452
mir:: SourceInfo { span : * fn_span, ..source_info } ,
0 commit comments