aboutsummaryrefslogtreecommitdiff
path: root/src/arch
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2023-04-11 23:07:49 +0200
committerJakub Konka <kubkon@jakubkonka.com>2023-04-13 11:47:51 +0200
commit38d46a6764a63bfa17560b70c5e82831bd4aeba1 (patch)
tree03eb49acbba503a7806d78b3421fd4a7822ebb66 /src/arch
parentdbdf8086bd964cec22c44d41702d35643cce412a (diff)
downloadzig-38d46a6764a63bfa17560b70c5e82831bd4aeba1.tar.gz
zig-38d46a6764a63bfa17560b70c5e82831bd4aeba1.zip
x86_64: simplify genUnOpMir() when modifying value in memory
Diffstat (limited to 'src/arch')
-rw-r--r--src/arch/x86_64/CodeGen.zig20
1 files changed, 19 insertions, 1 deletions
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 }),