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 ;
@@ -261,21 +262,33 @@ impl CodegenBackend for SpirvCodegenBackend {
261
262
rustc_errors:: DEFAULT_LOCALE_RESOURCE
262
263
}
263
264
264
- fn target_features_cfg ( & self , sess : & Session ) -> ( Vec < Symbol > , Vec < Symbol > ) {
265
+ fn target_config ( & self , sess : & Session ) -> TargetConfig {
265
266
let cmdline = sess. opts . cg . target_feature . split ( ',' ) ;
266
267
let cfg = sess. target . options . features . split ( ',' ) ;
267
268
268
- let all_target_features : Vec < _ > = cfg
269
+ let target_features : Vec < _ > = cfg
269
270
. chain ( cmdline)
270
271
. filter ( |l| l. starts_with ( '+' ) )
271
272
. map ( |l| & l[ 1 ..] )
272
273
. filter ( |l| !l. is_empty ( ) )
273
274
. map ( Symbol :: intern)
274
275
. collect ( ) ;
275
276
276
- // HACK(eddyb) the second list is "including unstable target features",
277
+ // HACK(eddyb) this should be a superset of `target_features`,
278
+ // which *additionally* also includes unstable target features,
277
279
// but there is no reason to make a distinction for SPIR-V ones.
278
- ( all_target_features. clone ( ) , all_target_features)
280
+ let unstable_target_features = target_features. clone ( ) ;
281
+
282
+ TargetConfig {
283
+ target_features,
284
+ unstable_target_features,
285
+
286
+ // FIXME(eddyb) support and/or emulate `f16` and `f128`.
287
+ has_reliable_f16 : false ,
288
+ has_reliable_f16_math : false ,
289
+ has_reliable_f128 : false ,
290
+ has_reliable_f128_math : false ,
291
+ }
279
292
}
280
293
281
294
fn provide ( & self , providers : & mut rustc_middle:: util:: Providers ) {
@@ -477,8 +490,8 @@ impl ExtraBackendMethods for SpirvCodegenBackend {
477
490
// TODO: Do dep_graph stuff
478
491
let cgu = tcx. codegen_unit ( cgu_name) ;
479
492
480
- let cx = CodegenCx :: new ( tcx, cgu) ;
481
- let do_codegen = || {
493
+ let mut cx = CodegenCx :: new ( tcx, cgu) ;
494
+ let do_codegen = |cx : & mut CodegenCx < ' _ > | {
482
495
let mono_items = cx. codegen_unit . items_in_deterministic_order ( cx. tcx ) ;
483
496
484
497
if let Some ( dir) = & cx. codegen_args . dump_mir {
@@ -492,32 +505,38 @@ impl ExtraBackendMethods for SpirvCodegenBackend {
492
505
}
493
506
}
494
507
mono_item. predefine :: < Builder < ' _ , ' _ > > (
495
- & cx,
508
+ cx,
496
509
mono_item_data. linkage ,
497
510
mono_item_data. visibility ,
498
511
) ;
499
512
}
500
513
501
514
// ... and now that we have everything pre-defined, fill out those definitions.
502
- for & ( mono_item, _ ) in mono_items. iter ( ) {
515
+ for & ( mono_item, mono_item_data ) in & mono_items {
503
516
if let MonoItem :: Fn ( instance) = mono_item {
504
517
if is_blocklisted_fn ( cx. tcx , & cx. sym , instance) {
505
518
continue ;
506
519
}
507
520
}
508
- mono_item. define :: < Builder < ' _ , ' _ > > ( & cx ) ;
521
+ mono_item. define :: < Builder < ' _ , ' _ > > ( cx , mono_item_data ) ;
509
522
}
510
523
511
- if let Some ( _entry) = maybe_create_entry_wrapper :: < Builder < ' _ , ' _ > > ( & cx) {
524
+ if let Some ( _entry) = maybe_create_entry_wrapper :: < Builder < ' _ , ' _ > > ( cx) {
512
525
// attributes::sanitize(&cx, SanitizerSet::empty(), entry);
513
526
}
514
527
} ;
515
- if let Some ( path) = & cx. codegen_args . dump_module_on_panic {
516
- let module_dumper = DumpModuleOnPanic { cx : & cx, path } ;
517
- with_no_trimmed_paths ! ( do_codegen( ) ) ;
528
+ // HACK(eddyb) mutable access needed for `mono_item.define::<...>(cx, ...)`
529
+ // but that alone leads to needless cloning and smuggling a mutable borrow
530
+ // through `DumpModuleOnPanic` (for both its `Drop` impl and `do_codegen`).
531
+ if let Some ( path) = cx. codegen_args . dump_module_on_panic . clone ( ) {
532
+ let module_dumper = DumpModuleOnPanic {
533
+ cx : & mut cx,
534
+ path : & path,
535
+ } ;
536
+ with_no_trimmed_paths ! ( do_codegen( module_dumper. cx) ) ;
518
537
drop ( module_dumper) ;
519
538
} else {
520
- with_no_trimmed_paths ! ( do_codegen( ) ) ;
539
+ with_no_trimmed_paths ! ( do_codegen( & mut cx ) ) ;
521
540
}
522
541
let spirv_module = cx. finalize_module ( ) . assemble ( ) ;
523
542
@@ -544,7 +563,7 @@ impl ExtraBackendMethods for SpirvCodegenBackend {
544
563
}
545
564
546
565
struct DumpModuleOnPanic < ' a , ' cx , ' tcx > {
547
- cx : & ' cx CodegenCx < ' tcx > ,
566
+ cx : & ' cx mut CodegenCx < ' tcx > ,
548
567
path : & ' a Path ,
549
568
}
550
569
0 commit comments