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