12
12
#![ feature( string_from_utf8_lossy_owned) ]
13
13
#![ feature( trait_alias) ]
14
14
#![ feature( try_blocks) ]
15
+ #![ recursion_limit = "256" ]
15
16
// HACK(eddyb) end of `rustc_codegen_ssa` crate-level attributes (see `build.rs`).
16
17
17
18
//! Welcome to the API documentation for the `rust-gpu` project, this API is
@@ -150,7 +151,7 @@ use maybe_pqp_cg_ssa::traits::{
150
151
CodegenBackend , ExtraBackendMethods , ModuleBufferMethods , ThinBufferMethods ,
151
152
WriteBackendMethods ,
152
153
} ;
153
- use maybe_pqp_cg_ssa:: { CodegenResults , CompiledModule , ModuleCodegen , ModuleKind } ;
154
+ use maybe_pqp_cg_ssa:: { CodegenResults , CompiledModule , ModuleCodegen , ModuleKind , TargetConfig } ;
154
155
use rspirv:: binary:: Assemble ;
155
156
use rustc_ast:: expand:: allocator:: AllocatorKind ;
156
157
use rustc_ast:: expand:: autodiff_attrs:: AutoDiffItem ;
@@ -222,21 +223,33 @@ impl CodegenBackend for SpirvCodegenBackend {
222
223
rustc_errors:: DEFAULT_LOCALE_RESOURCE
223
224
}
224
225
225
- fn target_features_cfg ( & self , sess : & Session ) -> ( Vec < Symbol > , Vec < Symbol > ) {
226
+ fn target_config ( & self , sess : & Session ) -> TargetConfig {
226
227
let cmdline = sess. opts . cg . target_feature . split ( ',' ) ;
227
228
let cfg = sess. target . options . features . split ( ',' ) ;
228
229
229
- let all_target_features : Vec < _ > = cfg
230
+ let target_features : Vec < _ > = cfg
230
231
. chain ( cmdline)
231
232
. filter ( |l| l. starts_with ( '+' ) )
232
233
. map ( |l| & l[ 1 ..] )
233
234
. filter ( |l| !l. is_empty ( ) )
234
235
. map ( Symbol :: intern)
235
236
. collect ( ) ;
236
237
237
- // HACK(eddyb) the second list is "including unstable target features",
238
+ // HACK(eddyb) this should be a superset of `target_features`,
239
+ // which *additionally* also includes unstable target features,
238
240
// but there is no reason to make a distinction for SPIR-V ones.
239
- ( all_target_features. clone ( ) , all_target_features)
241
+ let unstable_target_features = target_features. clone ( ) ;
242
+
243
+ TargetConfig {
244
+ target_features,
245
+ unstable_target_features,
246
+
247
+ // FIXME(eddyb) support and/or emulate `f16` and `f128`.
248
+ has_reliable_f16 : false ,
249
+ has_reliable_f16_math : false ,
250
+ has_reliable_f128 : false ,
251
+ has_reliable_f128_math : false ,
252
+ }
240
253
}
241
254
242
255
fn provide ( & self , providers : & mut rustc_middle:: util:: Providers ) {
@@ -438,8 +451,8 @@ impl ExtraBackendMethods for SpirvCodegenBackend {
438
451
// TODO: Do dep_graph stuff
439
452
let cgu = tcx. codegen_unit ( cgu_name) ;
440
453
441
- let cx = CodegenCx :: new ( tcx, cgu) ;
442
- let do_codegen = || {
454
+ let mut cx = CodegenCx :: new ( tcx, cgu) ;
455
+ let do_codegen = |cx : & mut CodegenCx < ' _ > | {
443
456
let mono_items = cx. codegen_unit . items_in_deterministic_order ( cx. tcx ) ;
444
457
445
458
if let Some ( dir) = & cx. codegen_args . dump_mir {
@@ -448,27 +461,33 @@ impl ExtraBackendMethods for SpirvCodegenBackend {
448
461
449
462
for & ( mono_item, mono_item_data) in mono_items. iter ( ) {
450
463
mono_item. predefine :: < Builder < ' _ , ' _ > > (
451
- & cx,
464
+ cx,
452
465
mono_item_data. linkage ,
453
466
mono_item_data. visibility ,
454
467
) ;
455
468
}
456
469
457
470
// ... and now that we have everything pre-defined, fill out those definitions.
458
- for & ( mono_item, _ ) in mono_items. iter ( ) {
459
- mono_item. define :: < Builder < ' _ , ' _ > > ( & cx ) ;
471
+ for & ( mono_item, mono_item_data ) in & mono_items {
472
+ mono_item. define :: < Builder < ' _ , ' _ > > ( cx , mono_item_data ) ;
460
473
}
461
474
462
- if let Some ( _entry) = maybe_create_entry_wrapper :: < Builder < ' _ , ' _ > > ( & cx) {
475
+ if let Some ( _entry) = maybe_create_entry_wrapper :: < Builder < ' _ , ' _ > > ( cx) {
463
476
// attributes::sanitize(&cx, SanitizerSet::empty(), entry);
464
477
}
465
478
} ;
466
- if let Some ( path) = & cx. codegen_args . dump_module_on_panic {
467
- let module_dumper = DumpModuleOnPanic { cx : & cx, path } ;
468
- with_no_trimmed_paths ! ( do_codegen( ) ) ;
479
+ // HACK(eddyb) mutable access needed for `mono_item.define::<...>(cx, ...)`
480
+ // but that alone leads to needless cloning and smuggling a mutable borrow
481
+ // through `DumpModuleOnPanic` (for both its `Drop` impl and `do_codegen`).
482
+ if let Some ( path) = cx. codegen_args . dump_module_on_panic . clone ( ) {
483
+ let module_dumper = DumpModuleOnPanic {
484
+ cx : & mut cx,
485
+ path : & path,
486
+ } ;
487
+ with_no_trimmed_paths ! ( do_codegen( module_dumper. cx) ) ;
469
488
drop ( module_dumper) ;
470
489
} else {
471
- with_no_trimmed_paths ! ( do_codegen( ) ) ;
490
+ with_no_trimmed_paths ! ( do_codegen( & mut cx ) ) ;
472
491
}
473
492
let spirv_module = cx. finalize_module ( ) . assemble ( ) ;
474
493
@@ -495,7 +514,7 @@ impl ExtraBackendMethods for SpirvCodegenBackend {
495
514
}
496
515
497
516
struct DumpModuleOnPanic < ' a , ' cx , ' tcx > {
498
- cx : & ' cx CodegenCx < ' tcx > ,
517
+ cx : & ' cx mut CodegenCx < ' tcx > ,
499
518
path : & ' a Path ,
500
519
}
501
520
0 commit comments