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
36
37
// crate-specific exceptions:
37
38
#![ allow(
38
39
unsafe_code, // rustc_codegen_ssa requires unsafe functions in traits to be impl'd
39
- clippy:: match_on_vec_items, // rustc_codegen_spirv has less strict panic requirements than other embark projects
40
40
clippy:: enum_glob_use, // pretty useful pattern with some codegen'd enums (e.g. rspirv::spirv::Op)
41
41
clippy:: todo, // still lots to implement :)
42
42
@@ -147,7 +147,7 @@ use maybe_pqp_cg_ssa::traits::{
147
147
CodegenBackend , ExtraBackendMethods , ModuleBufferMethods , ThinBufferMethods ,
148
148
WriteBackendMethods ,
149
149
} ;
150
- use maybe_pqp_cg_ssa:: { CodegenResults , CompiledModule , ModuleCodegen , ModuleKind } ;
150
+ use maybe_pqp_cg_ssa:: { CodegenResults , CompiledModule , ModuleCodegen , ModuleKind , TargetConfig } ;
151
151
use rspirv:: binary:: Assemble ;
152
152
use rustc_ast:: expand:: allocator:: AllocatorKind ;
153
153
use rustc_ast:: expand:: autodiff_attrs:: AutoDiffItem ;
@@ -258,21 +258,33 @@ impl CodegenBackend for SpirvCodegenBackend {
258
258
rustc_errors:: DEFAULT_LOCALE_RESOURCE
259
259
}
260
260
261
- fn target_features_cfg ( & self , sess : & Session ) -> ( Vec < Symbol > , Vec < Symbol > ) {
261
+ fn target_config ( & self , sess : & Session ) -> TargetConfig {
262
262
let cmdline = sess. opts . cg . target_feature . split ( ',' ) ;
263
263
let cfg = sess. target . options . features . split ( ',' ) ;
264
264
265
- let all_target_features : Vec < _ > = cfg
265
+ let target_features : Vec < _ > = cfg
266
266
. chain ( cmdline)
267
267
. filter ( |l| l. starts_with ( '+' ) )
268
268
. map ( |l| & l[ 1 ..] )
269
269
. filter ( |l| !l. is_empty ( ) )
270
270
. map ( Symbol :: intern)
271
271
. collect ( ) ;
272
272
273
- // 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,
274
275
// but there is no reason to make a distinction for SPIR-V ones.
275
- ( 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
+ }
276
288
}
277
289
278
290
fn provide ( & self , providers : & mut rustc_middle:: util:: Providers ) {
@@ -474,8 +486,8 @@ impl ExtraBackendMethods for SpirvCodegenBackend {
474
486
// TODO: Do dep_graph stuff
475
487
let cgu = tcx. codegen_unit ( cgu_name) ;
476
488
477
- let cx = CodegenCx :: new ( tcx, cgu) ;
478
- let do_codegen = || {
489
+ let mut cx = CodegenCx :: new ( tcx, cgu) ;
490
+ let do_codegen = |cx : & mut CodegenCx < ' _ > | {
479
491
let mono_items = cx. codegen_unit . items_in_deterministic_order ( cx. tcx ) ;
480
492
481
493
if let Some ( dir) = & cx. codegen_args . dump_mir {
@@ -489,32 +501,38 @@ impl ExtraBackendMethods for SpirvCodegenBackend {
489
501
}
490
502
}
491
503
mono_item. predefine :: < Builder < ' _ , ' _ > > (
492
- & cx,
504
+ cx,
493
505
mono_item_data. linkage ,
494
506
mono_item_data. visibility ,
495
507
) ;
496
508
}
497
509
498
510
// ... and now that we have everything pre-defined, fill out those definitions.
499
- for & ( mono_item, _ ) in mono_items. iter ( ) {
511
+ for & ( mono_item, mono_item_data ) in & mono_items {
500
512
if let MonoItem :: Fn ( instance) = mono_item {
501
513
if is_blocklisted_fn ( cx. tcx , & cx. sym , instance) {
502
514
continue ;
503
515
}
504
516
}
505
- mono_item. define :: < Builder < ' _ , ' _ > > ( & cx ) ;
517
+ mono_item. define :: < Builder < ' _ , ' _ > > ( cx , mono_item_data ) ;
506
518
}
507
519
508
- if let Some ( _entry) = maybe_create_entry_wrapper :: < Builder < ' _ , ' _ > > ( & cx) {
520
+ if let Some ( _entry) = maybe_create_entry_wrapper :: < Builder < ' _ , ' _ > > ( cx) {
509
521
// attributes::sanitize(&cx, SanitizerSet::empty(), entry);
510
522
}
511
523
} ;
512
- if let Some ( path) = & cx. codegen_args . dump_module_on_panic {
513
- let module_dumper = DumpModuleOnPanic { cx : & cx, path } ;
514
- 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) ) ;
515
533
drop ( module_dumper) ;
516
534
} else {
517
- with_no_trimmed_paths ! ( do_codegen( ) ) ;
535
+ with_no_trimmed_paths ! ( do_codegen( & mut cx ) ) ;
518
536
}
519
537
let spirv_module = cx. finalize_module ( ) . assemble ( ) ;
520
538
@@ -541,7 +559,7 @@ impl ExtraBackendMethods for SpirvCodegenBackend {
541
559
}
542
560
543
561
struct DumpModuleOnPanic < ' a , ' cx , ' tcx > {
544
- cx : & ' cx CodegenCx < ' tcx > ,
562
+ cx : & ' cx mut CodegenCx < ' tcx > ,
545
563
path : & ' a Path ,
546
564
}
547
565
0 commit comments