zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 3df2f356eba9b0882ee3fa09704aae7dc173f3d4 (tree)
parent 2e23ddbe7ba48857fbdcf014da3251f1decca00d
Author: mlugg <mlugg@mlugg.co.uk>
Date:   Wed, 26 Apr 2023 01:43:55 +0100

Sema: avoid emitting sequential dbg_stmt instructions

Often, a `dbg_stmt` ends up being associated with no real code because
whatever it referred to was eliminated by semantic analysis. In these
cases, Sema can replace the last `dbg_stmt` with the new one to avoid
redundant AIR instructions which at best are nops and at worst cause
backends to emit useless info (e.g. CBE does this).

Diffstat:
Msrc/Sema.zig | 13+++++++++++++
1 file changed, 13 insertions(+), 0 deletions(-)

diff --git a/src/Sema.zig b/src/Sema.zig @@ -5852,6 +5852,19 @@ fn zirDbgStmt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi if (block.is_comptime or sema.mod.comp.bin_file.options.strip) return; const inst_data = sema.code.instructions.items(.data)[inst].dbg_stmt; + + if (block.instructions.items.len != 0) { + const idx = block.instructions.items[block.instructions.items.len - 1]; + if (sema.air_instructions.items(.tag)[idx] == .dbg_stmt) { + // The previous dbg_stmt didn't correspond to any actual code, so replace it. + sema.air_instructions.items(.data)[idx].dbg_stmt = .{ + .line = inst_data.line, + .column = inst_data.column, + }; + return; + } + } + _ = try block.addInst(.{ .tag = .dbg_stmt, .data = .{ .dbg_stmt = .{