authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-10-07 15:23:39+02:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-10-15 13:59:26+02:00
log31ad2d72a756b837b153ae63dfc0e6df608033b4
tree808bb2ce70edde3ad38a1110fcca6342326a8f05
parenta3d77bdba9f8c6c3a88cfdfc009e1fabff22d2eb
signaturebadge-check Signed by SSH key SHA256:CQ99aPxq+RueiL9u7z0FEki5Fm7V6T8q4PrEGmINrA4

spirv: use CacheString for source_file_names instead of []const u8


2 files changed, 8 insertions(+), 11 deletions(-)

src/codegen/spirv.zig+4-4
......@@ -3726,10 +3726,10 @@ pub const DeclGen = struct {
37263726
37273727 fn airDbgStmt(self: *DeclGen, inst: Air.Inst.Index) !void {
37283728 const dbg_stmt = self.air.instructions.items(.data)[inst].dbg_stmt;
3729 const src_fname_id = try self.spv.resolveSourceFileName(
3730 self.module,
3731 self.module.declPtr(self.decl_index),
3732 );
3729 const mod = self.module;
3730 const decl = mod.declPtr(self.decl_index);
3731 const path = decl.getFileScope(mod).sub_file_path;
3732 const src_fname_id = try self.spv.resolveSourceFileName(path);
37333733 const base_line = self.base_line_stack.getLast();
37343734 try self.func.body.emit(self.spv.gpa, .OpLine, .{
37353735 .file = src_fname_id,
src/codegen/spirv/Module.zig+4-7
......@@ -11,9 +11,6 @@ const std = @import("std");
1111const Allocator = std.mem.Allocator;
1212const assert = std.debug.assert;
1313
14const ZigModule = @import("../../Module.zig");
15const ZigDecl = ZigModule.Decl;
16
1714const spec = @import("spec.zig");
1815const Word = spec.Word;
1916const IdRef = spec.IdRef;
......@@ -147,7 +144,7 @@ next_result_id: Word,
147144/// Cache for results of OpString instructions for module file names fed to OpSource.
148145/// Since OpString is pretty much only used for those, we don't need to keep track of all strings,
149146/// just the ones for OpLine. Note that OpLine needs the result of OpString, and not that of OpSource.
150source_file_names: std.StringHashMapUnmanaged(IdRef) = .{},
147source_file_names: std.AutoArrayHashMapUnmanaged(CacheString, IdRef) = .{},
151148
152149/// SPIR-V type- and constant cache. This structure is used to store information about these in a more
153150/// efficient manner.
......@@ -460,9 +457,9 @@ pub fn addFunction(self: *Module, decl_index: Decl.Index, func: Fn) !void {
460457/// Fetch the result-id of an OpString instruction that encodes the path of the source
461458/// file of the decl. This function may also emit an OpSource with source-level information regarding
462459/// the decl.
463pub fn resolveSourceFileName(self: *Module, zig_module: *ZigModule, zig_decl: *ZigDecl) !IdRef {
464 const path = zig_decl.getFileScope(zig_module).sub_file_path;
465 const result = try self.source_file_names.getOrPut(self.gpa, path);
460pub fn resolveSourceFileName(self: *Module, path: []const u8) !IdRef {
461 const path_ref = try self.resolveString(path);
462 const result = try self.source_file_names.getOrPut(self.gpa, path_ref);
466463 if (!result.found_existing) {
467464 const file_result_id = self.allocId();
468465 result.value_ptr.* = file_result_id;