@@ -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,23 @@ 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+ match args[ 0 ] . val {
246+ // Return the value unchanged for immediates
247+ OperandValue :: Immediate ( v) | OperandValue :: Pair ( v, _) => v,
248+ // For non-immediates, store and reload
249+ OperandValue :: Ref ( place) => self . load (
250+ self . layout_of ( arg_tys[ 0 ] ) . spirv_type ( self . span ( ) , self ) ,
251+ place. llval ,
252+ place. align ,
253+ ) ,
254+ // For ZSTs, return an undef value that will be optimized away
255+ OperandValue :: ZeroSized => {
256+ self . undef ( self . layout_of ( arg_tys[ 0 ] ) . spirv_type ( self . span ( ) , self ) )
257+ }
258+ }
259+ }
243260 sym:: bswap => {
244261 // https://github.com/KhronosGroup/SPIRV-LLVM/pull/221/files
245262 // TODO: Definitely add tests to make sure this impl is right.
0 commit comments