x86_64: simplify store() logic when value is in memory

This commit is contained in:
Jakub Konka 2023-04-11 22:45:50 +02:00
parent ee6b4fad47
commit 397dd77697

View File

@ -3809,11 +3809,29 @@ fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type
try self.store(ptr, .{ .register = tmp_reg }, ptr_ty, value_ty);
} else {
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, value);
switch (value) {
.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,
.{ .register = addr_reg },