1212#![ feature( string_from_utf8_lossy_owned) ]
1313#![ feature( trait_alias) ]
1414#![ feature( try_blocks) ]
15+ #![ recursion_limit = "256" ]
1516// HACK(eddyb) end of `rustc_codegen_ssa` crate-level attributes (see `build.rs`).
1617
1718//! Welcome to the API documentation for the `rust-gpu` project, this API is
@@ -150,7 +151,7 @@ use maybe_pqp_cg_ssa::traits::{
150151 CodegenBackend , ExtraBackendMethods , ModuleBufferMethods , ThinBufferMethods ,
151152 WriteBackendMethods ,
152153} ;
153- use maybe_pqp_cg_ssa:: { CodegenResults , CompiledModule , ModuleCodegen , ModuleKind } ;
154+ use maybe_pqp_cg_ssa:: { CodegenResults , CompiledModule , ModuleCodegen , ModuleKind , TargetConfig } ;
154155use rspirv:: binary:: Assemble ;
155156use rustc_ast:: expand:: allocator:: AllocatorKind ;
156157use rustc_ast:: expand:: autodiff_attrs:: AutoDiffItem ;
@@ -261,21 +262,33 @@ impl CodegenBackend for SpirvCodegenBackend {
261262 rustc_errors:: DEFAULT_LOCALE_RESOURCE
262263 }
263264
264- fn target_features_cfg ( & self , sess : & Session ) -> ( Vec < Symbol > , Vec < Symbol > ) {
265+ fn target_config ( & self , sess : & Session ) -> TargetConfig {
265266 let cmdline = sess. opts . cg . target_feature . split ( ',' ) ;
266267 let cfg = sess. target . options . features . split ( ',' ) ;
267268
268- let all_target_features : Vec < _ > = cfg
269+ let target_features : Vec < _ > = cfg
269270 . chain ( cmdline)
270271 . filter ( |l| l. starts_with ( '+' ) )
271272 . map ( |l| & l[ 1 ..] )
272273 . filter ( |l| !l. is_empty ( ) )
273274 . map ( Symbol :: intern)
274275 . collect ( ) ;
275276
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,
277279 // 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+ }
279292 }
280293
281294 fn provide ( & self , providers : & mut rustc_middle:: util:: Providers ) {
@@ -477,8 +490,8 @@ impl ExtraBackendMethods for SpirvCodegenBackend {
477490 // TODO: Do dep_graph stuff
478491 let cgu = tcx. codegen_unit ( cgu_name) ;
479492
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 < ' _ > | {
482495 let mono_items = cx. codegen_unit . items_in_deterministic_order ( cx. tcx ) ;
483496
484497 if let Some ( dir) = & cx. codegen_args . dump_mir {
@@ -492,32 +505,38 @@ impl ExtraBackendMethods for SpirvCodegenBackend {
492505 }
493506 }
494507 mono_item. predefine :: < Builder < ' _ , ' _ > > (
495- & cx,
508+ cx,
496509 mono_item_data. linkage ,
497510 mono_item_data. visibility ,
498511 ) ;
499512 }
500513
501514 // ... 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 {
503516 if let MonoItem :: Fn ( instance) = mono_item {
504517 if is_blocklisted_fn ( cx. tcx , & cx. sym , instance) {
505518 continue ;
506519 }
507520 }
508- mono_item. define :: < Builder < ' _ , ' _ > > ( & cx ) ;
521+ mono_item. define :: < Builder < ' _ , ' _ > > ( cx , mono_item_data ) ;
509522 }
510523
511- if let Some ( _entry) = maybe_create_entry_wrapper :: < Builder < ' _ , ' _ > > ( & cx) {
524+ if let Some ( _entry) = maybe_create_entry_wrapper :: < Builder < ' _ , ' _ > > ( cx) {
512525 // attributes::sanitize(&cx, SanitizerSet::empty(), entry);
513526 }
514527 } ;
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) ) ;
518537 drop ( module_dumper) ;
519538 } else {
520- with_no_trimmed_paths ! ( do_codegen( ) ) ;
539+ with_no_trimmed_paths ! ( do_codegen( & mut cx ) ) ;
521540 }
522541 let spirv_module = cx. finalize_module ( ) . assemble ( ) ;
523542
@@ -544,7 +563,7 @@ impl ExtraBackendMethods for SpirvCodegenBackend {
544563}
545564
546565struct DumpModuleOnPanic < ' a , ' cx , ' tcx > {
547- cx : & ' cx CodegenCx < ' tcx > ,
566+ cx : & ' cx mut CodegenCx < ' tcx > ,
548567 path : & ' a Path ,
549568}
550569
0 commit comments