From 38d46a6764a63bfa17560b70c5e82831bd4aeba1 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Tue, 11 Apr 2023 23:07:49 +0200 Subject: [PATCH] x86_64: simplify genUnOpMir() when modifying value in memory --- src/arch/x86_64/CodeGen.zig | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig index 4f68fff0de..c48172f39f 100644 --- a/src/arch/x86_64/CodeGen.zig +++ b/src/arch/x86_64/CodeGen.zig @@ -4228,7 +4228,25 @@ fn genUnOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MCValue const addr_reg_lock = self.register_manager.lockRegAssumeUnused(addr_reg); defer self.register_manager.unlockReg(addr_reg_lock); - try self.loadMemPtrIntoRegister(addr_reg, Type.usize, dst_mcv); + switch (dst_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.asmMemory( mir_tag, Memory.sib(Memory.PtrSize.fromSize(abi_size), .{ .base = addr_reg }),