diff options
Diffstat (limited to 'src/compile.zig')
-rw-r--r-- | src/compile.zig | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/compile.zig b/src/compile.zig index 0ce170c..3ee3eb0 100644 --- a/src/compile.zig +++ b/src/compile.zig @@ -94,6 +94,7 @@ pub const BasicBlock = struct { instrs: std.ArrayListUnmanaged(Instr) = .empty, vreg_last_use: std.AutoHashMapUnmanaged(VReg, usize) = .empty, + vreg_used_during_call: std.AutoHashMapUnmanaged(VReg, void) = .empty, fn finalize(self: *BasicBlock, allocator: Allocator) !void { std.debug.assert(self.instrs.items.len > 0); @@ -102,11 +103,18 @@ pub const BasicBlock = struct { }); self.vreg_last_use = .empty; + var set_at: std.AutoHashMapUnmanaged(VReg, usize) = .empty; + var last_call: usize = 0; for (0.., self.instrs.items) |i, instr| { - for (instr.sources().slice()) |src| - try self.vreg_last_use.put(allocator, src, i); - if (instr.dest()) |dest| + if (instr.dest()) |dest| { try self.vreg_last_use.put(allocator, dest, i); + try set_at.put(allocator, dest, i); + } + for (instr.sources().slice()) |src| { + try self.vreg_last_use.put(allocator, src, i); + if (set_at.get(src).? < last_call) try self.vreg_used_during_call.put(allocator, src, {}); + } + if (instr.type == .call) last_call = i; } } |