| ... | ... | @@ -271,7 +271,8 @@ pub const Function = struct { |
| 271 | 271 | /// the locals within so that it can be used to render the block of |
| 272 | 272 | /// variable declarations at the top of a function, sorted descending by |
| 273 | 273 | /// type alignment. |
| 274 | | allocs: std.AutoArrayHashMapUnmanaged(LocalIndex, void) = .{}, |
| 274 | /// The value is whether the alloc is static or not. |
| 275 | allocs: std.AutoArrayHashMapUnmanaged(LocalIndex, bool) = .{}, |
| 275 | 276 | /// Needed for memory used by Type objects used as keys in free_locals. |
| 276 | 277 | arena: std.heap.ArenaAllocator, |
| 277 | 278 | |
| ... | ... | @@ -290,6 +291,8 @@ pub const Function = struct { |
| 290 | 291 | const writer = f.object.code_header.writer(); |
| 291 | 292 | const alignment = 0; |
| 292 | 293 | const decl_c_value = try f.allocLocalValue(ty, alignment); |
| 294 | const gpa = f.object.dg.gpa; |
| 295 | try f.allocs.put(gpa, decl_c_value.local, true); |
| 293 | 296 | try writer.writeAll("static "); |
| 294 | 297 | try f.object.dg.renderTypeAndName(writer, ty, decl_c_value, .Const, alignment, .Complete); |
| 295 | 298 | try writer.writeAll(" = "); |
| ... | ... | @@ -2487,7 +2490,9 @@ pub fn genFunc(f: *Function) !void { |
| 2487 | 2490 | // Liveness analysis, however, locals from alloc instructions will be |
| 2488 | 2491 | // missing. These are added now to complete the map. Then we can sort by |
| 2489 | 2492 | // alignment, descending. |
| 2490 | | for (f.allocs.keys()) |local_index| { |
| 2493 | const values = f.allocs.values(); |
| 2494 | for (f.allocs.keys()) |local_index, i| { |
| 2495 | if (values[i]) continue; // static |
| 2491 | 2496 | const local = f.locals.items[local_index]; |
| 2492 | 2497 | log.debug("inserting local {d} into free_locals", .{local_index}); |
| 2493 | 2498 | const gop = try f.free_locals.getOrPutContext(gpa, local.ty, f.tyHashCtx()); |
| ... | ... | @@ -3110,7 +3115,7 @@ fn airAlloc(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3110 | 3115 | const local = try f.allocAlignedLocal(elem_type, mutability, inst_ty.ptrAlignment(target)); |
| 3111 | 3116 | log.debug("%{d}: allocated unfreeable t{d}", .{ inst, local.local }); |
| 3112 | 3117 | const gpa = f.object.dg.module.gpa; |
| 3113 | | try f.allocs.put(gpa, local.local, {}); |
| 3118 | try f.allocs.put(gpa, local.local, false); |
| 3114 | 3119 | return CValue{ .local_ref = local.local }; |
| 3115 | 3120 | } |
| 3116 | 3121 | |
| ... | ... | @@ -3127,7 +3132,7 @@ fn airRetPtr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3127 | 3132 | const local = try f.allocAlignedLocal(elem_ty, mutability, inst_ty.ptrAlignment(target)); |
| 3128 | 3133 | log.debug("%{d}: allocated unfreeable t{d}", .{ inst, local.local }); |
| 3129 | 3134 | const gpa = f.object.dg.module.gpa; |
| 3130 | | try f.allocs.put(gpa, local.local, {}); |
| 3135 | try f.allocs.put(gpa, local.local, false); |
| 3131 | 3136 | return CValue{ .local_ref = local.local }; |
| 3132 | 3137 | } |
| 3133 | 3138 | |