Skip to content

Commit 17814d6

Browse files
committed
PassMode::Cast
1 parent aec0b72 commit 17814d6

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

rustc_codegen_spirv/src/abi.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -528,13 +528,8 @@ impl<'spv, 'tcx> ConvSpirvType<'spv, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
528528

529529
let return_type = match self.ret.mode {
530530
PassMode::Ignore => SpirvType::Void.def(cx),
531-
PassMode::Direct(_arg_attributes) => self.ret.layout.spirv_type_immediate(cx),
532-
PassMode::Pair(_arg_attributes_1, _arg_attributes_2) => {
533-
panic!("PassMode::Pair not supported for return type")
534-
}
535-
PassMode::Cast(_cast_target) => {
536-
panic!("TODO: PassMode::Cast not supported for return type")
537-
}
531+
PassMode::Direct(_) | PassMode::Pair(..) => self.ret.layout.spirv_type_immediate(cx),
532+
PassMode::Cast(cast_target) => cast_target.spirv_type(cx),
538533
// TODO: Deal with wide ptr?
539534
PassMode::Indirect(_arg_attributes, wide_ptr_attrs) => {
540535
if wide_ptr_attrs.is_some() {
@@ -575,9 +570,19 @@ impl<'spv, 'tcx> ConvSpirvType<'spv, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
575570
argument_types.push(right);
576571
continue;
577572
}
578-
PassMode::Cast(_cast_target) => arg.layout.spirv_type(cx),
579-
// TODO: Deal with wide ptr?
580-
PassMode::Indirect(_arg_attributes, _wide_ptr_attrs) => {
573+
PassMode::Cast(cast_target) => cast_target.spirv_type(cx),
574+
PassMode::Indirect(_, Some(_)) => {
575+
let ptr_ty = cx.tcx.mk_mut_ptr(arg.layout.ty);
576+
let ptr_layout = cx.layout_of(ptr_ty);
577+
let (a, b) = match &arg.layout.abi {
578+
Abi::ScalarPair(a, b) => (a, b),
579+
other => panic!("PassMode::Indirect invalid abi: {:?}", other),
580+
};
581+
argument_types.push(trans_scalar_pair(cx, &ptr_layout, a, 0, true));
582+
argument_types.push(trans_scalar_pair(cx, &ptr_layout, b, 0, true));
583+
continue;
584+
}
585+
PassMode::Indirect(_, None) => {
581586
let pointee = arg.layout.spirv_type(cx);
582587
SpirvType::Pointer {
583588
storage_class: StorageClass::Generic,

rustc_codegen_spirv/src/builder/mod.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ mod builder_methods;
33
use crate::abi::{ConvSpirvType, SpirvType};
44
use crate::builder_spirv::{BuilderCursor, SpirvValue, SpirvValueExt};
55
use crate::codegen_cx::CodegenCx;
6+
use rspirv::spirv::StorageClass;
67
use rustc_ast::ast::{InlineAsmOptions, InlineAsmTemplatePiece};
78
use rustc_codegen_ssa::common::IntPredicate;
89
use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
@@ -207,7 +208,6 @@ impl<'a, 'spv, 'tcx> ArgAbiMethods<'tcx> for Builder<'a, 'spv, 'tcx> {
207208
}
208209
match arg_abi.mode {
209210
PassMode::Ignore => (),
210-
PassMode::Direct(_) => OperandValue::Immediate(next(self, idx)).store(self, dst),
211211
PassMode::Pair(..) => {
212212
OperandValue::Pair(next(self, idx), next(self, idx)).store(self, dst)
213213
}
@@ -217,11 +217,9 @@ impl<'a, 'spv, 'tcx> ArgAbiMethods<'tcx> for Builder<'a, 'spv, 'tcx> {
217217
arg_abi.layout.align.abi,
218218
)
219219
.store(self, dst),
220-
PassMode::Indirect(_, None) => {
221-
OperandValue::Ref(next(self, idx), None, arg_abi.layout.align.abi).store(self, dst)
222-
}
223-
PassMode::Cast(_) => {
224-
panic!("TODO: store_fn_arg PassMode::Cast not implemented yet");
220+
PassMode::Direct(_) | PassMode::Indirect(_, None) | PassMode::Cast(_) => {
221+
let next_arg = next(self, idx);
222+
self.store_arg(arg_abi, next_arg, dst)
225223
}
226224
}
227225
}
@@ -236,14 +234,18 @@ impl<'a, 'spv, 'tcx> ArgAbiMethods<'tcx> for Builder<'a, 'spv, 'tcx> {
236234
return;
237235
}
238236
if arg_abi.is_sized_indirect() {
239-
OperandValue::Ref(val, None, arg_abi.layout.align.abi).store(self, dst)
237+
OperandValue::Ref(val, None, arg_abi.layout.align.abi).store(self, dst);
240238
} else if arg_abi.is_unsized_indirect() {
241239
panic!("unsized `ArgAbi` must be handled through `store_fn_arg`");
242240
} else if let PassMode::Cast(cast) = arg_abi.mode {
243-
panic!(
244-
"TODO: PassMode::Cast not implemented yet for store_arg: {:?}",
245-
cast
246-
);
241+
let cast_ty = cast.spirv_type(self);
242+
let cast_ptr_ty = SpirvType::Pointer {
243+
storage_class: StorageClass::Generic,
244+
pointee: cast_ty,
245+
}
246+
.def(self);
247+
let cast_dst = self.pointercast(dst.llval, cast_ptr_ty);
248+
self.store(val, cast_dst, arg_abi.layout.align.abi);
247249
} else {
248250
OperandValue::Immediate(val).store(self, dst);
249251
}

0 commit comments

Comments
 (0)