authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-03-24 14:41:13+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-03-24 17:02:29+01:00
log4e801c27839be3f7ff209aa0f22c158b6340c69b
tree66c9499178c60b04f80a30fb33f16710496770be
parent2286f9bd1f1c622d182e8b815864ad90d3ff0e92

x64: implement aggregate_init for structs


1 files changed, 21 insertions(+), 3 deletions(-)

src/arch/x86_64/CodeGen.zig+21-3
...@@ -5671,13 +5671,31 @@ fn airReduce(self: *Self, inst: Air.Inst.Index) !void {...@@ -5671,13 +5671,31 @@ fn airReduce(self: *Self, inst: Air.Inst.Index) !void {
5671}5671}
56725672
5673fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {5673fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
5674 const vector_ty = self.air.typeOfIndex(inst);5674 const result_ty = self.air.typeOfIndex(inst);
5675 const len = vector_ty.vectorLen();5675 const len = result_ty.vectorLen();
5676 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;5676 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
5677 const elements = @bitCast([]const Air.Inst.Ref, self.air.extra[ty_pl.payload..][0..len]);5677 const elements = @bitCast([]const Air.Inst.Ref, self.air.extra[ty_pl.payload..][0..len]);
5678 const abi_size = @intCast(u32, result_ty.abiSize(self.target.*));
5679 const abi_align = result_ty.abiAlignment(self.target.*);
5678 const result: MCValue = res: {5680 const result: MCValue = res: {
5679 if (self.liveness.isUnused(inst)) break :res MCValue.dead;5681 if (self.liveness.isUnused(inst)) break :res MCValue.dead;
5680 return self.fail("TODO implement airAggregateInit for x86_64", .{});5682 switch (result_ty.zigTypeTag()) {
5683 .Struct => {
5684 const stack_offset = @intCast(i32, try self.allocMem(inst, abi_size, abi_align));
5685 for (elements) |elem, elem_i| {
5686 if (result_ty.structFieldValueComptime(elem_i) != null) continue; // comptime elem
5687
5688 const elem_ty = result_ty.structFieldType(elem_i);
5689 const elem_off = result_ty.structFieldOffset(elem_i, self.target.*);
5690 const elem_mcv = try self.resolveInst(elem);
5691 try self.genSetStack(elem_ty, stack_offset - @intCast(i32, elem_off), elem_mcv, .{});
5692 }
5693 break :res MCValue{ .stack_offset = stack_offset };
5694 },
5695 .Array => return self.fail("TODO implement aggregate_init for arrays", .{}),
5696 .Vector => return self.fail("TODO implement aggregate_init for vectors", .{}),
5697 else => unreachable,
5698 }
5681 };5699 };
56825700
5683 if (elements.len <= Liveness.bpi - 1) {5701 if (elements.len <= Liveness.bpi - 1) {