authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2025-02-24 20:39:13+01:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2025-02-24 20:58:13+01:00
logfe5a78691fc3cebf8fcefa3498a4b594dbb28c65
tree69ad58cd94f28e6bffd05f1029695048e7bbeeeb
parentaec0f9b3e7790c2e3b66d519e4d8e438208b5406
signaturebadge-check Signed by SSH key SHA256:ZS52FNyUv2WUXvO4njmVaFVO46RHojFuOrxRc4LuKzg

spirv: get rid of function_types cache

This deep hash map doesn't work

1 files changed, 7 insertions(+), 26 deletions(-)

src/codegen/spirv/Module.zig+7-26
...@@ -21,19 +21,6 @@ const IdResultType = spec.IdResultType;...@@ -21,19 +21,6 @@ const IdResultType = spec.IdResultType;
2121
22const Section = @import("Section.zig");22const Section = @import("Section.zig");
2323
24/// Helper HashMap type to hash deeply
25fn DeepHashMap(K: type, V: type) type {
26 return std.HashMapUnmanaged(K, V, struct {
27 pub fn hash(ctx: @This(), key: K) u64 {
28 _ = ctx;
29 var hasher = Wyhash.init(0);
30 autoHashStrat(&hasher, key, .Deep);
31 return hasher.final();
32 }
33 pub const eql = std.hash_map.getAutoEqlFn(K, @This());
34 }, std.hash_map.default_max_load_percentage);
35}
36
37/// This structure represents a function that isc in-progress of being emitted.24/// This structure represents a function that isc in-progress of being emitted.
38/// Commonly, the contents of this structure will be merged with the appropriate25/// Commonly, the contents of this structure will be merged with the appropriate
39/// sections of the module and re-used. Note that the SPIR-V module system makes26/// sections of the module and re-used. Note that the SPIR-V module system makes
...@@ -181,7 +168,6 @@ cache: struct {...@@ -181,7 +168,6 @@ cache: struct {
181 // same ID as @Vector(X, bool) in indirect representation.168 // same ID as @Vector(X, bool) in indirect representation.
182 vector_types: std.AutoHashMapUnmanaged(struct { IdRef, u32 }, IdRef) = .empty,169 vector_types: std.AutoHashMapUnmanaged(struct { IdRef, u32 }, IdRef) = .empty,
183 array_types: std.AutoHashMapUnmanaged(struct { IdRef, IdRef }, IdRef) = .empty,170 array_types: std.AutoHashMapUnmanaged(struct { IdRef, IdRef }, IdRef) = .empty,
184 function_types: DeepHashMap(struct { IdRef, []const IdRef }, IdRef) = .empty,
185171
186 capabilities: std.AutoHashMapUnmanaged(spec.Capability, void) = .empty,172 capabilities: std.AutoHashMapUnmanaged(spec.Capability, void) = .empty,
187 extensions: std.StringHashMapUnmanaged(void) = .empty,173 extensions: std.StringHashMapUnmanaged(void) = .empty,
...@@ -241,7 +227,6 @@ pub fn deinit(self: *Module) void {...@@ -241,7 +227,6 @@ pub fn deinit(self: *Module) void {
241 self.cache.float_types.deinit(self.gpa);227 self.cache.float_types.deinit(self.gpa);
242 self.cache.vector_types.deinit(self.gpa);228 self.cache.vector_types.deinit(self.gpa);
243 self.cache.array_types.deinit(self.gpa);229 self.cache.array_types.deinit(self.gpa);
244 self.cache.function_types.deinit(self.gpa);
245 self.cache.capabilities.deinit(self.gpa);230 self.cache.capabilities.deinit(self.gpa);
246 self.cache.extensions.deinit(self.gpa);231 self.cache.extensions.deinit(self.gpa);
247 self.cache.extended_instruction_set.deinit(self.gpa);232 self.cache.extended_instruction_set.deinit(self.gpa);
...@@ -616,17 +601,13 @@ pub fn arrayType(self: *Module, len_id: IdRef, child_ty_id: IdRef) !IdRef {...@@ -616,17 +601,13 @@ pub fn arrayType(self: *Module, len_id: IdRef, child_ty_id: IdRef) !IdRef {
616}601}
617602
618pub fn functionType(self: *Module, return_ty_id: IdRef, param_type_ids: []const IdRef) !IdRef {603pub fn functionType(self: *Module, return_ty_id: IdRef, param_type_ids: []const IdRef) !IdRef {
619 const entry = try self.cache.function_types.getOrPut(self.gpa, .{ return_ty_id, param_type_ids });604 const result_id = self.allocId();
620 if (!entry.found_existing) {605 try self.sections.types_globals_constants.emit(self.gpa, .OpTypeFunction, .{
621 const result_id = self.allocId();606 .id_result = result_id,
622 entry.value_ptr.* = result_id;607 .return_type = return_ty_id,
623 try self.sections.types_globals_constants.emit(self.gpa, .OpTypeFunction, .{608 .id_ref_2 = param_type_ids,
624 .id_result = result_id,609 });
625 .return_type = return_ty_id,610 return result_id;
626 .id_ref_2 = param_type_ids,
627 });
628 }
629 return entry.value_ptr.*;
630}611}
631612
632pub fn constBool(self: *Module, value: bool) !IdRef {613pub fn constBool(self: *Module, value: bool) !IdRef {