| ... | @@ -21,19 +21,6 @@ const IdResultType = spec.IdResultType; | ... | @@ -21,19 +21,6 @@ const IdResultType = spec.IdResultType; |
| 21 | | 21 | |
| 22 | const Section = @import("Section.zig"); | 22 | const Section = @import("Section.zig"); |
| 23 | | 23 | |
| 24 | /// Helper HashMap type to hash deeply | | |
| 25 | fn 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 appropriate | 25 | /// 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 makes | 26 | /// 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, | | |
| 185 | | 171 | |
| 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 | } |
| 617 | | 602 | |
| 618 | pub fn functionType(self: *Module, return_ty_id: IdRef, param_type_ids: []const IdRef) !IdRef { | 603 | pub 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 | } |
| 631 | | 612 | |
| 632 | pub fn constBool(self: *Module, value: bool) !IdRef { | 613 | pub fn constBool(self: *Module, value: bool) !IdRef { |