| author | |
| committer | |
| log | 1e1598950aeb20e8f414fdb3993109f05f1b4765 |
| tree | 80e2028257e69c9c4d44954d00fe18d51eb159d4 |
| parent | 661137ac92ef05490a22dfcfb812a81a3014f0c7 |
This avoids llvm module verification errors when the strip option
is different across modules.3 files changed, 69 insertions(+), 52 deletions(-)
src/Sema.zig+2-2| ... | @@ -6415,8 +6415,6 @@ fn zirDbgVar( | ... | @@ -6415,8 +6415,6 @@ fn zirDbgVar( |
| 6415 | inst: Zir.Inst.Index, | 6415 | inst: Zir.Inst.Index, |
| 6416 | air_tag: Air.Inst.Tag, | 6416 | air_tag: Air.Inst.Tag, |
| 6417 | ) CompileError!void { | 6417 | ) CompileError!void { |
| 6418 | if (block.is_comptime or block.ownerModule().strip) return; | ||
| 6419 | |||
| 6420 | const str_op = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_op; | 6418 | const str_op = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_op; |
| 6421 | const operand = try sema.resolveInst(str_op.operand); | 6419 | const operand = try sema.resolveInst(str_op.operand); |
| 6422 | const name = str_op.getStr(sema.code); | 6420 | const name = str_op.getStr(sema.code); |
| ... | @@ -6430,6 +6428,8 @@ fn addDbgVar( | ... | @@ -6430,6 +6428,8 @@ fn addDbgVar( |
| 6430 | air_tag: Air.Inst.Tag, | 6428 | air_tag: Air.Inst.Tag, |
| 6431 | name: []const u8, | 6429 | name: []const u8, |
| 6432 | ) CompileError!void { | 6430 | ) CompileError!void { |
| 6431 | if (block.is_comptime or block.ownerModule().strip) return; | ||
| 6432 | |||
| 6433 | const mod = sema.mod; | 6433 | const mod = sema.mod; |
| 6434 | const operand_ty = sema.typeOf(operand); | 6434 | const operand_ty = sema.typeOf(operand); |
| 6435 | const val_ty = switch (air_tag) { | 6435 | const val_ty = switch (air_tag) { |
src/codegen/llvm.zig+32-26| ... | @@ -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 | ||
| ... | @@ -1372,6 +1374,7 @@ pub const Object = struct { | ... | @@ -1372,6 +1374,7 @@ pub const Object = struct { |
| 1372 | air: Air, | 1374 | air: Air, |
| 1373 | liveness: Liveness, | 1375 | liveness: Liveness, |
| 1374 | ) !void { | 1376 | ) !void { |
| 1377 | const comp = zcu.comp; | ||
| 1375 | const func = zcu.funcInfo(func_index); | 1378 | const func = zcu.funcInfo(func_index); |
| 1376 | const decl_index = func.owner_decl; | 1379 | const decl_index = func.owner_decl; |
| 1377 | const decl = zcu.declPtr(decl_index); | 1380 | const decl = zcu.declPtr(decl_index); |
| ... | @@ -1440,7 +1443,10 @@ pub const Object = struct { | ... | @@ -1440,7 +1443,10 @@ pub const Object = struct { |
| 1440 | function_index.setSection(try o.builder.string(section), &o.builder); | 1443 | function_index.setSection(try o.builder.string(section), &o.builder); |
| 1441 | 1444 | ||
| 1442 | var deinit_wip = true; | 1445 | var deinit_wip = true; |
| 1443 | var wip = try Builder.WipFunction.init(&o.builder, function_index); | 1446 | var wip = try Builder.WipFunction.init(&o.builder, .{ |
| 1447 | .function = function_index, | ||
| 1448 | .strip = owner_mod.strip, | ||
| 1449 | }); | ||
| 1444 | defer if (deinit_wip) wip.deinit(); | 1450 | defer if (deinit_wip) wip.deinit(); |
| 1445 | wip.cursor = .{ .block = try wip.block(0, "Entry") }; | 1451 | wip.cursor = .{ .block = try wip.block(0, "Entry") }; |
| 1446 | 1452 | ||
| ... | @@ -1459,8 +1465,6 @@ pub const Object = struct { | ... | @@ -1459,8 +1465,6 @@ pub const Object = struct { |
| 1459 | .unsigned => try attributes.addRetAttr(.zeroext, &o.builder), | 1465 | .unsigned => try attributes.addRetAttr(.zeroext, &o.builder), |
| 1460 | }; | 1466 | }; |
| 1461 | 1467 | ||
| 1462 | const comp = zcu.comp; | ||
| 1463 | |||
| 1464 | const err_return_tracing = Type.fromInterned(fn_info.return_type).isError(zcu) and | 1468 | const err_return_tracing = Type.fromInterned(fn_info.return_type).isError(zcu) and |
| 1465 | comp.config.any_error_tracing; | 1469 | comp.config.any_error_tracing; |
| 1466 | 1470 | ||
| ... | @@ -1645,7 +1649,7 @@ pub const Object = struct { | ... | @@ -1645,7 +1649,7 @@ pub const Object = struct { |
| 1645 | 1649 | ||
| 1646 | function_index.setAttributes(try attributes.finish(&o.builder), &o.builder); | 1650 | function_index.setAttributes(try attributes.finish(&o.builder), &o.builder); |
| 1647 | 1651 | ||
| 1648 | const file, const subprogram = if (!o.builder.strip) debug_info: { | 1652 | const file, const subprogram = if (!wip.strip) debug_info: { |
| 1649 | const file = try o.getDebugFile(namespace.file_scope); | 1653 | const file = try o.getDebugFile(namespace.file_scope); |
| 1650 | 1654 | ||
| 1651 | const line_number = decl.src_line + 1; | 1655 | const line_number = decl.src_line + 1; |
| ... | @@ -4616,7 +4620,10 @@ pub const Object = struct { | ... | @@ -4616,7 +4620,10 @@ pub const Object = struct { |
| 4616 | function_index.setAttributes(try attributes.finish(&o.builder), &o.builder); | 4620 | function_index.setAttributes(try attributes.finish(&o.builder), &o.builder); |
| 4617 | gop.value_ptr.* = function_index.ptrConst(&o.builder).global; | 4621 | gop.value_ptr.* = function_index.ptrConst(&o.builder).global; |
| 4618 | 4622 | ||
| 4619 | 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 | }); | ||
| 4620 | defer wip.deinit(); | 4627 | defer wip.deinit(); |
| 4621 | wip.cursor = .{ .block = try wip.block(0, "Entry") }; | 4628 | wip.cursor = .{ .block = try wip.block(0, "Entry") }; |
| 4622 | 4629 | ||
| ... | @@ -4686,23 +4693,23 @@ pub const DeclGen = struct { | ... | @@ -4686,23 +4693,23 @@ pub const DeclGen = struct { |
| 4686 | 4693 | ||
| 4687 | fn genDecl(dg: *DeclGen) !void { | 4694 | fn genDecl(dg: *DeclGen) !void { |
| 4688 | const o = dg.object; | 4695 | const o = dg.object; |
| 4689 | const mod = o.module; | 4696 | const zcu = o.module; |
| 4690 | const decl = dg.decl; | 4697 | const decl = dg.decl; |
| 4691 | const decl_index = dg.decl_index; | 4698 | const decl_index = dg.decl_index; |
| 4692 | assert(decl.has_tv); | 4699 | assert(decl.has_tv); |
| 4693 | 4700 | ||
| 4694 | if (decl.val.getExternFunc(mod)) |extern_func| { | 4701 | if (decl.val.getExternFunc(zcu)) |extern_func| { |
| 4695 | _ = try o.resolveLlvmFunction(extern_func.decl); | 4702 | _ = try o.resolveLlvmFunction(extern_func.decl); |
| 4696 | } else { | 4703 | } else { |
| 4697 | const variable_index = try o.resolveGlobalDecl(decl_index); | 4704 | const variable_index = try o.resolveGlobalDecl(decl_index); |
| 4698 | variable_index.setAlignment( | 4705 | variable_index.setAlignment( |
| 4699 | decl.getAlignment(mod).toLlvm(), | 4706 | decl.getAlignment(zcu).toLlvm(), |
| 4700 | &o.builder, | 4707 | &o.builder, |
| 4701 | ); | 4708 | ); |
| 4702 | if (mod.intern_pool.stringToSliceUnwrap(decl.@"linksection")) |section| | 4709 | if (zcu.intern_pool.stringToSliceUnwrap(decl.@"linksection")) |section| |
| 4703 | variable_index.setSection(try o.builder.string(section), &o.builder); | 4710 | variable_index.setSection(try o.builder.string(section), &o.builder); |
| 4704 | assert(decl.has_tv); | 4711 | assert(decl.has_tv); |
| 4705 | 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: { |
| 4706 | variable_index.setMutability(.constant, &o.builder); | 4713 | variable_index.setMutability(.constant, &o.builder); |
| 4707 | break :init_val decl.val.toIntern(); | 4714 | break :init_val decl.val.toIntern(); |
| 4708 | }; | 4715 | }; |
| ... | @@ -4714,12 +4721,15 @@ pub const DeclGen = struct { | ... | @@ -4714,12 +4721,15 @@ pub const DeclGen = struct { |
| 4714 | const line_number = decl.src_line + 1; | 4721 | const line_number = decl.src_line + 1; |
| 4715 | const is_internal_linkage = !o.module.decl_exports.contains(decl_index); | 4722 | const is_internal_linkage = !o.module.decl_exports.contains(decl_index); |
| 4716 | 4723 | ||
| 4717 | if (dg.object.builder.strip) return; | 4724 | const namespace = zcu.namespacePtr(decl.src_namespace); |
| 4725 | const owner_mod = namespace.file_scope.mod; | ||
| 4718 | 4726 | ||
| 4719 | 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); | ||
| 4720 | 4730 | ||
| 4721 | const debug_global_var = try o.builder.debugGlobalVar( | 4731 | const debug_global_var = try o.builder.debugGlobalVar( |
| 4722 | try o.builder.metadataString(mod.intern_pool.stringToSlice(decl.name)), // Name | 4732 | try o.builder.metadataString(zcu.intern_pool.stringToSlice(decl.name)), // Name |
| 4723 | try o.builder.metadataStringFromString(variable_index.name(&o.builder)), // Linkage name | 4733 | try o.builder.metadataStringFromString(variable_index.name(&o.builder)), // Linkage name |
| 4724 | debug_file, // File | 4734 | debug_file, // File |
| 4725 | debug_file, // Scope | 4735 | debug_file, // Scope |
| ... | @@ -4735,7 +4745,7 @@ pub const DeclGen = struct { | ... | @@ -4735,7 +4745,7 @@ pub const DeclGen = struct { |
| 4735 | debug_global_var, | 4745 | debug_global_var, |
| 4736 | debug_expression, | 4746 | debug_expression, |
| 4737 | ); | 4747 | ); |
| 4738 | if (!is_internal_linkage or decl.isExtern(mod)) | 4748 | if (!is_internal_linkage or decl.isExtern(zcu)) |
| 4739 | variable_index.setGlobalVariableExpression(debug_global_var_expression, &o.builder); | 4749 | variable_index.setGlobalVariableExpression(debug_global_var_expression, &o.builder); |
| 4740 | try o.debug_globals.append(o.gpa, debug_global_var_expression); | 4750 | try o.debug_globals.append(o.gpa, debug_global_var_expression); |
| 4741 | } | 4751 | } |
| ... | @@ -6570,7 +6580,6 @@ pub const FuncGen = struct { | ... | @@ -6570,7 +6580,6 @@ pub const FuncGen = struct { |
| 6570 | } | 6580 | } |
| 6571 | 6581 | ||
| 6572 | fn airDbgStmt(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 6582 | fn airDbgStmt(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6573 | if (self.wip.builder.strip) return .none; | ||
| 6574 | 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; |
| 6575 | 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); |
| 6576 | self.prev_dbg_column = @intCast(dbg_stmt.column + 1); | 6585 | self.prev_dbg_column = @intCast(dbg_stmt.column + 1); |
| ... | @@ -6593,7 +6602,6 @@ pub const FuncGen = struct { | ... | @@ -6593,7 +6602,6 @@ pub const FuncGen = struct { |
| 6593 | } | 6602 | } |
| 6594 | 6603 | ||
| 6595 | fn airDbgInlineBegin(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 6604 | fn airDbgInlineBegin(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6596 | if (self.wip.builder.strip) return .none; | ||
| 6597 | const o = self.dg.object; | 6605 | const o = self.dg.object; |
| 6598 | const zcu = o.module; | 6606 | const zcu = o.module; |
| 6599 | 6607 | ||
| ... | @@ -6660,7 +6668,6 @@ pub const FuncGen = struct { | ... | @@ -6660,7 +6668,6 @@ pub const FuncGen = struct { |
| 6660 | } | 6668 | } |
| 6661 | 6669 | ||
| 6662 | 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 { |
| 6663 | if (self.wip.builder.strip) return .none; | ||
| 6664 | const o = self.dg.object; | 6671 | const o = self.dg.object; |
| 6665 | 6672 | ||
| 6666 | 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; |
| ... | @@ -6677,7 +6684,6 @@ pub const FuncGen = struct { | ... | @@ -6677,7 +6684,6 @@ pub const FuncGen = struct { |
| 6677 | } | 6684 | } |
| 6678 | 6685 | ||
| 6679 | fn airDbgBlockBegin(self: *FuncGen) Allocator.Error!Builder.Value { | 6686 | fn airDbgBlockBegin(self: *FuncGen) Allocator.Error!Builder.Value { |
| 6680 | if (self.wip.builder.strip) return .none; | ||
| 6681 | const o = self.dg.object; | 6687 | const o = self.dg.object; |
| 6682 | 6688 | ||
| 6683 | try self.scope_stack.append(self.gpa, self.scope); | 6689 | try self.scope_stack.append(self.gpa, self.scope); |
| ... | @@ -6693,13 +6699,11 @@ pub const FuncGen = struct { | ... | @@ -6693,13 +6699,11 @@ pub const FuncGen = struct { |
| 6693 | } | 6699 | } |
| 6694 | 6700 | ||
| 6695 | fn airDbgBlockEnd(self: *FuncGen) !Builder.Value { | 6701 | fn airDbgBlockEnd(self: *FuncGen) !Builder.Value { |
| 6696 | if (self.wip.builder.strip) return .none; | ||
| 6697 | self.scope = self.scope_stack.pop(); | 6702 | self.scope = self.scope_stack.pop(); |
| 6698 | return .none; | 6703 | return .none; |
| 6699 | } | 6704 | } |
| 6700 | 6705 | ||
| 6701 | fn airDbgVarPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 6706 | fn airDbgVarPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6702 | if (self.wip.builder.strip) return .none; | ||
| 6703 | const o = self.dg.object; | 6707 | const o = self.dg.object; |
| 6704 | const mod = o.module; | 6708 | const mod = o.module; |
| 6705 | 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; |
| ... | @@ -6732,7 +6736,6 @@ pub const FuncGen = struct { | ... | @@ -6732,7 +6736,6 @@ pub const FuncGen = struct { |
| 6732 | } | 6736 | } |
| 6733 | 6737 | ||
| 6734 | fn airDbgVarVal(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { | 6738 | fn airDbgVarVal(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6735 | if (self.wip.builder.strip) return .none; | ||
| 6736 | const o = self.dg.object; | 6739 | const o = self.dg.object; |
| 6737 | 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; |
| 6738 | const operand = try self.resolveInst(pl_op.operand); | 6741 | const operand = try self.resolveInst(pl_op.operand); |
| ... | @@ -8813,7 +8816,7 @@ pub const FuncGen = struct { | ... | @@ -8813,7 +8816,7 @@ pub const FuncGen = struct { |
| 8813 | const arg_val = self.args[self.arg_index]; | 8816 | const arg_val = self.args[self.arg_index]; |
| 8814 | self.arg_index += 1; | 8817 | self.arg_index += 1; |
| 8815 | 8818 | ||
| 8816 | if (self.wip.builder.strip) return arg_val; | 8819 | if (self.wip.strip) return arg_val; |
| 8817 | 8820 | ||
| 8818 | const inst_ty = self.typeOfIndex(inst); | 8821 | const inst_ty = self.typeOfIndex(inst); |
| 8819 | if (needDbgVarWorkaround(o)) return arg_val; | 8822 | if (needDbgVarWorkaround(o)) return arg_val; |
| ... | @@ -9660,7 +9663,10 @@ pub const FuncGen = struct { | ... | @@ -9660,7 +9663,10 @@ pub const FuncGen = struct { |
| 9660 | function_index.setAttributes(try attributes.finish(&o.builder), &o.builder); | 9663 | function_index.setAttributes(try attributes.finish(&o.builder), &o.builder); |
| 9661 | gop.value_ptr.* = function_index; | 9664 | gop.value_ptr.* = function_index; |
| 9662 | 9665 | ||
| 9663 | var wip = try Builder.WipFunction.init(&o.builder, function_index); | 9666 | var wip = try Builder.WipFunction.init(&o.builder, .{ |
| 9667 | .function = function_index, | ||
| 9668 | .strip = true, | ||
| 9669 | }); | ||
| 9664 | defer wip.deinit(); | 9670 | defer wip.deinit(); |
| 9665 | wip.cursor = .{ .block = try wip.block(0, "Entry") }; | 9671 | wip.cursor = .{ .block = try wip.block(0, "Entry") }; |
| 9666 | 9672 |
src/codegen/llvm/Builder.zig+35-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)) |
| ... | @@ -8723,11 +8730,14 @@ pub fn addFunctionAssumeCapacity( | ... | @@ -8723,11 +8730,14 @@ pub fn addFunctionAssumeCapacity( |
| 8723 | ) Function.Index { | 8730 | ) Function.Index { |
| 8724 | assert(ty.isFunction(self)); | 8731 | assert(ty.isFunction(self)); |
| 8725 | const function_index: Function.Index = @enumFromInt(self.functions.items.len); | 8732 | const function_index: Function.Index = @enumFromInt(self.functions.items.len); |
| 8726 | self.functions.appendAssumeCapacity(.{ .global = self.addGlobalAssumeCapacity(name, .{ | 8733 | self.functions.appendAssumeCapacity(.{ |
| 8727 | .addr_space = addr_space, | 8734 | .global = self.addGlobalAssumeCapacity(name, .{ |
| 8728 | .type = ty, | 8735 | .addr_space = addr_space, |
| 8729 | .kind = .{ .function = function_index }, | 8736 | .type = ty, |
| 8730 | }) }); | 8737 | .kind = .{ .function = function_index }, |
| 8738 | }), | ||
| 8739 | .strip = undefined, | ||
| 8740 | }); | ||
| 8731 | return function_index; | 8741 | return function_index; |
| 8732 | } | 8742 | } |
| 8733 | 8743 | ||
| ... | @@ -14396,16 +14406,17 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14396,16 +14406,17 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14396 | return @intCast(switch (value.unwrap()) { | 14406 | return @intCast(switch (value.unwrap()) { |
| 14397 | .instruction => |instruction| instruction.valueIndex(adapter.func) + adapter.firstInstr(), | 14407 | .instruction => |instruction| instruction.valueIndex(adapter.func) + adapter.firstInstr(), |
| 14398 | .constant => |constant| adapter.constant_adapter.getConstantIndex(constant), | 14408 | .constant => |constant| adapter.constant_adapter.getConstantIndex(constant), |
| 14399 | .metadata => |metadata| if (!adapter.metadata_adapter.builder.strip) blk: { | 14409 | .metadata => |metadata| { |
| 14410 | assert(!adapter.func.strip); | ||
| 14400 | const real_metadata = metadata.unwrap(adapter.metadata_adapter.builder); | 14411 | const real_metadata = metadata.unwrap(adapter.metadata_adapter.builder); |
| 14401 | if (@intFromEnum(real_metadata) < Metadata.first_local_metadata) | 14412 | if (@intFromEnum(real_metadata) < Metadata.first_local_metadata) |
| 14402 | break :blk adapter.metadata_adapter.getMetadataIndex(real_metadata) - 1; | 14413 | return adapter.metadata_adapter.getMetadataIndex(real_metadata) - 1; |
| 14403 | 14414 | ||
| 14404 | return @intCast(@intFromEnum(metadata) - | 14415 | return @intCast(@intFromEnum(metadata) - |
| 14405 | Metadata.first_local_metadata + | 14416 | Metadata.first_local_metadata + |
| 14406 | adapter.metadata_adapter.builder.metadata_string_map.count() - 1 + | 14417 | adapter.metadata_adapter.builder.metadata_string_map.count() - 1 + |
| 14407 | adapter.metadata_adapter.builder.metadata_map.count() - 1); | 14418 | adapter.metadata_adapter.builder.metadata_map.count() - 1); |
| 14408 | } else unreachable, | 14419 | }, |
| 14409 | }); | 14420 | }); |
| 14410 | } | 14421 | } |
| 14411 | 14422 | ||
| ... | @@ -14452,7 +14463,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14452,7 +14463,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14452 | var adapter = FunctionAdapter.init(constant_adapter, metadata_adapter, &func); | 14463 | var adapter = FunctionAdapter.init(constant_adapter, metadata_adapter, &func); |
| 14453 | 14464 | ||
| 14454 | // Emit function level metadata block | 14465 | // Emit function level metadata block |
| 14455 | if (!self.strip and func.debug_values.len != 0) { | 14466 | if (!func.strip and func.debug_values.len > 0) { |
| 14456 | const MetadataBlock = ir.FunctionMetadataBlock; | 14467 | const MetadataBlock = ir.FunctionMetadataBlock; |
| 14457 | var metadata_block = try function_block.enterSubBlock(MetadataBlock); | 14468 | var metadata_block = try function_block.enterSubBlock(MetadataBlock); |
| 14458 | 14469 | ||
| ... | @@ -14913,7 +14924,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14913,7 +14924,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14913 | }, | 14924 | }, |
| 14914 | } | 14925 | } |
| 14915 | 14926 | ||
| 14916 | if (!self.strip) { | 14927 | if (!func.strip) { |
| 14917 | if (func.debug_locations.get(@enumFromInt(instr_index))) |debug_location| { | 14928 | if (func.debug_locations.get(@enumFromInt(instr_index))) |debug_location| { |
| 14918 | switch (debug_location) { | 14929 | switch (debug_location) { |
| 14919 | .no_location => has_location = false, | 14930 | .no_location => has_location = false, |
| ... | @@ -14937,7 +14948,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14937,7 +14948,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14937 | } | 14948 | } |
| 14938 | 14949 | ||
| 14939 | // VALUE_SYMTAB | 14950 | // VALUE_SYMTAB |
| 14940 | if (!self.strip) { | 14951 | if (!func.strip) { |
| 14941 | const ValueSymbolTable = ir.FunctionValueSymbolTable; | 14952 | const ValueSymbolTable = ir.FunctionValueSymbolTable; |
| 14942 | 14953 | ||
| 14943 | var value_symtab_block = try function_block.enterSubBlock(ValueSymbolTable); | 14954 | var value_symtab_block = try function_block.enterSubBlock(ValueSymbolTable); |
| ... | @@ -14959,7 +14970,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14959,7 +14970,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14959 | } | 14970 | } |
| 14960 | 14971 | ||
| 14961 | // METADATA_ATTACHMENT_BLOCK | 14972 | // METADATA_ATTACHMENT_BLOCK |
| 14962 | if (!self.strip) blk: { | 14973 | if (!func.strip) blk: { |
| 14963 | const dbg = func.global.ptrConst(self).dbg; | 14974 | const dbg = func.global.ptrConst(self).dbg; |
| 14964 | 14975 | ||
| 14965 | if (dbg == .none) break :blk; | 14976 | if (dbg == .none) break :blk; |