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
@@ -146,7 +147,7 @@ use maybe_pqp_cg_ssa::traits::{
146147 CodegenBackend , ExtraBackendMethods , ModuleBufferMethods , ThinBufferMethods ,
147148 WriteBackendMethods ,
148149} ;
149- use maybe_pqp_cg_ssa:: { CodegenResults , CompiledModule , ModuleCodegen , ModuleKind } ;
150+ use maybe_pqp_cg_ssa:: { CodegenResults , CompiledModule , ModuleCodegen , ModuleKind , TargetConfig } ;
150151use rspirv:: binary:: Assemble ;
151152use rustc_ast:: expand:: allocator:: AllocatorKind ;
152153use rustc_ast:: expand:: autodiff_attrs:: AutoDiffItem ;
@@ -257,21 +258,33 @@ impl CodegenBackend for SpirvCodegenBackend {
257258 rustc_errors:: DEFAULT_LOCALE_RESOURCE
258259 }
259260
260- fn target_features_cfg ( & self , sess : & Session ) -> ( Vec < Symbol > , Vec < Symbol > ) {
261+ fn target_config ( & self , sess : & Session ) -> TargetConfig {
261262 let cmdline = sess. opts . cg . target_feature . split ( ',' ) ;
262263 let cfg = sess. target . options . features . split ( ',' ) ;
263264
264- let all_target_features : Vec < _ > = cfg
265+ let target_features : Vec < _ > = cfg
265266 . chain ( cmdline)
266267 . filter ( |l| l. starts_with ( '+' ) )
267268 . map ( |l| & l[ 1 ..] )
268269 . filter ( |l| !l. is_empty ( ) )
269270 . map ( Symbol :: intern)
270271 . collect ( ) ;
271272
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,
273275 // 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+ }
275288 }
276289
277290 fn provide ( & self , providers : & mut rustc_middle:: util:: Providers ) {
@@ -473,8 +486,8 @@ impl ExtraBackendMethods for SpirvCodegenBackend {
473486 // TODO: Do dep_graph stuff
474487 let cgu = tcx. codegen_unit ( cgu_name) ;
475488
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 < ' _ > | {
478491 let mono_items = cx. codegen_unit . items_in_deterministic_order ( cx. tcx ) ;
479492
480493 if let Some ( dir) = & cx. codegen_args . dump_mir {
@@ -488,32 +501,38 @@ impl ExtraBackendMethods for SpirvCodegenBackend {
488501 }
489502 }
490503 mono_item. predefine :: < Builder < ' _ , ' _ > > (
491- & cx,
504+ cx,
492505 mono_item_data. linkage ,
493506 mono_item_data. visibility ,
494507 ) ;
495508 }
496509
497510 // ... 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 {
499512 if let MonoItem :: Fn ( instance) = mono_item {
500513 if is_blocklisted_fn ( cx. tcx , & cx. sym , instance) {
501514 continue ;
502515 }
503516 }
504- mono_item. define :: < Builder < ' _ , ' _ > > ( & cx ) ;
517+ mono_item. define :: < Builder < ' _ , ' _ > > ( cx , mono_item_data ) ;
505518 }
506519
507- if let Some ( _entry) = maybe_create_entry_wrapper :: < Builder < ' _ , ' _ > > ( & cx) {
520+ if let Some ( _entry) = maybe_create_entry_wrapper :: < Builder < ' _ , ' _ > > ( cx) {
508521 // attributes::sanitize(&cx, SanitizerSet::empty(), entry);
509522 }
510523 } ;
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) ) ;
514533 drop ( module_dumper) ;
515534 } else {
516- with_no_trimmed_paths ! ( do_codegen( ) ) ;
535+ with_no_trimmed_paths ! ( do_codegen( & mut cx ) ) ;
517536 }
518537 let spirv_module = cx. finalize_module ( ) . assemble ( ) ;
519538
@@ -540,7 +559,7 @@ impl ExtraBackendMethods for SpirvCodegenBackend {
540559}
541560
542561struct DumpModuleOnPanic < ' a , ' cx , ' tcx > {
543- cx : & ' cx CodegenCx < ' tcx > ,
562+ cx : & ' cx mut CodegenCx < ' tcx > ,
544563 path : & ' a Path ,
545564}
546565
0 commit comments