x86_64: simplify genSetStackArg() when storing value from memory

This commit is contained in:
Jakub Konka 2023-04-12 10:19:43 +02:00
parent 059ed062bc
commit 0abaf5f88a

View File

@ -7097,11 +7097,30 @@ fn genSetStackArg(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue) InnerE
return self.genSetStackArg(ty, stack_offset, MCValue{ .register = reg });
}
const addr_reg = try self.register_manager.allocReg(null, gp);
const addr_reg = (try self.register_manager.allocReg(null, gp)).to64();
const addr_lock = self.register_manager.lockRegAssumeUnused(addr_reg);
defer self.register_manager.unlockReg(addr_lock);
try self.loadMemPtrIntoRegister(addr_reg, Type.usize, mcv);
switch (mcv) {
.memory => |addr| try self.genSetReg(Type.usize, addr_reg, .{ .immediate = addr }),
.linker_load => |load_struct| {
const atom_index = if (self.bin_file.cast(link.File.MachO)) |macho_file| blk: {
const atom = try macho_file.getOrCreateAtomForDecl(self.mod_fn.owner_decl);
break :blk macho_file.getAtom(atom).getSymbolIndex().?;
} else if (self.bin_file.cast(link.File.Coff)) |coff_file| blk: {
const atom = try coff_file.getOrCreateAtomForDecl(self.mod_fn.owner_decl);
break :blk coff_file.getAtom(atom).getSymbolIndex().?;
} else unreachable;
switch (load_struct.type) {
.import => unreachable,
.got => try self.asmMovLinker(addr_reg, atom_index, load_struct),
.direct => try self.asmLeaLinker(addr_reg, atom_index, load_struct),
}
},
else => unreachable,
}
try self.genInlineMemcpy(
.{ .ptr_stack_offset = stack_offset },
.{ .register = addr_reg },