| ... | ... | @@ -21,19 +21,6 @@ const IdResultType = spec.IdResultType; |
| 21 | 21 | |
| 22 | 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 | 24 | /// This structure represents a function that isc in-progress of being emitted. |
| 38 | 25 | /// Commonly, the contents of this structure will be merged with the appropriate |
| 39 | 26 | /// sections of the module and re-used. Note that the SPIR-V module system makes |
| ... | ... | @@ -181,7 +168,6 @@ cache: struct { |
| 181 | 168 | // same ID as @Vector(X, bool) in indirect representation. |
| 182 | 169 | vector_types: std.AutoHashMapUnmanaged(struct { IdRef, u32 }, IdRef) = .empty, |
| 183 | 170 | array_types: std.AutoHashMapUnmanaged(struct { IdRef, IdRef }, IdRef) = .empty, |
| 184 | | function_types: DeepHashMap(struct { IdRef, []const IdRef }, IdRef) = .empty, |
| 185 | 171 | |
| 186 | 172 | capabilities: std.AutoHashMapUnmanaged(spec.Capability, void) = .empty, |
| 187 | 173 | extensions: std.StringHashMapUnmanaged(void) = .empty, |
| ... | ... | @@ -241,7 +227,6 @@ pub fn deinit(self: *Module) void { |
| 241 | 227 | self.cache.float_types.deinit(self.gpa); |
| 242 | 228 | self.cache.vector_types.deinit(self.gpa); |
| 243 | 229 | self.cache.array_types.deinit(self.gpa); |
| 244 | | self.cache.function_types.deinit(self.gpa); |
| 245 | 230 | self.cache.capabilities.deinit(self.gpa); |
| 246 | 231 | self.cache.extensions.deinit(self.gpa); |
| 247 | 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 | 601 | } |
| 617 | 602 | |
| 618 | 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 }); |
| 620 | | if (!entry.found_existing) { |
| 621 | | const result_id = self.allocId(); |
| 622 | | entry.value_ptr.* = result_id; |
| 623 | | try self.sections.types_globals_constants.emit(self.gpa, .OpTypeFunction, .{ |
| 624 | | .id_result = result_id, |
| 625 | | .return_type = return_ty_id, |
| 626 | | .id_ref_2 = param_type_ids, |
| 627 | | }); |
| 628 | | } |
| 629 | | return entry.value_ptr.*; |
| 604 | const result_id = self.allocId(); |
| 605 | try self.sections.types_globals_constants.emit(self.gpa, .OpTypeFunction, .{ |
| 606 | .id_result = result_id, |
| 607 | .return_type = return_ty_id, |
| 608 | .id_ref_2 = param_type_ids, |
| 609 | }); |
| 610 | return result_id; |
| 630 | 611 | } |
| 631 | 612 | |
| 632 | 613 | pub fn constBool(self: *Module, value: bool) !IdRef { |