@@ -9,7 +9,7 @@ use crate::custom_insts::CustomInst;
99use  crate :: spirv_type:: SpirvType ; 
1010use  rspirv:: dr:: Operand ; 
1111use  rspirv:: spirv:: GLOp ; 
12- use  rustc_codegen_ssa:: mir:: operand:: OperandRef ; 
12+ use  rustc_codegen_ssa:: mir:: operand:: { OperandRef ,   OperandValue } ; 
1313use  rustc_codegen_ssa:: mir:: place:: PlaceRef ; 
1414use  rustc_codegen_ssa:: traits:: { BuilderMethods ,  IntrinsicCallBuilderMethods } ; 
1515use  rustc_middle:: ty:: layout:: LayoutOf ; 
@@ -240,6 +240,24 @@ impl<'a, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'tcx> {
240240
241241            sym:: ctpop => self . count_ones ( args[ 0 ] . immediate ( ) ) , 
242242            sym:: bitreverse => self . bit_reverse ( args[ 0 ] . immediate ( ) ) , 
243+             sym:: black_box => { 
244+                 // TODO(LegNeato): do something more sophisticated that prevents DCE 
245+                 self . tcx . dcx ( ) . warn ( "black_box intrinsic does not prevent optimization in Rust GPU" ) ; 
246+                 match  args[ 0 ] . val  { 
247+                     // Return the value unchanged for immediates 
248+                     OperandValue :: Immediate ( v)  | OperandValue :: Pair ( v,  _)  => v, 
249+                     // For non-immediates, store and reload 
250+                     OperandValue :: Ref ( place)  => self . load ( 
251+                         self . layout_of ( arg_tys[ 0 ] ) . spirv_type ( self . span ( ) ,  self ) , 
252+                         place. llval , 
253+                         place. align , 
254+                     ) , 
255+                     // For ZSTs, return an undef value that will be optimized away 
256+                     OperandValue :: ZeroSized  => { 
257+                         self . undef ( self . layout_of ( arg_tys[ 0 ] ) . spirv_type ( self . span ( ) ,  self ) ) 
258+                     } 
259+                 } 
260+             } 
243261            sym:: bswap => { 
244262                // https://github.com/KhronosGroup/SPIRV-LLVM/pull/221/files 
245263                // TODO: Definitely add tests to make sure this impl is right. 
0 commit comments