@@ -5,24 +5,47 @@ use rustc_index::vec::IndexVec;
5
5
use rustc_middle:: ty:: adjustment:: PointerCast ;
6
6
use rustc_middle:: ty:: layout:: FnAbiOf ;
7
7
use rustc_middle:: ty:: print:: with_no_trimmed_paths;
8
+ use rustc_middle:: ty:: SymbolName ;
8
9
9
10
use indexmap:: IndexSet ;
10
11
11
12
use crate :: constant:: ConstantCx ;
12
13
use crate :: prelude:: * ;
13
14
use crate :: pretty_clif:: CommentWriter ;
14
15
15
- pub ( crate ) fn codegen_fn < ' tcx > (
16
+ struct CodegenedFunction < ' tcx > {
17
+ instance : Instance < ' tcx > ,
18
+ symbol_name : SymbolName < ' tcx > ,
19
+ func_id : FuncId ,
20
+ func : Function ,
21
+ clif_comments : CommentWriter ,
22
+ source_info_set : IndexSet < SourceInfo > ,
23
+ local_map : IndexVec < mir:: Local , CPlace < ' tcx > > ,
24
+ }
25
+
26
+ pub ( crate ) fn codegen_and_compile_fn < ' tcx > (
16
27
cx : & mut crate :: CodegenCx < ' tcx > ,
17
28
module : & mut dyn Module ,
18
29
instance : Instance < ' tcx > ,
19
30
) {
20
31
let tcx = cx. tcx ;
21
-
22
32
let _inst_guard =
23
33
crate :: PrintOnPanic ( || format ! ( "{:?} {}" , instance, tcx. symbol_name( instance) . name) ) ;
34
+
35
+ let codegened_func = codegen_fn ( cx, module, instance) ;
36
+
37
+ compile_fn ( cx, module, codegened_func) ;
38
+ }
39
+
40
+ fn codegen_fn < ' tcx > (
41
+ cx : & mut crate :: CodegenCx < ' tcx > ,
42
+ module : & mut dyn Module ,
43
+ instance : Instance < ' tcx > ,
44
+ ) -> CodegenedFunction < ' tcx > {
24
45
debug_assert ! ( !instance. substs. needs_infer( ) ) ;
25
46
47
+ let tcx = cx. tcx ;
48
+
26
49
let mir = tcx. instance_mir ( instance. def ) ;
27
50
let _mir_guard = crate :: PrintOnPanic ( || {
28
51
let mut buf = Vec :: new ( ) ;
@@ -104,36 +127,30 @@ pub(crate) fn codegen_fn<'tcx>(
104
127
// Verify function
105
128
verify_func ( tcx, & clif_comments, & func) ;
106
129
107
- compile_fn (
108
- cx,
109
- module,
130
+ CodegenedFunction {
110
131
instance,
111
- symbol_name. name ,
132
+ symbol_name,
112
133
func_id,
113
134
func,
114
135
clif_comments,
115
136
source_info_set,
116
137
local_map,
117
- ) ;
138
+ }
118
139
}
119
140
120
141
fn compile_fn < ' tcx > (
121
142
cx : & mut crate :: CodegenCx < ' tcx > ,
122
143
module : & mut dyn Module ,
123
- instance : Instance < ' tcx > ,
124
- symbol_name : & str ,
125
- func_id : FuncId ,
126
- func : Function ,
127
- mut clif_comments : CommentWriter ,
128
- source_info_set : IndexSet < SourceInfo > ,
129
- local_map : IndexVec < mir:: Local , CPlace < ' tcx > > ,
144
+ codegened_func : CodegenedFunction < ' tcx > ,
130
145
) {
131
146
let tcx = cx. tcx ;
132
147
148
+ let mut clif_comments = codegened_func. clif_comments ;
149
+
133
150
// Store function in context
134
151
let context = & mut cx. cached_context ;
135
152
context. clear ( ) ;
136
- context. func = func;
153
+ context. func = codegened_func . func ;
137
154
138
155
// If the return block is not reachable, then the SSA builder may have inserted an `iconst.i128`
139
156
// instruction, which doesn't have an encoding.
@@ -150,7 +167,7 @@ fn compile_fn<'tcx>(
150
167
crate :: optimize:: optimize_function (
151
168
tcx,
152
169
module. isa ( ) ,
153
- instance,
170
+ codegened_func . instance ,
154
171
context,
155
172
& mut clif_comments,
156
173
) ;
@@ -186,23 +203,23 @@ fn compile_fn<'tcx>(
186
203
// Define function
187
204
tcx. sess . time ( "define function" , || {
188
205
context. want_disasm = crate :: pretty_clif:: should_write_ir ( tcx) ;
189
- module. define_function ( func_id, context) . unwrap ( ) ;
206
+ module. define_function ( codegened_func . func_id , context) . unwrap ( ) ;
190
207
} ) ;
191
208
192
209
// Write optimized function to file for debugging
193
210
crate :: pretty_clif:: write_clif_file (
194
211
tcx,
195
212
"opt" ,
196
213
module. isa ( ) ,
197
- instance,
214
+ codegened_func . instance ,
198
215
& context. func ,
199
216
& clif_comments,
200
217
) ;
201
218
202
219
if let Some ( disasm) = & context. mach_compile_result . as_ref ( ) . unwrap ( ) . disasm {
203
220
crate :: pretty_clif:: write_ir_file (
204
221
tcx,
205
- || format ! ( "{}.vcode" , tcx. symbol_name( instance) . name) ,
222
+ || format ! ( "{}.vcode" , tcx. symbol_name( codegened_func . instance) . name) ,
206
223
|file| file. write_all ( disasm. as_bytes ( ) ) ,
207
224
)
208
225
}
@@ -214,16 +231,16 @@ fn compile_fn<'tcx>(
214
231
tcx. sess . time ( "generate debug info" , || {
215
232
if let Some ( debug_context) = debug_context {
216
233
debug_context. define_function (
217
- instance,
218
- func_id,
219
- symbol_name,
234
+ codegened_func . instance ,
235
+ codegened_func . func_id ,
236
+ codegened_func . symbol_name . name ,
220
237
isa,
221
238
context,
222
- & source_info_set,
223
- local_map,
239
+ & codegened_func . source_info_set ,
240
+ codegened_func . local_map ,
224
241
) ;
225
242
}
226
- unwind_context. add_function ( func_id, & context, isa) ;
243
+ unwind_context. add_function ( codegened_func . func_id , & context, isa) ;
227
244
} ) ;
228
245
}
229
246
0 commit comments