@@ -3,7 +3,9 @@ use crate::maybe_pqp_cg_ssa as rustc_codegen_ssa;
3
3
4
4
use super :: Builder ;
5
5
use crate :: abi:: ConvSpirvType ;
6
- use crate :: builder_spirv:: { BuilderCursor , SpirvConst , SpirvValue , SpirvValueExt , SpirvValueKind } ;
6
+ use crate :: builder_spirv:: {
7
+ SpirvBlockCursor , SpirvConst , SpirvValue , SpirvValueExt , SpirvValueKind ,
8
+ } ;
7
9
use crate :: codegen_cx:: CodegenCx ;
8
10
use crate :: custom_insts:: { CustomInst , CustomOp } ;
9
11
use crate :: spirv_type:: SpirvType ;
@@ -166,8 +168,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
166
168
| MemorySemantics :: ACQUIRE_RELEASE
167
169
}
168
170
AtomicOrdering :: SeqCst => {
169
- let emit = self . emit ( ) ;
170
- let memory_model = emit . module_ref ( ) . memory_model . as_ref ( ) . unwrap ( ) ;
171
+ let builder = self . emit ( ) ;
172
+ let memory_model = builder . module_ref ( ) . memory_model . as_ref ( ) . unwrap ( ) ;
171
173
if memory_model. operands [ 1 ] . unwrap_memory_model ( ) == MemoryModel :: Vulkan {
172
174
invalid_seq_cst = true ;
173
175
}
@@ -750,9 +752,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
750
752
let ptr_id = ptr. def ( self ) ;
751
753
752
754
let maybe_original_access_chain = {
753
- let emit = self . emit ( ) ;
754
- let module = emit . module_ref ( ) ;
755
- let current_func_blocks = emit
755
+ let builder = self . emit ( ) ;
756
+ let module = builder . module_ref ( ) ;
757
+ let current_func_blocks = builder
756
758
. selected_function ( )
757
759
. and_then ( |func_idx| Some ( & module. functions . get ( func_idx) ?. blocks [ ..] ) )
758
760
. unwrap_or_default ( ) ;
@@ -830,21 +832,21 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
830
832
indices : Vec < Word > ,
831
833
is_inbounds : bool ,
832
834
) -> SpirvValue {
833
- let mut emit = self . emit ( ) ;
835
+ let mut builder = self . emit ( ) ;
834
836
835
837
let non_zero_ptr_base_index =
836
838
ptr_base_index. filter ( |& idx| self . builder . lookup_const_scalar ( idx) != Some ( 0 ) ) ;
837
839
if let Some ( ptr_base_index) = non_zero_ptr_base_index {
838
840
let result = if is_inbounds {
839
- emit . in_bounds_ptr_access_chain (
841
+ builder . in_bounds_ptr_access_chain (
840
842
result_type,
841
843
None ,
842
844
pointer,
843
845
ptr_base_index. def ( self ) ,
844
846
indices,
845
847
)
846
848
} else {
847
- emit . ptr_access_chain (
849
+ builder . ptr_access_chain (
848
850
result_type,
849
851
None ,
850
852
pointer,
@@ -857,9 +859,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
857
859
result
858
860
} else {
859
861
if is_inbounds {
860
- emit . in_bounds_access_chain ( result_type, None , pointer, indices)
862
+ builder . in_bounds_access_chain ( result_type, None , pointer, indices)
861
863
} else {
862
- emit . access_chain ( result_type, None , pointer, indices)
864
+ builder . access_chain ( result_type, None , pointer, indices)
863
865
}
864
866
. unwrap ( )
865
867
}
@@ -1091,21 +1093,9 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
1091
1093
1092
1094
#[ instrument( level = "trace" , skip( cx) ) ]
1093
1095
fn build ( cx : & ' a Self :: CodegenCx , llbb : Self :: BasicBlock ) -> Self {
1094
- let cursor = cx. builder . select_block_by_id ( llbb) ;
1095
- // FIXME(eddyb) change `Self::Function` to be more like a function index.
1096
- let current_fn = {
1097
- let emit = cx. emit_with_cursor ( cursor) ;
1098
- let selected_function = emit. selected_function ( ) . unwrap ( ) ;
1099
- let selected_function = & emit. module_ref ( ) . functions [ selected_function] ;
1100
- let def_inst = selected_function. def . as_ref ( ) . unwrap ( ) ;
1101
- let def = def_inst. result_id . unwrap ( ) ;
1102
- let ty = def_inst. operands [ 1 ] . unwrap_id_ref ( ) ;
1103
- def. with_type ( ty)
1104
- } ;
1105
1096
Self {
1106
1097
cx,
1107
- cursor,
1108
- current_fn,
1098
+ current_block : llbb,
1109
1099
current_span : Default :: default ( ) ,
1110
1100
}
1111
1101
}
@@ -1201,17 +1191,18 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
1201
1191
llfn : Self :: Function ,
1202
1192
_name : & str ,
1203
1193
) -> Self :: BasicBlock {
1204
- let cursor_fn = cx. builder . select_function_by_id ( llfn. def_cx ( cx) ) ;
1205
- cx. emit_with_cursor ( cursor_fn) . begin_block ( None ) . unwrap ( )
1194
+ let mut builder = cx. builder . builder_for_fn ( llfn) ;
1195
+ let id = builder. begin_block ( None ) . unwrap ( ) ;
1196
+ let index_in_builder = builder. selected_block ( ) . unwrap ( ) ;
1197
+ SpirvBlockCursor {
1198
+ parent_fn : llfn,
1199
+ id,
1200
+ index_in_builder,
1201
+ }
1206
1202
}
1207
1203
1208
- fn append_sibling_block ( & mut self , _name : & str ) -> Self :: BasicBlock {
1209
- self . emit_with_cursor ( BuilderCursor {
1210
- function : self . cursor . function ,
1211
- block : None ,
1212
- } )
1213
- . begin_block ( None )
1214
- . unwrap ( )
1204
+ fn append_sibling_block ( & mut self , name : & str ) -> Self :: BasicBlock {
1205
+ Self :: append_block ( self . cx , self . current_block . parent_fn , name)
1215
1206
}
1216
1207
1217
1208
fn switch_to_block ( & mut self , llbb : Self :: BasicBlock ) {
@@ -1239,7 +1230,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
1239
1230
}
1240
1231
1241
1232
fn br ( & mut self , dest : Self :: BasicBlock ) {
1242
- self . emit ( ) . branch ( dest) . unwrap ( ) ;
1233
+ self . emit ( ) . branch ( dest. id ) . unwrap ( ) ;
1243
1234
}
1244
1235
1245
1236
fn cond_br (
@@ -1257,7 +1248,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
1257
1248
Some ( SpirvConst :: Scalar ( 0 ) ) => self . br ( else_llbb) ,
1258
1249
_ => {
1259
1250
self . emit ( )
1260
- . branch_conditional ( cond, then_llbb, else_llbb, empty ( ) )
1251
+ . branch_conditional ( cond, then_llbb. id , else_llbb. id , empty ( ) )
1261
1252
. unwrap ( ) ;
1262
1253
}
1263
1254
}
@@ -1330,9 +1321,11 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
1330
1321
) ) ,
1331
1322
} ;
1332
1323
let cases = cases
1333
- . map ( |( i, b) | ( construct_case ( self , signed, i) , b) )
1324
+ . map ( |( i, b) | ( construct_case ( self , signed, i) , b. id ) )
1334
1325
. collect :: < Vec < _ > > ( ) ;
1335
- self . emit ( ) . switch ( v. def ( self ) , else_llbb, cases) . unwrap ( ) ;
1326
+ self . emit ( )
1327
+ . switch ( v. def ( self ) , else_llbb. id , cases)
1328
+ . unwrap ( ) ;
1336
1329
}
1337
1330
1338
1331
fn invoke (
@@ -1349,7 +1342,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
1349
1342
) -> Self :: Value {
1350
1343
// Exceptions don't exist, jump directly to then block
1351
1344
let result = self . call ( llty, fn_attrs, fn_abi, llfn, args, funclet, instance) ;
1352
- self . emit ( ) . branch ( then) . unwrap ( ) ;
1345
+ self . emit ( ) . branch ( then. id ) . unwrap ( ) ;
1353
1346
result
1354
1347
}
1355
1348
@@ -2741,16 +2734,16 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
2741
2734
. with_type ( agg_val. ty )
2742
2735
}
2743
2736
2744
- fn set_personality_fn ( & mut self , _personality : Self :: Value ) {
2737
+ fn set_personality_fn ( & mut self , _personality : Self :: Function ) {
2745
2738
todo ! ( )
2746
2739
}
2747
2740
2748
2741
// These are used by everyone except msvc
2749
- fn cleanup_landing_pad ( & mut self , _pers_fn : Self :: Value ) -> ( Self :: Value , Self :: Value ) {
2742
+ fn cleanup_landing_pad ( & mut self , _pers_fn : Self :: Function ) -> ( Self :: Value , Self :: Value ) {
2750
2743
todo ! ( )
2751
2744
}
2752
2745
2753
- fn filter_landing_pad ( & mut self , _pers_fn : Self :: Value ) -> ( Self :: Value , Self :: Value ) {
2746
+ fn filter_landing_pad ( & mut self , _pers_fn : Self :: Function ) -> ( Self :: Value , Self :: Value ) {
2754
2747
todo ! ( )
2755
2748
}
2756
2749
@@ -2979,16 +2972,6 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
2979
2972
// be fixed upstream, so we never see any "function pointer" values being
2980
2973
// created just to perform direct calls.
2981
2974
let ( callee_val, result_type, argument_types) = match self . lookup_type ( callee. ty ) {
2982
- // HACK(eddyb) this seems to be needed, but it's not what `get_fn_addr`
2983
- // produces, are these coming from inside `rustc_codegen_spirv`?
2984
- SpirvType :: Function {
2985
- return_type,
2986
- arguments,
2987
- } => {
2988
- assert_ty_eq ! ( self , callee_ty, callee. ty) ;
2989
- ( callee. def ( self ) , return_type, arguments)
2990
- }
2991
-
2992
2975
SpirvType :: Pointer { pointee } => match self . lookup_type ( pointee) {
2993
2976
SpirvType :: Function {
2994
2977
return_type,
@@ -3014,7 +2997,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
3014
2997
} ,
3015
2998
3016
2999
_ => bug ! (
3017
- "call expected function or `fn` pointer type, got `{}`" ,
3000
+ "call expected `fn` pointer type, got `{}`" ,
3018
3001
self . debug_type( callee. ty)
3019
3002
) ,
3020
3003
} ;
0 commit comments