| author | |
| committer | |
| log | 9dda2eb1abe675a99ff5d7ad85454b1cc5946c95 |
| tree | a50f2d52e8a0745ce1f72bae25d609c448a485e6 |
| parent | 91fb211faa3f37d08da55b0c8df92a6475624316 |
| parent | ed026b5dffd116d36aa51508e3eefa8c36838c07 |
| signature |
llvm: implement per-module stripping3 files changed, 119 insertions(+), 56 deletions(-)
src/Sema.zig+2-2| ... | @@ -6407,8 +6407,6 @@ fn zirDbgVar( | ... | @@ -6407,8 +6407,6 @@ fn zirDbgVar( |
| 6407 | inst: Zir.Inst.Index, | 6407 | inst: Zir.Inst.Index, |
| 6408 | air_tag: Air.Inst.Tag, | 6408 | air_tag: Air.Inst.Tag, |
| 6409 | ) CompileError!void { | 6409 | ) CompileError!void { |
| 6410 | if (block.is_comptime or block.ownerModule().strip) return; | ||
| 6411 | |||
| 6412 | const str_op = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_op; | 6410 | const str_op = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_op; |
| 6413 | const operand = try sema.resolveInst(str_op.operand); | 6411 | const operand = try sema.resolveInst(str_op.operand); |
| 6414 | const name = str_op.getStr(sema.code); | 6412 | const name = str_op.getStr(sema.code); |
| ... | @@ -6422,6 +6420,8 @@ fn addDbgVar( | ... | @@ -6422,6 +6420,8 @@ fn addDbgVar( |
| 6422 | air_tag: Air.Inst.Tag, | 6420 | air_tag: Air.Inst.Tag, |
| 6423 | name: []const u8, | 6421 | name: []const u8, |
| 6424 | ) CompileError!void { | 6422 | ) CompileError!void { |
| 6423 | if (block.is_comptime or block.ownerModule().strip) return; | ||
| 6424 | |||
| 6425 | const mod = sema.mod; | 6425 | const mod = sema.mod; |
| 6426 | const operand_ty = sema.typeOf(operand); | 6426 | const operand_ty = sema.typeOf(operand); |
| 6427 | const val_ty = switch (air_tag) { | 6427 | const val_ty = switch (air_tag) { |
src/codegen/llvm.zig+38-30| ... | @@ -837,11 +837,10 @@ pub const Object = struct { | ... | @@ -837,11 +837,10 @@ pub const Object = struct { |
| 837 | const gpa = comp.gpa; | 837 | const gpa = comp.gpa; |
| 838 | const target = comp.root_mod.resolved_target.result; | 838 | const target = comp.root_mod.resolved_target.result; |
| 839 | const llvm_target_triple = try targetTriple(arena, target); | 839 | const llvm_target_triple = try targetTriple(arena, target); |
| 840 | const strip = comp.root_mod.strip; | ||
| 841 | 840 | ||
| 842 | var builder = try Builder.init(.{ | 841 | var builder = try Builder.init(.{ |
| 843 | .allocator = gpa, | 842 | .allocator = gpa, |
| 844 | .strip = strip, | 843 | .strip = comp.config.debug_format == .strip, |
| 845 | .name = comp.root_name, | 844 | .name = comp.root_name, |
| 846 | .target = target, | 845 | .target = target, |
| 847 | .triple = llvm_target_triple, | 846 | .triple = llvm_target_triple, |
| ... | @@ -1052,7 +1051,10 @@ pub const Object = struct { | ... | @@ -1052,7 +1051,10 @@ pub const Object = struct { |
| 1052 | const mod = o.module; | 1051 | const mod = o.module; |
| 1053 | const errors_len = mod.global_error_set.count(); | 1052 | const errors_len = mod.global_error_set.count(); |
| 1054 | 1053 | ||
| 1055 | var wip = try Builder.WipFunction.init(&o.builder, llvm_fn.ptrConst(&o.builder).kind.function); | 1054 | var wip = try Builder.WipFunction.init(&o.builder, .{ |
| 1055 | .function = llvm_fn.ptrConst(&o.builder).kind.function, | ||
| 1056 | .strip = true, | ||
| 1057 | }); | ||
| 1056 | defer wip.deinit(); | 1058 | defer wip.deinit(); |
| 1057 | wip.cursor = .{ .block = try wip.block(0, "Entry") }; | 1059 | wip.cursor = .{ .block = try wip.block(0, "Entry") }; |
| 1058 | 1060 | ||
| ... | @@ -1181,6 +1183,10 @@ pub const Object = struct { | ... | @@ -1181,6 +1183,10 @@ pub const Object = struct { |
| 1181 | } | 1183 | } |
| 1182 | } | 1184 | } |
| 1183 | 1185 | ||
| 1186 | const target_triple_sentinel = | ||
| 1187 | try self.gpa.dupeZ(u8, self.builder.target_triple.slice(&self.builder).?); | ||
| 1188 | defer self.gpa.free(target_triple_sentinel); | ||
| 1189 | |||
| 1184 | const emit_asm_msg = options.asm_path orelse "(none)"; | 1190 | const emit_asm_msg = options.asm_path orelse "(none)"; |
| 1185 | const emit_bin_msg = options.bin_path orelse "(none)"; | 1191 | const emit_bin_msg = options.bin_path orelse "(none)"; |
| 1186 | const post_llvm_ir_msg = options.post_ir_path orelse "(none)"; | 1192 | const post_llvm_ir_msg = options.post_ir_path orelse "(none)"; |
| ... | @@ -1200,6 +1206,7 @@ pub const Object = struct { | ... | @@ -1200,6 +1206,7 @@ pub const Object = struct { |
| 1200 | 1206 | ||
| 1201 | const bitcode = try self.builder.toBitcode(self.gpa); | 1207 | const bitcode = try self.builder.toBitcode(self.gpa); |
| 1202 | defer self.gpa.free(bitcode); | 1208 | defer self.gpa.free(bitcode); |
| 1209 | self.builder.clearAndFree(); | ||
| 1203 | 1210 | ||
| 1204 | if (options.pre_bc_path) |path| { | 1211 | if (options.pre_bc_path) |path| { |
| 1205 | var file = try std.fs.cwd().createFile(path, .{}); | 1212 | var file = try std.fs.cwd().createFile(path, .{}); |
| ... | @@ -1247,16 +1254,13 @@ pub const Object = struct { | ... | @@ -1247,16 +1254,13 @@ pub const Object = struct { |
| 1247 | }; | 1254 | }; |
| 1248 | defer context.dispose(); | 1255 | defer context.dispose(); |
| 1249 | 1256 | ||
| 1250 | const target_triple_sentinel = | ||
| 1251 | try self.gpa.dupeZ(u8, self.builder.target_triple.slice(&self.builder).?); | ||
| 1252 | defer self.gpa.free(target_triple_sentinel); | ||
| 1253 | var target: *llvm.Target = undefined; | 1257 | var target: *llvm.Target = undefined; |
| 1254 | var error_message: [*:0]const u8 = undefined; | 1258 | var error_message: [*:0]const u8 = undefined; |
| 1255 | if (llvm.Target.getFromTriple(target_triple_sentinel, &target, &error_message).toBool()) { | 1259 | if (llvm.Target.getFromTriple(target_triple_sentinel, &target, &error_message).toBool()) { |
| 1256 | defer llvm.disposeMessage(error_message); | 1260 | defer llvm.disposeMessage(error_message); |
| 1257 | 1261 | ||
| 1258 | log.err("LLVM failed to parse '{s}': {s}", .{ | 1262 | log.err("LLVM failed to parse '{s}': {s}", .{ |
| 1259 | self.builder.target_triple.slice(&self.builder).?, | 1263 | target_triple_sentinel, |
| 1260 | error_message, | 1264 | error_message, |
| 1261 | }); | 1265 | }); |
| 1262 | @panic("Invalid LLVM triple"); | 1266 | @panic("Invalid LLVM triple"); |
| ... | @@ -1372,6 +1376,7 @@ pub const Object = struct { | ... | @@ -1372,6 +1376,7 @@ pub const Object = struct { |
| 1372 | air: Air, | 1376 | air: Air, |
| 1373 | liveness: Liveness, | 1377 | liveness: Liveness, |
| 1374 | ) !void { | 1378 | ) !void { |
| 1379 | const comp = zcu.comp; | ||
| 1375 | const func = zcu.funcInfo(func_index); | 1380 | const func = zcu.funcInfo(func_index); |
| 1376 | const decl_index = func.owner_decl; | 1381 | const decl_index = func.owner_decl; |
| 1377 | const decl = zcu.declPtr(decl_index); | 1382 | const decl = zcu.declPtr(decl_index); |
| ... | @@ -1440,7 +1445,10 @@ pub const Object = struct { | ... | @@ -1440,7 +1445,10 @@ pub const Object = struct { |
| 1440 | function_index.setSection(try o.builder.string(section), &o.builder); | 1445 | function_index.setSection(try o.builder.string(section), &o.builder); |
| 1441 | 1446 | ||
| 1442 | var deinit_wip = true; | 1447 | var deinit_wip = true; |
| 1443 | var wip = try Builder.WipFunction.init(&o.builder, function_index); | 1448 | var wip = try Builder.WipFunction.init(&o.builder, .{ |
| 1449 | .function = function_index, | ||
| 1450 | .strip = owner_mod.strip, | ||
| 1451 | }); | ||
| 1444 | defer if (deinit_wip) wip.deinit(); | 1452 | defer if (deinit_wip) wip.deinit(); |
| 1445 | wip.cursor = .{ .block = try wip.block(0, "Entry") }; | 1453 | wip.cursor = .{ .block = try wip.block(0, "Entry") }; |
| 1446 | 1454 | ||
| ... | @@ -1459,8 +1467,6 @@ pub const Object = struct { | ... | @@ -1459,8 +1467,6 @@ pub const Object = struct { |
| 1459 | .unsigned => try attributes.addRetAttr(.zeroext, &o.builder), | 1467 | .unsigned => try attributes.addRetAttr(.zeroext, &o.builder), |
| 1460 | }; | 1468 | }; |
| 1461 | 1469 | ||
| 1462 | const comp = zcu.comp; | ||
| 1463 | |||
| 1464 | const err_return_tracing = Type.fromInterned(fn_info.return_type).isError(zcu) and | 1470 | const err_return_tracing = Type.fromInterned(fn_info.return_type).isError(zcu) and |
| 1465 | comp.config.any_error_tracing; | 1471 | comp.config.any_error_tracing; |
| 1466 | 1472 | ||
| ... | @@ -1645,7 +1651,7 @@ pub const Object = struct { | ... | @@ -1645,7 +1651,7 @@ pub const Object = struct { |
| 1645 | 1651 | ||
| 1646 | function_index.setAttributes(try attributes.finish(&o.builder), &o.builder); | 1652 | function_index.setAttributes(try attributes.finish(&o.builder), &o.builder); |
| 1647 | 1653 | ||
| 1648 | const file, const subprogram = if (!o.builder.strip) debug_info: { | 1654 | const file, const subprogram = if (!wip.strip) debug_info: { |
| 1649 | const file = try o.getDebugFile(namespace.file_scope); | 1655 | const file = try o.getDebugFile(namespace.file_scope); |
| 1650 | 1656 | ||
| 1651 | const line_number = decl.src_line + 1; | 1657 | const line_number = decl.src_line + 1; |
| ... | @@ -4614,7 +4620,10 @@ pub const Object = struct { | ... | @@ -4614,7 +4620,10 @@ pub const Object = struct { |
| 4614 | function_index.setAttributes(try attributes.finish(&o.builder), &o.builder); | 4620 | function_index.setAttributes(try attributes.finish(&o.builder), &o.builder); |
| 4615 | gop.value_ptr.* = function_index.ptrConst(&o.builder).global; | 4621 | gop.value_ptr.* = function_index.ptrConst(&o.builder).global; |
| 4616 | 4622 | ||
| 4617 | var wip = try Builder.WipFunction.init(&o.builder, function_index); | 4623 | var wip = try Builder.WipFunction.init(&o.builder, .{ |
| 4624 | .function = function_index, | ||
| 4625 | .strip = true, | ||
| 4626 | }); | ||
| 4618 | defer wip.deinit(); | 4627 | defer wip.deinit(); |
| 4619 | wip.cursor = .{ .block = try wip.block(0, "Entry") }; | 4628 | wip.cursor = .{ .block = try wip.block(0, "Entry") }; |
| 4620 | 4629 | ||
| ... | @@ -4684,23 +4693,23 @@ pub const DeclGen = struct { | ... | @@ -4684,23 +4693,23 @@ pub const DeclGen = struct { |
| 4684 | 4693 | ||
| 4685 | fn genDecl(dg: *DeclGen) !void { | 4694 | fn genDecl(dg: *DeclGen) !void { |
| 4686 | const o = dg.object; | 4695 | const o = dg.object; |
| 4687 | const mod = o.module; | 4696 | const zcu = o.module; |
| 4688 | const decl = dg.decl; | 4697 | const decl = dg.decl; |
| 4689 | const decl_index = dg.decl_index; | 4698 | const decl_index = dg.decl_index; |
| 4690 | assert(decl.has_tv); | 4699 | assert(decl.has_tv); |
| 4691 | 4700 | ||
| 4692 | if (decl.val.getExternFunc(mod)) |extern_func| { | 4701 | if (decl.val.getExternFunc(zcu)) |extern_func| { |
| 4693 | _ = try o.resolveLlvmFunction(extern_func.decl); | 4702 | _ = try o.resolveLlvmFunction(extern_func.decl); |
| 4694 | } else { | 4703 | } else { |
| 4695 | const variable_index = try o.resolveGlobalDecl(decl_index); | 4704 | const variable_index = try o.resolveGlobalDecl(decl_index); |
| 4696 | variable_index.setAlignment( | 4705 | variable_index.setAlignment( |
| 4697 | decl.getAlignment(mod).toLlvm(), | 4706 | decl.getAlignment(zcu).toLlvm(), |
| 4698 | &o.builder, | 4707 | &o.builder, |
| 4699 | ); | 4708 | ); |
| 4700 | if (mod.intern_pool.stringToSliceUnwrap(decl.@"linksection")) |section| | 4709 | if (zcu.intern_pool.stringToSliceUnwrap(decl.@"linksection")) |section| |
| 4701 | variable_index.setSection(try o.builder.string(section), &o.builder); | 4710 | variable_index.setSection(try o.builder.string(section), &o.builder); |
| 4702 | assert(decl.has_tv); | 4711 | assert(decl.has_tv); |
| 4703 | const init_val = if (decl.val.getVariable(mod)) |decl_var| decl_var.init else init_val: { | 4712 | const init_val = if (decl.val.getVariable(zcu)) |decl_var| decl_var.init else init_val: { |
| 4704 | variable_index.setMutability(.constant, &o.builder); | 4713 | variable_index.setMutability(.constant, &o.builder); |
| 4705 | break :init_val decl.val.toIntern(); | 4714 | break :init_val decl.val.toIntern(); |
| 4706 | }; | 4715 | }; |
| ... | @@ -4712,12 +4721,15 @@ pub const DeclGen = struct { | ... | @@ -4712,12 +4721,15 @@ pub const DeclGen = struct { |
| 4712 | const line_number = decl.src_line + 1; | 4721 | const line_number = decl.src_line + 1; |
| 4713 | const is_internal_linkage = !o.module.decl_exports.contains(decl_index); | 4722 | const is_internal_linkage = !o.module.decl_exports.contains(decl_index); |
| 4714 | 4723 | ||
| 4715 | if (dg.object.builder.strip) return; | 4724 | const namespace = zcu.namespacePtr(decl.src_namespace); |
| 4725 | const owner_mod = namespace.file_scope.mod; | ||
| 4716 | 4726 | ||
| 4717 | const debug_file = try o.getDebugFile(mod.namespacePtr(decl.src_namespace).file_scope); | 4727 | if (owner_mod.strip) return; |
| 4728 | |||
| 4729 | const debug_file = try o.getDebugFile(namespace.file_scope); | ||
| 4718 | 4730 | ||
| 4719 | const debug_global_var = try o.builder.debugGlobalVar( | 4731 | const debug_global_var = try o.builder.debugGlobalVar( |
| 4720 | try o.builder.metadataString(mod.intern_pool.stringToSlice(decl.name)), // Name | 4732 | try o.builder.metadataString(zcu.intern_pool.stringToSlice(decl.name)), // Name |
| 4721 | try o.builder.metadataStringFromString(variable_index.name(&o.builder)), // Linkage name | 4733 | try o.builder.metadataStringFromString(variable_index.name(&o.builder)), // Linkage name |
| 4722 | debug_file, // File | 4734 | debug_file, // File |
| 4723 | debug_file, // Scope | 4735 | debug_file, // Scope |
| ... | @@ -4733,7 +4745,7 @@ pub const DeclGen = struct { | ... | @@ -4733,7 +4745,7 @@ pub const DeclGen = struct { |
| 4733 | debug_global_var, | 4745 | debug_global_var, |
| 4734 | debug_expression, | 4746 | debug_expression, |
| 4735 | ); | 4747 | ); |
| 4736 | if (!is_internal_linkage or decl.isExtern(mod)) | 4748 | if (!is_internal_linkage or decl.isExtern(zcu)) |
| 4737 | variable_index.setGlobalVariableExpression(debug_global_var_expression, &o.builder); | 4749 | variable_index.setGlobalVariableExpression(debug_global_var_expression, &o.builder); |
| 4738 | try o.debug_globals.append(o.gpa, debug_global_var_expression); | 4750 | try o.debug_globals.append(o.gpa, debug_global_var_expression); |
| 4739 | } | 4751 | } |
| ... | @@ -6568,7 +6580,6 @@ pub const FuncGen = struct { | ... | @@ -6568,7 +6580,6 @@ pub const FuncGen = struct { |
| 6568 | } | 6580 | } |
| 6569 | 6581 | ||
| 6570 | fn airDbgStmt(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 6582 | fn airDbgStmt(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6571 | if (self.wip.builder.strip) return .none; | ||
| 6572 | const dbg_stmt = self.air.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt; | 6583 | const dbg_stmt = self.air.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt; |
| 6573 | self.prev_dbg_line = @intCast(self.base_line + dbg_stmt.line + 1); | 6584 | self.prev_dbg_line = @intCast(self.base_line + dbg_stmt.line + 1); |
| 6574 | self.prev_dbg_column = @intCast(dbg_stmt.column + 1); | 6585 | self.prev_dbg_column = @intCast(dbg_stmt.column + 1); |
| ... | @@ -6591,7 +6602,6 @@ pub const FuncGen = struct { | ... | @@ -6591,7 +6602,6 @@ pub const FuncGen = struct { |
| 6591 | } | 6602 | } |
| 6592 | 6603 | ||
| 6593 | fn airDbgInlineBegin(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 6604 | fn airDbgInlineBegin(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6594 | if (self.wip.builder.strip) return .none; | ||
| 6595 | const o = self.dg.object; | 6605 | const o = self.dg.object; |
| 6596 | const zcu = o.module; | 6606 | const zcu = o.module; |
| 6597 | 6607 | ||
| ... | @@ -6658,7 +6668,6 @@ pub const FuncGen = struct { | ... | @@ -6658,7 +6668,6 @@ pub const FuncGen = struct { |
| 6658 | } | 6668 | } |
| 6659 | 6669 | ||
| 6660 | fn airDbgInlineEnd(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { | 6670 | fn airDbgInlineEnd(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value { |
| 6661 | if (self.wip.builder.strip) return .none; | ||
| 6662 | const o = self.dg.object; | 6671 | const o = self.dg.object; |
| 6663 | 6672 | ||
| 6664 | const ty_fn = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_fn; | 6673 | const ty_fn = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_fn; |
| ... | @@ -6675,7 +6684,6 @@ pub const FuncGen = struct { | ... | @@ -6675,7 +6684,6 @@ pub const FuncGen = struct { |
| 6675 | } | 6684 | } |
| 6676 | 6685 | ||
| 6677 | fn airDbgBlockBegin(self: *FuncGen) Allocator.Error!Builder.Value { | 6686 | fn airDbgBlockBegin(self: *FuncGen) Allocator.Error!Builder.Value { |
| 6678 | if (self.wip.builder.strip) return .none; | ||
| 6679 | const o = self.dg.object; | 6687 | const o = self.dg.object; |
| 6680 | 6688 | ||
| 6681 | try self.scope_stack.append(self.gpa, self.scope); | 6689 | try self.scope_stack.append(self.gpa, self.scope); |
| ... | @@ -6691,13 +6699,11 @@ pub const FuncGen = struct { | ... | @@ -6691,13 +6699,11 @@ pub const FuncGen = struct { |
| 6691 | } | 6699 | } |
| 6692 | 6700 | ||
| 6693 | fn airDbgBlockEnd(self: *FuncGen) !Builder.Value { | 6701 | fn airDbgBlockEnd(self: *FuncGen) !Builder.Value { |
| 6694 | if (self.wip.builder.strip) return .none; | ||
| 6695 | self.scope = self.scope_stack.pop(); | 6702 | self.scope = self.scope_stack.pop(); |
| 6696 | return .none; | 6703 | return .none; |
| 6697 | } | 6704 | } |
| 6698 | 6705 | ||
| 6699 | fn airDbgVarPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 6706 | fn airDbgVarPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6700 | if (self.wip.builder.strip) return .none; | ||
| 6701 | const o = self.dg.object; | 6707 | const o = self.dg.object; |
| 6702 | const mod = o.module; | 6708 | const mod = o.module; |
| 6703 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | 6709 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| ... | @@ -6730,7 +6736,6 @@ pub const FuncGen = struct { | ... | @@ -6730,7 +6736,6 @@ pub const FuncGen = struct { |
| 6730 | } | 6736 | } |
| 6731 | 6737 | ||
| 6732 | fn airDbgVarVal(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 6738 | fn airDbgVarVal(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6733 | if (self.wip.builder.strip) return .none; | ||
| 6734 | const o = self.dg.object; | 6739 | const o = self.dg.object; |
| 6735 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; | 6740 | const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 6736 | const operand = try self.resolveInst(pl_op.operand); | 6741 | const operand = try self.resolveInst(pl_op.operand); |
| ... | @@ -8817,7 +8822,7 @@ pub const FuncGen = struct { | ... | @@ -8817,7 +8822,7 @@ pub const FuncGen = struct { |
| 8817 | const arg_val = self.args[self.arg_index]; | 8822 | const arg_val = self.args[self.arg_index]; |
| 8818 | self.arg_index += 1; | 8823 | self.arg_index += 1; |
| 8819 | 8824 | ||
| 8820 | if (self.wip.builder.strip) return arg_val; | 8825 | if (self.wip.strip) return arg_val; |
| 8821 | 8826 | ||
| 8822 | const inst_ty = self.typeOfIndex(inst); | 8827 | const inst_ty = self.typeOfIndex(inst); |
| 8823 | if (needDbgVarWorkaround(o)) return arg_val; | 8828 | if (needDbgVarWorkaround(o)) return arg_val; |
| ... | @@ -9664,7 +9669,10 @@ pub const FuncGen = struct { | ... | @@ -9664,7 +9669,10 @@ pub const FuncGen = struct { |
| 9664 | function_index.setAttributes(try attributes.finish(&o.builder), &o.builder); | 9669 | function_index.setAttributes(try attributes.finish(&o.builder), &o.builder); |
| 9665 | gop.value_ptr.* = function_index; | 9670 | gop.value_ptr.* = function_index; |
| 9666 | 9671 | ||
| 9667 | var wip = try Builder.WipFunction.init(&o.builder, function_index); | 9672 | var wip = try Builder.WipFunction.init(&o.builder, .{ |
| 9673 | .function = function_index, | ||
| 9674 | .strip = true, | ||
| 9675 | }); | ||
| 9668 | defer wip.deinit(); | 9676 | defer wip.deinit(); |
| 9669 | wip.cursor = .{ .block = try wip.block(0, "Entry") }; | 9677 | wip.cursor = .{ .block = try wip.block(0, "Entry") }; |
| 9670 | 9678 |
src/codegen/llvm/Builder.zig+79-24| ... | @@ -3797,6 +3797,7 @@ pub const Function = struct { | ... | @@ -3797,6 +3797,7 @@ pub const Function = struct { |
| 3797 | instructions: std.MultiArrayList(Instruction) = .{}, | 3797 | instructions: std.MultiArrayList(Instruction) = .{}, |
| 3798 | names: [*]const String = &[0]String{}, | 3798 | names: [*]const String = &[0]String{}, |
| 3799 | value_indices: [*]const u32 = &[0]u32{}, | 3799 | value_indices: [*]const u32 = &[0]u32{}, |
| 3800 | strip: bool, | ||
| 3800 | debug_locations: std.AutoHashMapUnmanaged(Instruction.Index, DebugLocation) = .{}, | 3801 | debug_locations: std.AutoHashMapUnmanaged(Instruction.Index, DebugLocation) = .{}, |
| 3801 | debug_values: []const Instruction.Index = &.{}, | 3802 | debug_values: []const Instruction.Index = &.{}, |
| 3802 | extra: []const u32 = &.{}, | 3803 | extra: []const u32 = &.{}, |
| ... | @@ -4890,6 +4891,7 @@ pub const WipFunction = struct { | ... | @@ -4890,6 +4891,7 @@ pub const WipFunction = struct { |
| 4890 | blocks: std.ArrayListUnmanaged(Block), | 4891 | blocks: std.ArrayListUnmanaged(Block), |
| 4891 | instructions: std.MultiArrayList(Instruction), | 4892 | instructions: std.MultiArrayList(Instruction), |
| 4892 | names: std.ArrayListUnmanaged(String), | 4893 | names: std.ArrayListUnmanaged(String), |
| 4894 | strip: bool, | ||
| 4893 | debug_locations: std.AutoArrayHashMapUnmanaged(Instruction.Index, DebugLocation), | 4895 | debug_locations: std.AutoArrayHashMapUnmanaged(Instruction.Index, DebugLocation), |
| 4894 | debug_values: std.AutoArrayHashMapUnmanaged(Instruction.Index, void), | 4896 | debug_values: std.AutoArrayHashMapUnmanaged(Instruction.Index, void), |
| 4895 | extra: std.ArrayListUnmanaged(u32), | 4897 | extra: std.ArrayListUnmanaged(u32), |
| ... | @@ -4922,31 +4924,35 @@ pub const WipFunction = struct { | ... | @@ -4922,31 +4924,35 @@ pub const WipFunction = struct { |
| 4922 | 4924 | ||
| 4923 | pub const Instruction = Function.Instruction; | 4925 | pub const Instruction = Function.Instruction; |
| 4924 | 4926 | ||
| 4925 | pub fn init(builder: *Builder, function: Function.Index) Allocator.Error!WipFunction { | 4927 | pub fn init(builder: *Builder, options: struct { |
| 4928 | function: Function.Index, | ||
| 4929 | strip: bool, | ||
| 4930 | }) Allocator.Error!WipFunction { | ||
| 4926 | var self: WipFunction = .{ | 4931 | var self: WipFunction = .{ |
| 4927 | .builder = builder, | 4932 | .builder = builder, |
| 4928 | .function = function, | 4933 | .function = options.function, |
| 4929 | .prev_debug_location = .no_location, | 4934 | .prev_debug_location = .no_location, |
| 4930 | .debug_location = .no_location, | 4935 | .debug_location = .no_location, |
| 4931 | .cursor = undefined, | 4936 | .cursor = undefined, |
| 4932 | .blocks = .{}, | 4937 | .blocks = .{}, |
| 4933 | .instructions = .{}, | 4938 | .instructions = .{}, |
| 4934 | .names = .{}, | 4939 | .names = .{}, |
| 4940 | .strip = options.strip, | ||
| 4935 | .debug_locations = .{}, | 4941 | .debug_locations = .{}, |
| 4936 | .debug_values = .{}, | 4942 | .debug_values = .{}, |
| 4937 | .extra = .{}, | 4943 | .extra = .{}, |
| 4938 | }; | 4944 | }; |
| 4939 | errdefer self.deinit(); | 4945 | errdefer self.deinit(); |
| 4940 | 4946 | ||
| 4941 | const params_len = function.typeOf(self.builder).functionParameters(self.builder).len; | 4947 | const params_len = options.function.typeOf(self.builder).functionParameters(self.builder).len; |
| 4942 | try self.ensureUnusedExtraCapacity(params_len, NoExtra, 0); | 4948 | try self.ensureUnusedExtraCapacity(params_len, NoExtra, 0); |
| 4943 | try self.instructions.ensureUnusedCapacity(self.builder.gpa, params_len); | 4949 | try self.instructions.ensureUnusedCapacity(self.builder.gpa, params_len); |
| 4944 | if (!self.builder.strip) { | 4950 | if (!self.strip) { |
| 4945 | try self.names.ensureUnusedCapacity(self.builder.gpa, params_len); | 4951 | try self.names.ensureUnusedCapacity(self.builder.gpa, params_len); |
| 4946 | } | 4952 | } |
| 4947 | for (0..params_len) |param_index| { | 4953 | for (0..params_len) |param_index| { |
| 4948 | self.instructions.appendAssumeCapacity(.{ .tag = .arg, .data = @intCast(param_index) }); | 4954 | self.instructions.appendAssumeCapacity(.{ .tag = .arg, .data = @intCast(param_index) }); |
| 4949 | if (!self.builder.strip) { | 4955 | if (!self.strip) { |
| 4950 | self.names.appendAssumeCapacity(.empty); // TODO: param names | 4956 | self.names.appendAssumeCapacity(.empty); // TODO: param names |
| 4951 | } | 4957 | } |
| 4952 | } | 4958 | } |
| ... | @@ -4967,7 +4973,7 @@ pub const WipFunction = struct { | ... | @@ -4967,7 +4973,7 @@ pub const WipFunction = struct { |
| 4967 | try self.blocks.ensureUnusedCapacity(self.builder.gpa, 1); | 4973 | try self.blocks.ensureUnusedCapacity(self.builder.gpa, 1); |
| 4968 | 4974 | ||
| 4969 | const index: Block.Index = @enumFromInt(self.blocks.items.len); | 4975 | const index: Block.Index = @enumFromInt(self.blocks.items.len); |
| 4970 | const final_name = if (self.builder.strip) .empty else try self.builder.string(name); | 4976 | const final_name = if (self.strip) .empty else try self.builder.string(name); |
| 4971 | self.blocks.appendAssumeCapacity(.{ | 4977 | self.blocks.appendAssumeCapacity(.{ |
| 4972 | .name = final_name, | 4978 | .name = final_name, |
| 4973 | .incoming = incoming, | 4979 | .incoming = incoming, |
| ... | @@ -5828,7 +5834,7 @@ pub const WipFunction = struct { | ... | @@ -5828,7 +5834,7 @@ pub const WipFunction = struct { |
| 5828 | } | 5834 | } |
| 5829 | 5835 | ||
| 5830 | pub fn debugValue(self: *WipFunction, value: Value) Allocator.Error!Metadata { | 5836 | pub fn debugValue(self: *WipFunction, value: Value) Allocator.Error!Metadata { |
| 5831 | if (self.builder.strip) return .none; | 5837 | if (self.strip) return .none; |
| 5832 | return switch (value.unwrap()) { | 5838 | return switch (value.unwrap()) { |
| 5833 | .instruction => |instr_index| blk: { | 5839 | .instruction => |instr_index| blk: { |
| 5834 | const gop = try self.debug_values.getOrPut(self.builder.gpa, instr_index); | 5840 | const gop = try self.debug_values.getOrPut(self.builder.gpa, instr_index); |
| ... | @@ -6015,7 +6021,7 @@ pub const WipFunction = struct { | ... | @@ -6015,7 +6021,7 @@ pub const WipFunction = struct { |
| 6015 | value_index += 1; | 6021 | value_index += 1; |
| 6016 | function.instructions.appendAssumeCapacity(argument); | 6022 | function.instructions.appendAssumeCapacity(argument); |
| 6017 | names[@intFromEnum(new_argument_index)] = try wip_name.map( | 6023 | names[@intFromEnum(new_argument_index)] = try wip_name.map( |
| 6018 | if (self.builder.strip) .empty else self.names.items[@intFromEnum(old_argument_index)], | 6024 | if (self.strip) .empty else self.names.items[@intFromEnum(old_argument_index)], |
| 6019 | ".", | 6025 | ".", |
| 6020 | ); | 6026 | ); |
| 6021 | if (self.debug_locations.get(old_argument_index)) |location| { | 6027 | if (self.debug_locations.get(old_argument_index)) |location| { |
| ... | @@ -6333,7 +6339,7 @@ pub const WipFunction = struct { | ... | @@ -6333,7 +6339,7 @@ pub const WipFunction = struct { |
| 6333 | }, | 6339 | }, |
| 6334 | } | 6340 | } |
| 6335 | function.instructions.appendAssumeCapacity(instruction); | 6341 | function.instructions.appendAssumeCapacity(instruction); |
| 6336 | names[@intFromEnum(new_instruction_index)] = try wip_name.map(if (self.builder.strip) | 6342 | names[@intFromEnum(new_instruction_index)] = try wip_name.map(if (self.strip) |
| 6337 | if (old_instruction_index.hasResultWip(self)) .empty else .none | 6343 | if (old_instruction_index.hasResultWip(self)) .empty else .none |
| 6338 | else | 6344 | else |
| 6339 | self.names.items[@intFromEnum(old_instruction_index)], "."); | 6345 | self.names.items[@intFromEnum(old_instruction_index)], "."); |
| ... | @@ -6356,6 +6362,7 @@ pub const WipFunction = struct { | ... | @@ -6356,6 +6362,7 @@ pub const WipFunction = struct { |
| 6356 | function.blocks = blocks; | 6362 | function.blocks = blocks; |
| 6357 | function.names = names.ptr; | 6363 | function.names = names.ptr; |
| 6358 | function.value_indices = value_indices.ptr; | 6364 | function.value_indices = value_indices.ptr; |
| 6365 | function.strip = self.strip; | ||
| 6359 | function.debug_locations = debug_locations; | 6366 | function.debug_locations = debug_locations; |
| 6360 | function.debug_values = debug_values; | 6367 | function.debug_values = debug_values; |
| 6361 | } | 6368 | } |
| ... | @@ -6503,19 +6510,19 @@ pub const WipFunction = struct { | ... | @@ -6503,19 +6510,19 @@ pub const WipFunction = struct { |
| 6503 | ) Allocator.Error!Instruction.Index { | 6510 | ) Allocator.Error!Instruction.Index { |
| 6504 | const block_instructions = &self.cursor.block.ptr(self).instructions; | 6511 | const block_instructions = &self.cursor.block.ptr(self).instructions; |
| 6505 | try self.instructions.ensureUnusedCapacity(self.builder.gpa, 1); | 6512 | try self.instructions.ensureUnusedCapacity(self.builder.gpa, 1); |
| 6506 | if (!self.builder.strip) { | 6513 | if (!self.strip) { |
| 6507 | try self.names.ensureUnusedCapacity(self.builder.gpa, 1); | 6514 | try self.names.ensureUnusedCapacity(self.builder.gpa, 1); |
| 6508 | try self.debug_locations.ensureUnusedCapacity(self.builder.gpa, 1); | 6515 | try self.debug_locations.ensureUnusedCapacity(self.builder.gpa, 1); |
| 6509 | } | 6516 | } |
| 6510 | try block_instructions.ensureUnusedCapacity(self.builder.gpa, 1); | 6517 | try block_instructions.ensureUnusedCapacity(self.builder.gpa, 1); |
| 6511 | const final_name = if (name) |n| | 6518 | const final_name = if (name) |n| |
| 6512 | if (self.builder.strip) .empty else try self.builder.string(n) | 6519 | if (self.strip) .empty else try self.builder.string(n) |
| 6513 | else | 6520 | else |
| 6514 | .none; | 6521 | .none; |
| 6515 | 6522 | ||
| 6516 | const index: Instruction.Index = @enumFromInt(self.instructions.len); | 6523 | const index: Instruction.Index = @enumFromInt(self.instructions.len); |
| 6517 | self.instructions.appendAssumeCapacity(instruction); | 6524 | self.instructions.appendAssumeCapacity(instruction); |
| 6518 | if (!self.builder.strip) { | 6525 | if (!self.strip) { |
| 6519 | self.names.appendAssumeCapacity(final_name); | 6526 | self.names.appendAssumeCapacity(final_name); |
| 6520 | if (block_instructions.items.len == 0 or | 6527 | if (block_instructions.items.len == 0 or |
| 6521 | !std.meta.eql(self.debug_location, self.prev_debug_location)) | 6528 | !std.meta.eql(self.debug_location, self.prev_debug_location)) |
| ... | @@ -8389,6 +8396,50 @@ pub fn init(options: Options) Allocator.Error!Builder { | ... | @@ -8389,6 +8396,50 @@ pub fn init(options: Options) Allocator.Error!Builder { |
| 8389 | return self; | 8396 | return self; |
| 8390 | } | 8397 | } |
| 8391 | 8398 | ||
| 8399 | pub fn clearAndFree(self: *Builder) void { | ||
| 8400 | self.module_asm.clearAndFree(self.gpa); | ||
| 8401 | |||
| 8402 | self.string_map.clearAndFree(self.gpa); | ||
| 8403 | self.string_indices.clearAndFree(self.gpa); | ||
| 8404 | self.string_bytes.clearAndFree(self.gpa); | ||
| 8405 | |||
| 8406 | self.types.clearAndFree(self.gpa); | ||
| 8407 | self.next_unique_type_id.clearAndFree(self.gpa); | ||
| 8408 | self.type_map.clearAndFree(self.gpa); | ||
| 8409 | self.type_items.clearAndFree(self.gpa); | ||
| 8410 | self.type_extra.clearAndFree(self.gpa); | ||
| 8411 | |||
| 8412 | self.attributes.clearAndFree(self.gpa); | ||
| 8413 | self.attributes_map.clearAndFree(self.gpa); | ||
| 8414 | self.attributes_indices.clearAndFree(self.gpa); | ||
| 8415 | self.attributes_extra.clearAndFree(self.gpa); | ||
| 8416 | |||
| 8417 | self.function_attributes_set.clearAndFree(self.gpa); | ||
| 8418 | |||
| 8419 | self.globals.clearAndFree(self.gpa); | ||
| 8420 | self.next_unique_global_id.clearAndFree(self.gpa); | ||
| 8421 | self.aliases.clearAndFree(self.gpa); | ||
| 8422 | self.variables.clearAndFree(self.gpa); | ||
| 8423 | for (self.functions.items) |*function| function.deinit(self.gpa); | ||
| 8424 | self.functions.clearAndFree(self.gpa); | ||
| 8425 | |||
| 8426 | self.constant_map.clearAndFree(self.gpa); | ||
| 8427 | self.constant_items.shrinkAndFree(self.gpa, 0); | ||
| 8428 | self.constant_extra.clearAndFree(self.gpa); | ||
| 8429 | self.constant_limbs.clearAndFree(self.gpa); | ||
| 8430 | |||
| 8431 | self.metadata_map.clearAndFree(self.gpa); | ||
| 8432 | self.metadata_items.shrinkAndFree(self.gpa, 0); | ||
| 8433 | self.metadata_extra.clearAndFree(self.gpa); | ||
| 8434 | self.metadata_limbs.clearAndFree(self.gpa); | ||
| 8435 | self.metadata_forward_references.clearAndFree(self.gpa); | ||
| 8436 | self.metadata_named.clearAndFree(self.gpa); | ||
| 8437 | |||
| 8438 | self.metadata_string_map.clearAndFree(self.gpa); | ||
| 8439 | self.metadata_string_indices.clearAndFree(self.gpa); | ||
| 8440 | self.metadata_string_bytes.clearAndFree(self.gpa); | ||
| 8441 | } | ||
| 8442 | |||
| 8392 | pub fn deinit(self: *Builder) void { | 8443 | pub fn deinit(self: *Builder) void { |
| 8393 | self.module_asm.deinit(self.gpa); | 8444 | self.module_asm.deinit(self.gpa); |
| 8394 | 8445 | ||
| ... | @@ -8723,11 +8774,14 @@ pub fn addFunctionAssumeCapacity( | ... | @@ -8723,11 +8774,14 @@ pub fn addFunctionAssumeCapacity( |
| 8723 | ) Function.Index { | 8774 | ) Function.Index { |
| 8724 | assert(ty.isFunction(self)); | 8775 | assert(ty.isFunction(self)); |
| 8725 | const function_index: Function.Index = @enumFromInt(self.functions.items.len); | 8776 | const function_index: Function.Index = @enumFromInt(self.functions.items.len); |
| 8726 | self.functions.appendAssumeCapacity(.{ .global = self.addGlobalAssumeCapacity(name, .{ | 8777 | self.functions.appendAssumeCapacity(.{ |
| 8727 | .addr_space = addr_space, | 8778 | .global = self.addGlobalAssumeCapacity(name, .{ |
| 8728 | .type = ty, | 8779 | .addr_space = addr_space, |
| 8729 | .kind = .{ .function = function_index }, | 8780 | .type = ty, |
| 8730 | }) }); | 8781 | .kind = .{ .function = function_index }, |
| 8782 | }), | ||
| 8783 | .strip = undefined, | ||
| 8784 | }); | ||
| 8731 | return function_index; | 8785 | return function_index; |
| 8732 | } | 8786 | } |
| 8733 | 8787 | ||
| ... | @@ -14396,16 +14450,17 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14396,16 +14450,17 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14396 | return @intCast(switch (value.unwrap()) { | 14450 | return @intCast(switch (value.unwrap()) { |
| 14397 | .instruction => |instruction| instruction.valueIndex(adapter.func) + adapter.firstInstr(), | 14451 | .instruction => |instruction| instruction.valueIndex(adapter.func) + adapter.firstInstr(), |
| 14398 | .constant => |constant| adapter.constant_adapter.getConstantIndex(constant), | 14452 | .constant => |constant| adapter.constant_adapter.getConstantIndex(constant), |
| 14399 | .metadata => |metadata| if (!adapter.metadata_adapter.builder.strip) blk: { | 14453 | .metadata => |metadata| { |
| 14454 | assert(!adapter.func.strip); | ||
| 14400 | const real_metadata = metadata.unwrap(adapter.metadata_adapter.builder); | 14455 | const real_metadata = metadata.unwrap(adapter.metadata_adapter.builder); |
| 14401 | if (@intFromEnum(real_metadata) < Metadata.first_local_metadata) | 14456 | if (@intFromEnum(real_metadata) < Metadata.first_local_metadata) |
| 14402 | break :blk adapter.metadata_adapter.getMetadataIndex(real_metadata) - 1; | 14457 | return adapter.metadata_adapter.getMetadataIndex(real_metadata) - 1; |
| 14403 | 14458 | ||
| 14404 | return @intCast(@intFromEnum(metadata) - | 14459 | return @intCast(@intFromEnum(metadata) - |
| 14405 | Metadata.first_local_metadata + | 14460 | Metadata.first_local_metadata + |
| 14406 | adapter.metadata_adapter.builder.metadata_string_map.count() - 1 + | 14461 | adapter.metadata_adapter.builder.metadata_string_map.count() - 1 + |
| 14407 | adapter.metadata_adapter.builder.metadata_map.count() - 1); | 14462 | adapter.metadata_adapter.builder.metadata_map.count() - 1); |
| 14408 | } else unreachable, | 14463 | }, |
| 14409 | }); | 14464 | }); |
| 14410 | } | 14465 | } |
| 14411 | 14466 | ||
| ... | @@ -14452,7 +14507,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14452,7 +14507,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14452 | var adapter = FunctionAdapter.init(constant_adapter, metadata_adapter, &func); | 14507 | var adapter = FunctionAdapter.init(constant_adapter, metadata_adapter, &func); |
| 14453 | 14508 | ||
| 14454 | // Emit function level metadata block | 14509 | // Emit function level metadata block |
| 14455 | if (!self.strip and func.debug_values.len != 0) { | 14510 | if (!func.strip and func.debug_values.len > 0) { |
| 14456 | const MetadataBlock = ir.FunctionMetadataBlock; | 14511 | const MetadataBlock = ir.FunctionMetadataBlock; |
| 14457 | var metadata_block = try function_block.enterSubBlock(MetadataBlock); | 14512 | var metadata_block = try function_block.enterSubBlock(MetadataBlock); |
| 14458 | 14513 | ||
| ... | @@ -14913,7 +14968,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14913,7 +14968,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14913 | }, | 14968 | }, |
| 14914 | } | 14969 | } |
| 14915 | 14970 | ||
| 14916 | if (!self.strip) { | 14971 | if (!func.strip) { |
| 14917 | if (func.debug_locations.get(@enumFromInt(instr_index))) |debug_location| { | 14972 | if (func.debug_locations.get(@enumFromInt(instr_index))) |debug_location| { |
| 14918 | switch (debug_location) { | 14973 | switch (debug_location) { |
| 14919 | .no_location => has_location = false, | 14974 | .no_location => has_location = false, |
| ... | @@ -14937,7 +14992,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14937,7 +14992,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14937 | } | 14992 | } |
| 14938 | 14993 | ||
| 14939 | // VALUE_SYMTAB | 14994 | // VALUE_SYMTAB |
| 14940 | if (!self.strip) { | 14995 | if (!func.strip) { |
| 14941 | const ValueSymbolTable = ir.FunctionValueSymbolTable; | 14996 | const ValueSymbolTable = ir.FunctionValueSymbolTable; |
| 14942 | 14997 | ||
| 14943 | var value_symtab_block = try function_block.enterSubBlock(ValueSymbolTable); | 14998 | var value_symtab_block = try function_block.enterSubBlock(ValueSymbolTable); |
| ... | @@ -14959,7 +15014,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14959,7 +15014,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14959 | } | 15014 | } |
| 14960 | 15015 | ||
| 14961 | // METADATA_ATTACHMENT_BLOCK | 15016 | // METADATA_ATTACHMENT_BLOCK |
| 14962 | if (!self.strip) blk: { | 15017 | if (!func.strip) blk: { |
| 14963 | const dbg = func.global.ptrConst(self).dbg; | 15018 | const dbg = func.global.ptrConst(self).dbg; |
| 14964 | 15019 | ||
| 14965 | if (dbg == .none) break :blk; | 15020 | if (dbg == .none) break :blk; |