spirv: get rid of function_types cache

This deep hash map doesn't work
This commit is contained in:
Robin Voetter 2025-02-24 20:39:13 +01:00
parent aec0f9b3e7
commit fe5a78691f
No known key found for this signature in database

View File

@ -21,19 +21,6 @@ const IdResultType = spec.IdResultType;
const Section = @import("Section.zig"); const Section = @import("Section.zig");
/// Helper HashMap type to hash deeply
fn DeepHashMap(K: type, V: type) type {
return std.HashMapUnmanaged(K, V, struct {
pub fn hash(ctx: @This(), key: K) u64 {
_ = ctx;
var hasher = Wyhash.init(0);
autoHashStrat(&hasher, key, .Deep);
return hasher.final();
}
pub const eql = std.hash_map.getAutoEqlFn(K, @This());
}, std.hash_map.default_max_load_percentage);
}
/// This structure represents a function that isc in-progress of being emitted. /// This structure represents a function that isc in-progress of being emitted.
/// Commonly, the contents of this structure will be merged with the appropriate /// Commonly, the contents of this structure will be merged with the appropriate
/// sections of the module and re-used. Note that the SPIR-V module system makes /// sections of the module and re-used. Note that the SPIR-V module system makes
@ -181,7 +168,6 @@ cache: struct {
// same ID as @Vector(X, bool) in indirect representation. // same ID as @Vector(X, bool) in indirect representation.
vector_types: std.AutoHashMapUnmanaged(struct { IdRef, u32 }, IdRef) = .empty, vector_types: std.AutoHashMapUnmanaged(struct { IdRef, u32 }, IdRef) = .empty,
array_types: std.AutoHashMapUnmanaged(struct { IdRef, IdRef }, IdRef) = .empty, array_types: std.AutoHashMapUnmanaged(struct { IdRef, IdRef }, IdRef) = .empty,
function_types: DeepHashMap(struct { IdRef, []const IdRef }, IdRef) = .empty,
capabilities: std.AutoHashMapUnmanaged(spec.Capability, void) = .empty, capabilities: std.AutoHashMapUnmanaged(spec.Capability, void) = .empty,
extensions: std.StringHashMapUnmanaged(void) = .empty, extensions: std.StringHashMapUnmanaged(void) = .empty,
@ -241,7 +227,6 @@ pub fn deinit(self: *Module) void {
self.cache.float_types.deinit(self.gpa); self.cache.float_types.deinit(self.gpa);
self.cache.vector_types.deinit(self.gpa); self.cache.vector_types.deinit(self.gpa);
self.cache.array_types.deinit(self.gpa); self.cache.array_types.deinit(self.gpa);
self.cache.function_types.deinit(self.gpa);
self.cache.capabilities.deinit(self.gpa); self.cache.capabilities.deinit(self.gpa);
self.cache.extensions.deinit(self.gpa); self.cache.extensions.deinit(self.gpa);
self.cache.extended_instruction_set.deinit(self.gpa); 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 {
} }
pub fn functionType(self: *Module, return_ty_id: IdRef, param_type_ids: []const IdRef) !IdRef { pub fn functionType(self: *Module, return_ty_id: IdRef, param_type_ids: []const IdRef) !IdRef {
const entry = try self.cache.function_types.getOrPut(self.gpa, .{ return_ty_id, param_type_ids }); const result_id = self.allocId();
if (!entry.found_existing) { try self.sections.types_globals_constants.emit(self.gpa, .OpTypeFunction, .{
const result_id = self.allocId(); .id_result = result_id,
entry.value_ptr.* = result_id; .return_type = return_ty_id,
try self.sections.types_globals_constants.emit(self.gpa, .OpTypeFunction, .{ .id_ref_2 = param_type_ids,
.id_result = result_id, });
.return_type = return_ty_id, return result_id;
.id_ref_2 = param_type_ids,
});
}
return entry.value_ptr.*;
} }
pub fn constBool(self: *Module, value: bool) !IdRef { pub fn constBool(self: *Module, value: bool) !IdRef {