| ... | @@ -332,7 +332,7 @@ pub fn generate( | ... | @@ -332,7 +332,7 @@ pub fn generate( |
| 332 | }; | 332 | }; |
| 333 | | 333 | |
| 334 | for (function.dbg_arg_relocs.items) |reloc| { | 334 | for (function.dbg_arg_relocs.items) |reloc| { |
| 335 | try function.genArgDbgInfo(reloc.inst, reloc.index, call_info.stack_byte_count); | 335 | try function.genArgDbgInfo(reloc.inst, reloc.index); |
| 336 | } | 336 | } |
| 337 | | 337 | |
| 338 | var mir = Mir{ | 338 | var mir = Mir{ |
| ... | @@ -351,7 +351,8 @@ pub fn generate( | ... | @@ -351,7 +351,8 @@ pub fn generate( |
| 351 | .prev_di_pc = 0, | 351 | .prev_di_pc = 0, |
| 352 | .prev_di_line = module_fn.lbrace_line, | 352 | .prev_di_line = module_fn.lbrace_line, |
| 353 | .prev_di_column = module_fn.lbrace_column, | 353 | .prev_di_column = module_fn.lbrace_column, |
| 354 | .prologue_stack_space = call_info.stack_byte_count + function.saved_regs_stack_space, | 354 | .stack_size = function.max_end_stack, |
| | 355 | .saved_regs_stack_space = function.saved_regs_stack_space, |
| 355 | }; | 356 | }; |
| 356 | defer emit.deinit(); | 357 | defer emit.deinit(); |
| 357 | | 358 | |
| ... | @@ -464,6 +465,7 @@ fn gen(self: *Self) !void { | ... | @@ -464,6 +465,7 @@ fn gen(self: *Self) !void { |
| 464 | const total_stack_size = self.max_end_stack + self.saved_regs_stack_space; | 465 | const total_stack_size = self.max_end_stack + self.saved_regs_stack_space; |
| 465 | const aligned_total_stack_end = mem.alignForwardGeneric(u32, total_stack_size, self.stack_align); | 466 | const aligned_total_stack_end = mem.alignForwardGeneric(u32, total_stack_size, self.stack_align); |
| 466 | const stack_size = aligned_total_stack_end - self.saved_regs_stack_space; | 467 | const stack_size = aligned_total_stack_end - self.saved_regs_stack_space; |
| | 468 | self.max_end_stack = stack_size; |
| 467 | if (Instruction.Operand.fromU32(stack_size)) |op| { | 469 | if (Instruction.Operand.fromU32(stack_size)) |op| { |
| 468 | self.mir_instructions.set(sub_reloc, .{ | 470 | self.mir_instructions.set(sub_reloc, .{ |
| 469 | .tag = .sub, | 471 | .tag = .sub, |
| ... | @@ -1812,7 +1814,7 @@ fn errUnionErr(self: *Self, error_union_mcv: MCValue, error_union_ty: Type) !MCV | ... | @@ -1812,7 +1814,7 @@ fn errUnionErr(self: *Self, error_union_mcv: MCValue, error_union_ty: Type) !MCV |
| 1812 | switch (error_union_mcv) { | 1814 | switch (error_union_mcv) { |
| 1813 | .register => return self.fail("TODO errUnionErr for registers", .{}), | 1815 | .register => return self.fail("TODO errUnionErr for registers", .{}), |
| 1814 | .stack_argument_offset => |off| { | 1816 | .stack_argument_offset => |off| { |
| 1815 | return MCValue{ .stack_argument_offset = off - err_offset }; | 1817 | return MCValue{ .stack_argument_offset = off + err_offset }; |
| 1816 | }, | 1818 | }, |
| 1817 | .stack_offset => |off| { | 1819 | .stack_offset => |off| { |
| 1818 | return MCValue{ .stack_offset = off - err_offset }; | 1820 | return MCValue{ .stack_offset = off - err_offset }; |
| ... | @@ -1849,7 +1851,7 @@ fn errUnionPayload(self: *Self, error_union_mcv: MCValue, error_union_ty: Type) | ... | @@ -1849,7 +1851,7 @@ fn errUnionPayload(self: *Self, error_union_mcv: MCValue, error_union_ty: Type) |
| 1849 | switch (error_union_mcv) { | 1851 | switch (error_union_mcv) { |
| 1850 | .register => return self.fail("TODO errUnionPayload for registers", .{}), | 1852 | .register => return self.fail("TODO errUnionPayload for registers", .{}), |
| 1851 | .stack_argument_offset => |off| { | 1853 | .stack_argument_offset => |off| { |
| 1852 | return MCValue{ .stack_argument_offset = off - payload_offset }; | 1854 | return MCValue{ .stack_argument_offset = off + payload_offset }; |
| 1853 | }, | 1855 | }, |
| 1854 | .stack_offset => |off| { | 1856 | .stack_offset => |off| { |
| 1855 | return MCValue{ .stack_offset = off - payload_offset }; | 1857 | return MCValue{ .stack_offset = off - payload_offset }; |
| ... | @@ -1983,7 +1985,7 @@ fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -1983,7 +1985,7 @@ fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void { |
| 1983 | .dead, .unreach => unreachable, | 1985 | .dead, .unreach => unreachable, |
| 1984 | .register => unreachable, // a slice doesn't fit in one register | 1986 | .register => unreachable, // a slice doesn't fit in one register |
| 1985 | .stack_argument_offset => |off| { | 1987 | .stack_argument_offset => |off| { |
| 1986 | break :result MCValue{ .stack_argument_offset = off - 4 }; | 1988 | break :result MCValue{ .stack_argument_offset = off + 4 }; |
| 1987 | }, | 1989 | }, |
| 1988 | .stack_offset => |off| { | 1990 | .stack_offset => |off| { |
| 1989 | break :result MCValue{ .stack_offset = off - 4 }; | 1991 | break :result MCValue{ .stack_offset = off - 4 }; |
| ... | @@ -2507,7 +2509,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -2507,7 +2509,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void { |
| 2507 | switch (mcv) { | 2509 | switch (mcv) { |
| 2508 | .dead, .unreach => unreachable, | 2510 | .dead, .unreach => unreachable, |
| 2509 | .stack_argument_offset => |off| { | 2511 | .stack_argument_offset => |off| { |
| 2510 | break :result MCValue{ .stack_argument_offset = off - struct_field_offset }; | 2512 | break :result MCValue{ .stack_argument_offset = off + struct_field_offset }; |
| 2511 | }, | 2513 | }, |
| 2512 | .stack_offset => |off| { | 2514 | .stack_offset => |off| { |
| 2513 | break :result MCValue{ .stack_offset = off - struct_field_offset }; | 2515 | break :result MCValue{ .stack_offset = off - struct_field_offset }; |
| ... | @@ -3369,9 +3371,7 @@ fn addDbgInfoTypeReloc(self: *Self, ty: Type) error{OutOfMemory}!void { | ... | @@ -3369,9 +3371,7 @@ fn addDbgInfoTypeReloc(self: *Self, ty: Type) error{OutOfMemory}!void { |
| 3369 | } | 3371 | } |
| 3370 | } | 3372 | } |
| 3371 | | 3373 | |
| 3372 | fn genArgDbgInfo(self: *Self, inst: Air.Inst.Index, arg_index: u32, stack_byte_count: u32) error{OutOfMemory}!void { | 3374 | fn genArgDbgInfo(self: *Self, inst: Air.Inst.Index, arg_index: u32) error{OutOfMemory}!void { |
| 3373 | const prologue_stack_space = stack_byte_count + self.saved_regs_stack_space; | | |
| 3374 | | | |
| 3375 | const mcv = self.args[arg_index]; | 3375 | const mcv = self.args[arg_index]; |
| 3376 | const ty = self.air.instructions.items(.data)[inst].ty; | 3376 | const ty = self.air.instructions.items(.data)[inst].ty; |
| 3377 | const name = self.mod_fn.getParamName(self.bin_file.options.module.?, arg_index); | 3377 | const name = self.mod_fn.getParamName(self.bin_file.options.module.?, arg_index); |
| ... | @@ -3404,7 +3404,7 @@ fn genArgDbgInfo(self: *Self, inst: Air.Inst.Index, arg_index: u32, stack_byte_c | ... | @@ -3404,7 +3404,7 @@ fn genArgDbgInfo(self: *Self, inst: Air.Inst.Index, arg_index: u32, stack_byte_c |
| 3404 | // const abi_size = @intCast(u32, ty.abiSize(self.target.*)); | 3404 | // const abi_size = @intCast(u32, ty.abiSize(self.target.*)); |
| 3405 | const adjusted_stack_offset = switch (mcv) { | 3405 | const adjusted_stack_offset = switch (mcv) { |
| 3406 | .stack_offset => |offset| -@intCast(i32, offset), | 3406 | .stack_offset => |offset| -@intCast(i32, offset), |
| 3407 | .stack_argument_offset => |offset| @intCast(i32, prologue_stack_space - offset), | 3407 | .stack_argument_offset => |offset| @intCast(i32, self.saved_regs_stack_space + offset), |
| 3408 | else => unreachable, | 3408 | else => unreachable, |
| 3409 | }; | 3409 | }; |
| 3410 | | 3410 | |
| ... | @@ -3559,7 +3559,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallOptions. | ... | @@ -3559,7 +3559,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallOptions. |
| 3559 | .stack_offset => unreachable, | 3559 | .stack_offset => unreachable, |
| 3560 | .stack_argument_offset => |offset| try self.genSetStackArgument( | 3560 | .stack_argument_offset => |offset| try self.genSetStackArgument( |
| 3561 | arg_ty, | 3561 | arg_ty, |
| 3562 | info.stack_byte_count - offset, | 3562 | offset, |
| 3563 | arg_mcv, | 3563 | arg_mcv, |
| 3564 | ), | 3564 | ), |
| 3565 | else => unreachable, | 3565 | else => unreachable, |
| ... | @@ -5653,8 +5653,8 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { | ... | @@ -5653,8 +5653,8 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { |
| 5653 | if (ty.abiAlignment(self.target.*) == 8) | 5653 | if (ty.abiAlignment(self.target.*) == 8) |
| 5654 | nsaa = std.mem.alignForwardGeneric(u32, nsaa, 8); | 5654 | nsaa = std.mem.alignForwardGeneric(u32, nsaa, 8); |
| 5655 | | 5655 | |
| 5656 | nsaa += param_size; | | |
| 5657 | result.args[i] = .{ .stack_argument_offset = nsaa }; | 5656 | result.args[i] = .{ .stack_argument_offset = nsaa }; |
| | 5657 | nsaa += param_size; |
| 5658 | } | 5658 | } |
| 5659 | } | 5659 | } |
| 5660 | | 5660 | |
| ... | @@ -5687,9 +5687,11 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { | ... | @@ -5687,9 +5687,11 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { |
| 5687 | for (param_types) |ty, i| { | 5687 | for (param_types) |ty, i| { |
| 5688 | if (ty.abiSize(self.target.*) > 0) { | 5688 | if (ty.abiSize(self.target.*) > 0) { |
| 5689 | const param_size = @intCast(u32, ty.abiSize(self.target.*)); | 5689 | const param_size = @intCast(u32, ty.abiSize(self.target.*)); |
| | 5690 | const param_alignment = ty.abiAlignment(self.target.*); |
| 5690 | | 5691 | |
| 5691 | stack_offset = std.mem.alignForwardGeneric(u32, stack_offset, ty.abiAlignment(self.target.*)) + param_size; | 5692 | stack_offset = std.mem.alignForwardGeneric(u32, stack_offset, param_alignment); |
| 5692 | result.args[i] = .{ .stack_argument_offset = stack_offset }; | 5693 | result.args[i] = .{ .stack_argument_offset = stack_offset }; |
| | 5694 | stack_offset += param_size; |
| 5693 | } else { | 5695 | } else { |
| 5694 | result.args[i] = .{ .none = {} }; | 5696 | result.args[i] = .{ .none = {} }; |
| 5695 | } | 5697 | } |