@@ -27,6 +27,41 @@ impl<HCX> HashStable<HCX> for ModuleCodegenResult {
27
27
}
28
28
}
29
29
30
+ pub ( crate ) struct OngoingCodegen {
31
+ modules : Vec < ModuleCodegenResult > ,
32
+ allocator_module : Option < CompiledModule > ,
33
+ metadata_module : Option < CompiledModule > ,
34
+ metadata : EncodedMetadata ,
35
+ crate_info : CrateInfo ,
36
+ work_products : FxHashMap < WorkProductId , WorkProduct > ,
37
+ }
38
+
39
+ impl OngoingCodegen {
40
+ pub ( crate ) fn join ( self ) -> ( CodegenResults , FxHashMap < WorkProductId , WorkProduct > ) {
41
+ let mut work_products = self . work_products ;
42
+ let mut modules = vec ! [ ] ;
43
+
44
+ for module_codegen_result in self . modules {
45
+ let ModuleCodegenResult ( module, work_product) = module_codegen_result;
46
+ if let Some ( ( work_product_id, work_product) ) = work_product {
47
+ work_products. insert ( work_product_id, work_product) ;
48
+ }
49
+ modules. push ( module) ;
50
+ }
51
+
52
+ (
53
+ CodegenResults {
54
+ modules,
55
+ allocator_module : self . allocator_module ,
56
+ metadata_module : self . metadata_module ,
57
+ metadata : self . metadata ,
58
+ crate_info : self . crate_info ,
59
+ } ,
60
+ work_products,
61
+ )
62
+ }
63
+ }
64
+
30
65
fn make_module ( sess : & Session , isa : Box < dyn TargetIsa > , name : String ) -> ObjectModule {
31
66
let mut builder =
32
67
ObjectBuilder :: new ( isa, name + ".o" , cranelift_module:: default_libcall_names ( ) ) . unwrap ( ) ;
@@ -192,9 +227,7 @@ pub(crate) fn run_aot(
192
227
backend_config : BackendConfig ,
193
228
metadata : EncodedMetadata ,
194
229
need_metadata_module : bool ,
195
- ) -> Box < ( CodegenResults , FxHashMap < WorkProductId , WorkProduct > ) > {
196
- let mut work_products = FxHashMap :: default ( ) ;
197
-
230
+ ) -> Box < OngoingCodegen > {
198
231
let cgus = if tcx. sess . opts . output_types . should_codegen ( ) {
199
232
tcx. collect_and_partition_mono_items ( ( ) ) . 1
200
233
} else {
@@ -219,7 +252,7 @@ pub(crate) fn run_aot(
219
252
} ;
220
253
tcx. sess . cgu_reuse_tracker . set_actual_reuse ( cgu. name ( ) . as_str ( ) , cgu_reuse) ;
221
254
222
- let module_codegen_result = match cgu_reuse {
255
+ match cgu_reuse {
223
256
CguReuse :: No => {
224
257
let dep_node = cgu. codegen_dep_node ( tcx) ;
225
258
tcx. dep_graph
@@ -234,21 +267,15 @@ pub(crate) fn run_aot(
234
267
}
235
268
CguReuse :: PreLto => reuse_workproduct_for_cgu ( tcx, & * cgu) ,
236
269
CguReuse :: PostLto => unreachable ! ( ) ,
237
- } ;
238
-
239
- let ModuleCodegenResult ( module, work_product) = module_codegen_result;
240
-
241
- if let Some ( ( id, product) ) = work_product {
242
- work_products. insert ( id, product) ;
243
270
}
244
-
245
- module
246
271
} )
247
272
. collect :: < Vec < _ > > ( )
248
273
} ) ;
249
274
250
275
tcx. sess . abort_if_errors ( ) ;
251
276
277
+ let mut work_products = FxHashMap :: default ( ) ;
278
+
252
279
let isa = crate :: build_isa ( tcx. sess , & backend_config) ;
253
280
let mut allocator_module = make_module ( tcx. sess , isa, "allocator_shim" . to_string ( ) ) ;
254
281
assert_eq ! ( pointer_ty( tcx) , allocator_module. target_config( ) . pointer_type( ) ) ;
@@ -316,16 +343,14 @@ pub(crate) fn run_aot(
316
343
}
317
344
. to_owned ( ) ;
318
345
319
- Box :: new ( (
320
- CodegenResults {
321
- modules,
322
- allocator_module,
323
- metadata_module,
324
- metadata,
325
- crate_info : CrateInfo :: new ( tcx, target_cpu) ,
326
- } ,
346
+ Box :: new ( OngoingCodegen {
347
+ modules,
348
+ allocator_module,
349
+ metadata_module,
350
+ metadata,
351
+ crate_info : CrateInfo :: new ( tcx, target_cpu) ,
327
352
work_products,
328
- ) )
353
+ } )
329
354
}
330
355
331
356
fn codegen_global_asm ( tcx : TyCtxt < ' _ > , cgu_name : & str , global_asm : & str ) {
0 commit comments