@@ -7,48 +7,44 @@ use rustc_middle::ty::layout::FnAbiOf;
7
7
use rustc_middle:: ty:: print:: with_no_trimmed_paths;
8
8
use rustc_middle:: ty:: SymbolName ;
9
9
10
- use indexmap:: IndexSet ;
11
-
12
10
use crate :: constant:: ConstantCx ;
11
+ use crate :: debuginfo:: FunctionDebugContext ;
13
12
use crate :: prelude:: * ;
14
13
use crate :: pretty_clif:: CommentWriter ;
15
14
16
15
struct CodegenedFunction < ' tcx > {
17
- instance : Instance < ' tcx > ,
18
16
symbol_name : SymbolName < ' tcx > ,
19
17
func_id : FuncId ,
20
18
func : Function ,
21
19
clif_comments : CommentWriter ,
22
- source_info_set : IndexSet < SourceInfo > ,
23
- local_map : IndexVec < mir:: Local , CPlace < ' tcx > > ,
20
+ func_debug_cx : Option < FunctionDebugContext > ,
24
21
}
25
22
26
23
pub ( crate ) fn codegen_and_compile_fn < ' tcx > (
27
- cx : & mut crate :: CodegenCx < ' tcx > ,
24
+ tcx : TyCtxt < ' tcx > ,
25
+ cx : & mut crate :: CodegenCx ,
28
26
cached_context : & mut Context ,
29
27
module : & mut dyn Module ,
30
28
instance : Instance < ' tcx > ,
31
29
) {
32
- let tcx = cx. tcx ;
33
30
let _inst_guard =
34
31
crate :: PrintOnPanic ( || format ! ( "{:?} {}" , instance, tcx. symbol_name( instance) . name) ) ;
35
32
36
33
let cached_func = std:: mem:: replace ( & mut cached_context. func , Function :: new ( ) ) ;
37
- let codegened_func = codegen_fn ( cx, cached_func, module, instance) ;
34
+ let codegened_func = codegen_fn ( tcx , cx, cached_func, module, instance) ;
38
35
39
36
compile_fn ( cx, cached_context, module, codegened_func) ;
40
37
}
41
38
42
39
fn codegen_fn < ' tcx > (
43
- cx : & mut crate :: CodegenCx < ' tcx > ,
40
+ tcx : TyCtxt < ' tcx > ,
41
+ cx : & mut crate :: CodegenCx ,
44
42
cached_func : Function ,
45
43
module : & mut dyn Module ,
46
44
instance : Instance < ' tcx > ,
47
45
) -> CodegenedFunction < ' tcx > {
48
46
debug_assert ! ( !instance. substs. needs_infer( ) ) ;
49
47
50
- let tcx = cx. tcx ;
51
-
52
48
let mir = tcx. instance_mir ( instance. def ) ;
53
49
let _mir_guard = crate :: PrintOnPanic ( || {
54
50
let mut buf = Vec :: new ( ) ;
@@ -84,13 +80,20 @@ fn codegen_fn<'tcx>(
84
80
let pointer_type = target_config. pointer_type ( ) ;
85
81
let clif_comments = crate :: pretty_clif:: CommentWriter :: new ( tcx, instance) ;
86
82
83
+ let func_debug_cx = if let Some ( debug_context) = & mut cx. debug_context {
84
+ Some ( debug_context. define_function ( tcx, symbol_name. name , mir. span ) )
85
+ } else {
86
+ None
87
+ } ;
88
+
87
89
let mut fx = FunctionCx {
88
90
cx,
89
91
module,
90
92
tcx,
91
93
target_config,
92
94
pointer_type,
93
95
constants_cx : ConstantCx :: new ( ) ,
96
+ func_debug_cx,
94
97
95
98
instance,
96
99
symbol_name,
@@ -103,52 +106,42 @@ fn codegen_fn<'tcx>(
103
106
caller_location : None , // set by `codegen_fn_prelude`
104
107
105
108
clif_comments,
106
- source_info_set : indexmap :: IndexSet :: new ( ) ,
109
+ last_source_file : None ,
107
110
next_ssa_var : 0 ,
108
111
} ;
109
112
110
113
tcx. sess . time ( "codegen clif ir" , || codegen_fn_body ( & mut fx, start_block) ) ;
111
114
112
115
// Recover all necessary data from fx, before accessing func will prevent future access to it.
113
- let instance = fx. instance ;
114
116
let clif_comments = fx. clif_comments ;
115
- let source_info_set = fx. source_info_set ;
116
- let local_map = fx. local_map ;
117
+ let func_debug_cx = fx. func_debug_cx ;
117
118
118
119
fx. constants_cx . finalize ( fx. tcx , & mut * fx. module ) ;
119
120
120
- crate :: pretty_clif:: write_clif_file (
121
- tcx,
122
- "unopt" ,
123
- module. isa ( ) ,
124
- instance,
125
- & func,
126
- & clif_comments,
127
- ) ;
121
+ if cx. should_write_ir {
122
+ crate :: pretty_clif:: write_clif_file (
123
+ tcx. output_filenames ( ( ) ) ,
124
+ symbol_name. name ,
125
+ "unopt" ,
126
+ module. isa ( ) ,
127
+ & func,
128
+ & clif_comments,
129
+ ) ;
130
+ }
128
131
129
132
// Verify function
130
133
verify_func ( tcx, & clif_comments, & func) ;
131
134
132
- CodegenedFunction {
133
- instance,
134
- symbol_name,
135
- func_id,
136
- func,
137
- clif_comments,
138
- source_info_set,
139
- local_map,
140
- }
135
+ CodegenedFunction { symbol_name, func_id, func, clif_comments, func_debug_cx }
141
136
}
142
137
143
138
fn compile_fn < ' tcx > (
144
- cx : & mut crate :: CodegenCx < ' tcx > ,
139
+ cx : & mut crate :: CodegenCx ,
145
140
cached_context : & mut Context ,
146
141
module : & mut dyn Module ,
147
142
codegened_func : CodegenedFunction < ' tcx > ,
148
143
) {
149
- let tcx = cx. tcx ;
150
-
151
- let mut clif_comments = codegened_func. clif_comments ;
144
+ let clif_comments = codegened_func. clif_comments ;
152
145
153
146
// Store function in context
154
147
let context = cached_context;
@@ -165,17 +158,6 @@ fn compile_fn<'tcx>(
165
158
// invalidate it when it would change.
166
159
context. domtree . clear ( ) ;
167
160
168
- // Perform rust specific optimizations
169
- tcx. sess . time ( "optimize clif ir" , || {
170
- crate :: optimize:: optimize_function (
171
- tcx,
172
- module. isa ( ) ,
173
- codegened_func. instance ,
174
- context,
175
- & mut clif_comments,
176
- ) ;
177
- } ) ;
178
-
179
161
#[ cfg( any( ) ) ] // This is never true
180
162
let _clif_guard = {
181
163
use std:: fmt:: Write ;
@@ -204,43 +186,41 @@ fn compile_fn<'tcx>(
204
186
} ;
205
187
206
188
// Define function
207
- tcx . sess . time ( "define function" , || {
208
- context. want_disasm = crate :: pretty_clif :: should_write_ir ( tcx ) ;
189
+ cx . profiler . verbose_generic_activity ( "define function" ) . run ( || {
190
+ context. want_disasm = cx . should_write_ir ;
209
191
module. define_function ( codegened_func. func_id , context) . unwrap ( ) ;
210
192
} ) ;
211
193
212
- // Write optimized function to file for debugging
213
- crate :: pretty_clif:: write_clif_file (
214
- tcx,
215
- "opt" ,
216
- module. isa ( ) ,
217
- codegened_func. instance ,
218
- & context. func ,
219
- & clif_comments,
220
- ) ;
194
+ if cx. should_write_ir {
195
+ // Write optimized function to file for debugging
196
+ crate :: pretty_clif:: write_clif_file (
197
+ & cx. output_filenames ,
198
+ codegened_func. symbol_name . name ,
199
+ "opt" ,
200
+ module. isa ( ) ,
201
+ & context. func ,
202
+ & clif_comments,
203
+ ) ;
221
204
222
- if let Some ( disasm) = & context. mach_compile_result . as_ref ( ) . unwrap ( ) . disasm {
223
- crate :: pretty_clif:: write_ir_file (
224
- tcx,
225
- || format ! ( "{}.vcode" , tcx. symbol_name( codegened_func. instance) . name) ,
226
- |file| file. write_all ( disasm. as_bytes ( ) ) ,
227
- )
205
+ if let Some ( disasm) = & context. mach_compile_result . as_ref ( ) . unwrap ( ) . disasm {
206
+ crate :: pretty_clif:: write_ir_file (
207
+ & cx. output_filenames ,
208
+ & format ! ( "{}.vcode" , codegened_func. symbol_name. name) ,
209
+ |file| file. write_all ( disasm. as_bytes ( ) ) ,
210
+ )
211
+ }
228
212
}
229
213
230
214
// Define debuginfo for function
231
215
let isa = module. isa ( ) ;
232
216
let debug_context = & mut cx. debug_context ;
233
217
let unwind_context = & mut cx. unwind_context ;
234
- tcx . sess . time ( "generate debug info" , || {
218
+ cx . profiler . verbose_generic_activity ( "generate debug info" ) . run ( || {
235
219
if let Some ( debug_context) = debug_context {
236
- debug_context . define_function (
237
- codegened_func . instance ,
220
+ codegened_func . func_debug_cx . unwrap ( ) . finalize (
221
+ debug_context ,
238
222
codegened_func. func_id ,
239
- codegened_func. symbol_name . name ,
240
- isa,
241
223
context,
242
- & codegened_func. source_info_set ,
243
- codegened_func. local_map ,
244
224
) ;
245
225
}
246
226
unwind_context. add_function ( codegened_func. func_id , & context, isa) ;
0 commit comments