From c9a153c7978b363a252f83878f75bd875fe6ae5e Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Sat, 11 Mar 2023 09:29:53 +0100 Subject: [PATCH] x86_64: add .dead pseudo-instruction to mark an unused MIR instruction --- src/arch/x86_64/CodeGen.zig | 16 ++++++++-------- src/arch/x86_64/Emit.zig | 2 ++ src/arch/x86_64/Mir.zig | 4 ++++ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig index fabca1d848..feb78ca7fc 100644 --- a/src/arch/x86_64/CodeGen.zig +++ b/src/arch/x86_64/CodeGen.zig @@ -630,8 +630,8 @@ fn gen(self: *Self) InnerError!void { // TODO During semantic analysis, check if there are no function calls. If there // are none, here we can omit the part where we subtract and then add rsp. const backpatch_stack_sub = try self.addInst(.{ - .tag = .nop, - .ops = .none, + .tag = .dead, + .ops = undefined, .data = undefined, }); @@ -657,8 +657,8 @@ fn gen(self: *Self) InnerError!void { // Push callee-preserved regs that were used actually in use. const backpatch_push_callee_preserved_regs = try self.addInst(.{ - .tag = .nop, - .ops = .none, + .tag = .dead, + .ops = undefined, .data = undefined, }); @@ -688,8 +688,8 @@ fn gen(self: *Self) InnerError!void { // Pop saved callee-preserved regs. const backpatch_pop_callee_preserved_regs = try self.addInst(.{ - .tag = .nop, - .ops = .none, + .tag = .dead, + .ops = undefined, .data = undefined, }); @@ -701,8 +701,8 @@ fn gen(self: *Self) InnerError!void { // Maybe add rsp, x if required. This is backpatched later. const backpatch_stack_add = try self.addInst(.{ - .tag = .nop, - .ops = .none, + .tag = .dead, + .ops = undefined, .data = undefined, }); diff --git a/src/arch/x86_64/Emit.zig b/src/arch/x86_64/Emit.zig index 6e92e81882..161c436323 100644 --- a/src/arch/x86_64/Emit.zig +++ b/src/arch/x86_64/Emit.zig @@ -137,6 +137,8 @@ pub fn lowerMir(emit: *Emit) InnerError!void { .push_regs => try emit.mirPushPopRegisterList(.push, inst), .pop_regs => try emit.mirPushPopRegisterList(.pop, inst), + + .dead => {}, } } diff --git a/src/arch/x86_64/Mir.zig b/src/arch/x86_64/Mir.zig index 5de8ad1410..4cde4dd240 100644 --- a/src/arch/x86_64/Mir.zig +++ b/src/arch/x86_64/Mir.zig @@ -163,6 +163,10 @@ pub const Inst = struct { /// Pop registers /// Uses `payload` payload with data of type `SaveRegisterList`. pop_regs, + + /// Tombstone + /// Emitter should skip this instruction. + dead, }; pub const Ops = enum(u8) {