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