Commit c9a153c797

Jakub Konka <kubkon@jakubkonka.com>
2023-03-11 09:29:53
x86_64: add .dead pseudo-instruction to mark an unused MIR instruction
1 parent 621fc36
Changed files (3)
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,
         });
 
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 => {},
         }
     }
 
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) {