@@ -155,6 +155,9 @@ cache: struct {
155
155
void_type : ? IdRef = null ,
156
156
int_types : std .AutoHashMapUnmanaged (std.builtin.Type.Int , IdRef ) = .{},
157
157
float_types : std .AutoHashMapUnmanaged (std.builtin.Type.Float , IdRef ) = .{},
158
+ // This cache is required so that @Vector(X, u1) in direct representation has the
159
+ // same ID as @Vector(X, bool) in indirect representation.
160
+ vector_types : std .AutoHashMapUnmanaged (struct { IdRef , u32 }, IdRef ) = .{},
158
161
} = .{},
159
162
160
163
/// Set of Decls, referred to by Decl.Index.
@@ -194,6 +197,7 @@ pub fn deinit(self: *Module) void {
194
197
195
198
self .cache .int_types .deinit (self .gpa );
196
199
self .cache .float_types .deinit (self .gpa );
200
+ self .cache .vector_types .deinit (self .gpa );
197
201
198
202
self .decls .deinit (self .gpa );
199
203
self .decl_deps .deinit (self .gpa );
@@ -474,13 +478,17 @@ pub fn floatType(self: *Module, bits: u16) !IdRef {
474
478
}
475
479
476
480
pub fn vectorType (self : * Module , len : u32 , child_id : IdRef ) ! IdRef {
477
- const result_id = self .allocId ();
478
- try self .sections .types_globals_constants .emit (self .gpa , .OpTypeVector , .{
479
- .id_result = result_id ,
480
- .component_type = child_id ,
481
- .component_count = len ,
482
- });
483
- return result_id ;
481
+ const entry = try self .cache .vector_types .getOrPut (self .gpa , .{ child_id , len });
482
+ if (! entry .found_existing ) {
483
+ const result_id = self .allocId ();
484
+ entry .value_ptr .* = result_id ;
485
+ try self .sections .types_globals_constants .emit (self .gpa , .OpTypeVector , .{
486
+ .id_result = result_id ,
487
+ .component_type = child_id ,
488
+ .component_count = len ,
489
+ });
490
+ }
491
+ return entry .value_ptr .* ;
484
492
}
485
493
486
494
pub fn constUndef (self : * Module , ty_id : IdRef ) ! IdRef {
0 commit comments