spirv: air slice

This commit is contained in:
Robin Voetter 2023-09-19 23:32:49 +02:00 committed by Andrew Kelley
parent 8895025688
commit a75300c8d8

View File

@ -1683,6 +1683,7 @@ pub const DeclGen = struct {
.not => try self.airNot(inst),
.array_to_slice => try self.airArrayToSlice(inst),
.slice => try self.airSlice(inst),
.aggregate_init => try self.airAggregateInit(inst),
.slice_ptr => try self.airSliceField(inst, 0),
@ -2462,6 +2463,22 @@ pub const DeclGen = struct {
return try self.constructStruct(slice_ty_ref, &.{ elem_ptr_id, len_id });
}
fn airSlice(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
if (self.liveness.isUnused(inst)) return null;
const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
const ptr_id = try self.resolve(bin_op.lhs);
const len_id = try self.resolve(bin_op.rhs);
const slice_ty = self.typeOfIndex(inst);
const slice_ty_ref = try self.resolveType(slice_ty, .direct);
return try self.constructStruct(slice_ty_ref, &.{
ptr_id, // Note: Type should not need to be converted to direct.
len_id, // Note: Type should not need to be converted to direct.
});
}
fn airAggregateInit(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
if (self.liveness.isUnused(inst)) return null;