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