authorgravatar for joachim.schmidt557@outlook.comJoachim Schmidt <joachim.schmidt557@outlook.com> 2022-03-22 13:24:42+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-22 20:16:05-07:00
loga4e8294c91d21e6c574bbae94e064935d90e8e95
tree2070feeb07e23e754a3b35b18b611767e12326a4
parent6ac04d8fd7d63dfd4aa611e1564f1d4768baf408

stage2 ARM: change semantics of MCValue.stack_argument_offset

MCValue.stack_argument_offset now has the same semantics as MCValue.stack_offset

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

src/arch/arm/CodeGen.zig+21-32
......@@ -1348,7 +1348,7 @@ fn slicePtr(self: *Self, mcv: MCValue) !MCValue {
13481348 .dead, .unreach => unreachable,
13491349 .register => unreachable, // a slice doesn't fit in one register
13501350 .stack_argument_offset => |off| {
1351 return MCValue{ .stack_argument_offset = off + 4 };
1351 return MCValue{ .stack_argument_offset = off };
13521352 },
13531353 .stack_offset => |off| {
13541354 return MCValue{ .stack_offset = off };
......@@ -1377,7 +1377,7 @@ fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void {
13771377 .dead, .unreach => unreachable,
13781378 .register => unreachable, // a slice doesn't fit in one register
13791379 .stack_argument_offset => |off| {
1380 break :result MCValue{ .stack_argument_offset = off };
1380 break :result MCValue{ .stack_argument_offset = off - 4 };
13811381 },
13821382 .stack_offset => |off| {
13831383 break :result MCValue{ .stack_offset = off - 4 };
......@@ -1782,14 +1782,12 @@ fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type
17821782 try self.genSetReg(ptr_ty, src_reg, .{ .ptr_stack_offset = off });
17831783 },
17841784 .memory => |addr| try self.genSetReg(Type.usize, src_reg, .{ .immediate = @intCast(u32, addr) }),
1785 .stack_argument_offset => |unadjusted_off| {
1786 const adj_off = unadjusted_off + elem_size;
1787
1785 .stack_argument_offset => |off| {
17881786 _ = try self.addInst(.{
17891787 .tag = .ldr_ptr_stack_argument,
17901788 .data = .{ .r_stack_offset = .{
17911789 .rt = src_reg,
1792 .stack_offset = adj_off,
1790 .stack_offset = off,
17931791 } },
17941792 });
17951793 },
......@@ -1884,22 +1882,18 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
18841882 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
18851883 const mcv = try self.resolveInst(operand);
18861884 const struct_ty = self.air.typeOf(operand);
1887 const struct_size = @intCast(u32, struct_ty.abiSize(self.target.*));
18881885 const struct_field_offset = @intCast(u32, struct_ty.structFieldOffset(index, self.target.*));
1889 const struct_field_ty = struct_ty.structFieldType(index);
1890 const struct_field_size = @intCast(u32, struct_field_ty.abiSize(self.target.*));
1891 const adjusted_field_offset = struct_size - struct_field_offset - struct_field_size;
18921886
18931887 switch (mcv) {
18941888 .dead, .unreach => unreachable,
18951889 .stack_argument_offset => |off| {
1896 break :result MCValue{ .stack_argument_offset = off + adjusted_field_offset };
1890 break :result MCValue{ .stack_argument_offset = off - struct_field_offset };
18971891 },
18981892 .stack_offset => |off| {
18991893 break :result MCValue{ .stack_offset = off - struct_field_offset };
19001894 },
19011895 .memory => |addr| {
1902 break :result MCValue{ .memory = addr + adjusted_field_offset };
1896 break :result MCValue{ .memory = addr + struct_field_offset };
19031897 },
19041898 else => return self.fail("TODO implement codegen struct_field_val for {}", .{mcv}),
19051899 }
......@@ -3683,14 +3677,12 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
36833677 try self.genSetReg(ptr_ty, src_reg, .{ .ptr_stack_offset = off });
36843678 },
36853679 .memory => |addr| try self.genSetReg(ptr_ty, src_reg, .{ .immediate = @intCast(u32, addr) }),
3686 .stack_argument_offset => |unadjusted_off| {
3687 const adj_off = unadjusted_off + abi_size;
3688
3680 .stack_argument_offset => |off| {
36893681 _ = try self.addInst(.{
36903682 .tag = .ldr_ptr_stack_argument,
36913683 .data = .{ .r_stack_offset = .{
36923684 .rt = src_reg,
3693 .stack_offset = adj_off,
3685 .stack_offset = off,
36943686 } },
36953687 });
36963688 },
......@@ -3948,9 +3940,8 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
39483940 });
39493941 }
39503942 },
3951 .stack_argument_offset => |unadjusted_off| {
3943 .stack_argument_offset => |off| {
39523944 const abi_size = ty.abiSize(self.target.*);
3953 const adj_off = unadjusted_off + abi_size;
39543945
39553946 const tag: Mir.Inst.Tag = switch (abi_size) {
39563947 1 => if (ty.isSignedInt()) Mir.Inst.Tag.ldrsb_stack_argument else .ldrb_stack_argument,
......@@ -3963,7 +3954,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
39633954 .tag = tag,
39643955 .data = .{ .r_stack_offset = .{
39653956 .rt = reg,
3966 .stack_offset = @intCast(u32, adj_off),
3957 .stack_offset = off,
39673958 } },
39683959 });
39693960 },
......@@ -3979,7 +3970,7 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I
39793970 if (!self.wantSafety())
39803971 return; // The already existing value will do just fine.
39813972 // TODO Upgrade this to a memset call when we have that available.
3982 switch (ty.abiSize(self.target.*)) {
3973 switch (abi_size) {
39833974 1 => return self.genSetStackArgument(ty, stack_offset, .{ .immediate = 0xaa }),
39843975 2 => return self.genSetStackArgument(ty, stack_offset, .{ .immediate = 0xaaaa }),
39853976 4 => return self.genSetStackArgument(ty, stack_offset, .{ .immediate = 0xaaaaaaaa }),
......@@ -3987,13 +3978,11 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I
39873978 }
39883979 },
39893980 .register => |reg| {
3990 const adj_off = stack_offset - abi_size;
3991
39923981 switch (abi_size) {
39933982 1, 4 => {
3994 const offset = if (math.cast(u12, adj_off)) |imm| blk: {
3983 const offset = if (math.cast(u12, stack_offset)) |imm| blk: {
39953984 break :blk Instruction.Offset.imm(imm);
3996 } else |_| Instruction.Offset.reg(try self.copyToTmpRegister(Type.initTag(.u32), MCValue{ .immediate = adj_off }), .none);
3985 } else |_| Instruction.Offset.reg(try self.copyToTmpRegister(Type.initTag(.u32), MCValue{ .immediate = stack_offset }), .none);
39973986
39983987 const tag: Mir.Inst.Tag = switch (abi_size) {
39993988 1 => .strb,
......@@ -4011,9 +4000,9 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I
40114000 });
40124001 },
40134002 2 => {
4014 const offset = if (adj_off <= math.maxInt(u8)) blk: {
4015 break :blk Instruction.ExtraLoadStoreOffset.imm(@intCast(u8, adj_off));
4016 } else Instruction.ExtraLoadStoreOffset.reg(try self.copyToTmpRegister(Type.initTag(.u32), MCValue{ .immediate = adj_off }));
4003 const offset = if (stack_offset <= math.maxInt(u8)) blk: {
4004 break :blk Instruction.ExtraLoadStoreOffset.imm(@intCast(u8, stack_offset));
4005 } else Instruction.ExtraLoadStoreOffset.reg(try self.copyToTmpRegister(Type.initTag(.u32), MCValue{ .immediate = stack_offset }));
40174006
40184007 _ = try self.addInst(.{
40194008 .tag = .strh,
......@@ -4060,8 +4049,7 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I
40604049 }
40614050
40624051 // add dst_reg, sp, #stack_offset
4063 const adj_dst_offset = stack_offset - abi_size;
4064 const dst_offset_op: Instruction.Operand = if (Instruction.Operand.fromU32(adj_dst_offset)) |x| x else {
4052 const dst_offset_op: Instruction.Operand = if (Instruction.Operand.fromU32(stack_offset)) |x| x else {
40654053 return self.fail("TODO load: set reg to stack offset with all possible offsets", .{});
40664054 };
40674055 _ = try self.addInst(.{
......@@ -4553,8 +4541,8 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
45534541 if (ty.abiAlignment(self.target.*) == 8)
45544542 nsaa = std.mem.alignForwardGeneric(u32, nsaa, 8);
45554543
4556 result.args[i] = .{ .stack_argument_offset = nsaa };
45574544 nsaa += param_size;
4545 result.args[i] = .{ .stack_argument_offset = nsaa };
45584546 }
45594547 }
45604548
......@@ -4583,9 +4571,10 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
45834571
45844572 for (param_types) |ty, i| {
45854573 if (ty.abiSize(self.target.*) > 0) {
4586 stack_offset = std.mem.alignForwardGeneric(u32, stack_offset, ty.abiAlignment(self.target.*));
4574 const param_size = @intCast(u32, ty.abiSize(self.target.*));
4575
4576 stack_offset = std.mem.alignForwardGeneric(u32, stack_offset, ty.abiAlignment(self.target.*)) + param_size;
45874577 result.args[i] = .{ .stack_argument_offset = stack_offset };
4588 stack_offset += @intCast(u32, ty.abiSize(self.target.*));
45894578 } else {
45904579 result.args[i] = .{ .none = {} };
45914580 }