| ... | @@ -189,6 +189,9 @@ navs_exe: std.AutoArrayHashMapUnmanaged(InternPool.Nav.Index, ZcuDataExe) = .emp | ... | @@ -189,6 +189,9 @@ navs_exe: std.AutoArrayHashMapUnmanaged(InternPool.Nav.Index, ZcuDataExe) = .emp |
| 189 | uavs_obj: std.AutoArrayHashMapUnmanaged(InternPool.Index, ZcuDataObj) = .empty, | 189 | uavs_obj: std.AutoArrayHashMapUnmanaged(InternPool.Index, ZcuDataObj) = .empty, |
| 190 | /// Tracks ref count to optimize LEB encodings for UAV references. | 190 | /// Tracks ref count to optimize LEB encodings for UAV references. |
| 191 | uavs_exe: std.AutoArrayHashMapUnmanaged(InternPool.Index, ZcuDataExe) = .empty, | 191 | uavs_exe: std.AutoArrayHashMapUnmanaged(InternPool.Index, ZcuDataExe) = .empty, |
| | 192 | /// Sparse table of uavs that need to be emitted with greater alignment than |
| | 193 | /// the default for the type. |
| | 194 | overaligned_uavs: std.AutoArrayHashMapUnmanaged(InternPool.Index, Alignment) = .empty, |
| 192 | /// When the key is an enum type, this represents a `@tagName` function. | 195 | /// When the key is an enum type, this represents a `@tagName` function. |
| 193 | zcu_funcs: std.AutoArrayHashMapUnmanaged(InternPool.Index, ZcuFunc) = .empty, | 196 | zcu_funcs: std.AutoArrayHashMapUnmanaged(InternPool.Index, ZcuFunc) = .empty, |
| 194 | nav_exports: std.AutoArrayHashMapUnmanaged(NavExport, Zcu.Export.Index) = .empty, | 197 | nav_exports: std.AutoArrayHashMapUnmanaged(NavExport, Zcu.Export.Index) = .empty, |
| ... | @@ -1945,6 +1948,7 @@ pub const DataSegmentId = enum(u32) { | ... | @@ -1945,6 +1948,7 @@ pub const DataSegmentId = enum(u32) { |
| 1945 | const zcu = wasm.base.comp.zcu.?; | 1948 | const zcu = wasm.base.comp.zcu.?; |
| 1946 | const ip = &zcu.intern_pool; | 1949 | const ip = &zcu.intern_pool; |
| 1947 | const ip_index = i.key(wasm).*; | 1950 | const ip_index = i.key(wasm).*; |
| | 1951 | if (wasm.overaligned_uavs.get(ip_index)) |a| return a; |
| 1948 | const ty: Zcu.Type = .fromInterned(ip.typeOf(ip_index)); | 1952 | const ty: Zcu.Type = .fromInterned(ip.typeOf(ip_index)); |
| 1949 | const result = ty.abiAlignment(zcu); | 1953 | const result = ty.abiAlignment(zcu); |
| 1950 | assert(result != .none); | 1954 | assert(result != .none); |
| ... | @@ -3085,6 +3089,7 @@ pub fn deinit(wasm: *Wasm) void { | ... | @@ -3085,6 +3089,7 @@ pub fn deinit(wasm: *Wasm) void { |
| 3085 | wasm.navs_obj.deinit(gpa); | 3089 | wasm.navs_obj.deinit(gpa); |
| 3086 | wasm.uavs_exe.deinit(gpa); | 3090 | wasm.uavs_exe.deinit(gpa); |
| 3087 | wasm.uavs_obj.deinit(gpa); | 3091 | wasm.uavs_obj.deinit(gpa); |
| | 3092 | wasm.overaligned_uavs.deinit(gpa); |
| 3088 | wasm.zcu_funcs.deinit(gpa); | 3093 | wasm.zcu_funcs.deinit(gpa); |
| 3089 | wasm.nav_exports.deinit(gpa); | 3094 | wasm.nav_exports.deinit(gpa); |
| 3090 | wasm.uav_exports.deinit(gpa); | 3095 | wasm.uav_exports.deinit(gpa); |
| ... | @@ -4397,10 +4402,22 @@ pub fn symbolNameIndex(wasm: *Wasm, name: String) Allocator.Error!SymbolTableInd | ... | @@ -4397,10 +4402,22 @@ pub fn symbolNameIndex(wasm: *Wasm, name: String) Allocator.Error!SymbolTableInd |
| 4397 | return @enumFromInt(gop.index); | 4402 | return @enumFromInt(gop.index); |
| 4398 | } | 4403 | } |
| 4399 | | 4404 | |
| 4400 | pub fn refUavObj(wasm: *Wasm, ip_index: InternPool.Index) !UavsObjIndex { | 4405 | pub fn refUavObj(wasm: *Wasm, ip_index: InternPool.Index, orig_ptr_ty: InternPool.Index) !UavsObjIndex { |
| 4401 | const comp = wasm.base.comp; | 4406 | const comp = wasm.base.comp; |
| | 4407 | const zcu = comp.zcu.?; |
| | 4408 | const ip = &zcu.intern_pool; |
| 4402 | const gpa = comp.gpa; | 4409 | const gpa = comp.gpa; |
| 4403 | assert(comp.config.output_mode == .Obj); | 4410 | assert(comp.config.output_mode == .Obj); |
| | 4411 | |
| | 4412 | if (orig_ptr_ty != .none) { |
| | 4413 | const abi_alignment = Zcu.Type.fromInterned(ip.typeOf(ip_index)).abiAlignment(zcu); |
| | 4414 | const explicit_alignment = ip.indexToKey(orig_ptr_ty).ptr_type.flags.alignment; |
| | 4415 | if (explicit_alignment.compare(.gt, abi_alignment)) { |
| | 4416 | const gop = try wasm.overaligned_uavs.getOrPut(gpa, ip_index); |
| | 4417 | gop.value_ptr.* = if (gop.found_existing) gop.value_ptr.maxStrict(explicit_alignment) else explicit_alignment; |
| | 4418 | } |
| | 4419 | } |
| | 4420 | |
| 4404 | const gop = try wasm.uavs_obj.getOrPut(gpa, ip_index); | 4421 | const gop = try wasm.uavs_obj.getOrPut(gpa, ip_index); |
| 4405 | if (!gop.found_existing) gop.value_ptr.* = .{ | 4422 | if (!gop.found_existing) gop.value_ptr.* = .{ |
| 4406 | // Lowering the value is delayed to avoid recursion. | 4423 | // Lowering the value is delayed to avoid recursion. |
| ... | @@ -4410,10 +4427,22 @@ pub fn refUavObj(wasm: *Wasm, ip_index: InternPool.Index) !UavsObjIndex { | ... | @@ -4410,10 +4427,22 @@ pub fn refUavObj(wasm: *Wasm, ip_index: InternPool.Index) !UavsObjIndex { |
| 4410 | return @enumFromInt(gop.index); | 4427 | return @enumFromInt(gop.index); |
| 4411 | } | 4428 | } |
| 4412 | | 4429 | |
| 4413 | pub fn refUavExe(wasm: *Wasm, ip_index: InternPool.Index) !UavsExeIndex { | 4430 | pub fn refUavExe(wasm: *Wasm, ip_index: InternPool.Index, orig_ptr_ty: InternPool.Index) !UavsExeIndex { |
| 4414 | const comp = wasm.base.comp; | 4431 | const comp = wasm.base.comp; |
| | 4432 | const zcu = comp.zcu.?; |
| | 4433 | const ip = &zcu.intern_pool; |
| 4415 | const gpa = comp.gpa; | 4434 | const gpa = comp.gpa; |
| 4416 | assert(comp.config.output_mode != .Obj); | 4435 | assert(comp.config.output_mode != .Obj); |
| | 4436 | |
| | 4437 | if (orig_ptr_ty != .none) { |
| | 4438 | const abi_alignment = Zcu.Type.fromInterned(ip.typeOf(ip_index)).abiAlignment(zcu); |
| | 4439 | const explicit_alignment = ip.indexToKey(orig_ptr_ty).ptr_type.flags.alignment; |
| | 4440 | if (explicit_alignment.compare(.gt, abi_alignment)) { |
| | 4441 | const gop = try wasm.overaligned_uavs.getOrPut(gpa, ip_index); |
| | 4442 | gop.value_ptr.* = if (gop.found_existing) gop.value_ptr.maxStrict(explicit_alignment) else explicit_alignment; |
| | 4443 | } |
| | 4444 | } |
| | 4445 | |
| 4417 | const gop = try wasm.uavs_exe.getOrPut(gpa, ip_index); | 4446 | const gop = try wasm.uavs_exe.getOrPut(gpa, ip_index); |
| 4418 | if (gop.found_existing) { | 4447 | if (gop.found_existing) { |
| 4419 | gop.value_ptr.count += 1; | 4448 | gop.value_ptr.count += 1; |