Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ pub fn build(b: *std.Build) !void {
check_case_exe.want_lto = false;
}

const use_llvm = b.option(bool, "use-llvm", "Use the llvm backend");
exe.use_llvm = use_llvm;
exe.use_lld = use_llvm;

const exe_options = b.addOptions();
exe.addOptions("build_options", exe_options);

Expand Down
2 changes: 1 addition & 1 deletion src/Module.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4120,7 +4120,7 @@ pub fn embedFile(
}
return error.ImportOutsideModulePath;
};
errdefer gpa.free(sub_file_path);
defer gpa.free(sub_file_path);

return newEmbedFile(mod, cur_file.mod, sub_file_path, resolved_path, gop, src_loc);
}
Expand Down
1 change: 1 addition & 0 deletions src/Sema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -23488,6 +23488,7 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
if (b_val.isUndef(mod)) return mod.undefRef(vec_ty);

const elems = try sema.gpa.alloc(InternPool.Index, vec_len);
defer sema.gpa.free(elems);
for (elems, 0..) |*elem, i| {
const pred_elem_val = try pred_val.elemValue(mod, i);
const should_choose_a = pred_elem_val.toBool();
Expand Down
25 changes: 13 additions & 12 deletions src/arch/x86_64/CodeGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ const InstTracking = struct {
tracking_log.debug("%{d} => {} (spilled)", .{ inst, self.* });
}

fn verifyMaterialize(self: *InstTracking, target: InstTracking) void {
fn verifyMaterialize(self: InstTracking, target: InstTracking) void {
switch (self.long) {
.none,
.unreach,
Expand Down Expand Up @@ -634,7 +634,7 @@ const InstTracking = struct {
}

fn materializeUnsafe(
self: *InstTracking,
self: InstTracking,
function: *Self,
inst: Air.Inst.Index,
target: InstTracking,
Expand Down Expand Up @@ -688,7 +688,7 @@ const InstTracking = struct {
}

fn liveOut(self: *InstTracking, function: *Self, inst: Air.Inst.Index) void {
for (self.short.getRegs()) |reg| {
for (self.getRegs()) |reg| {
if (function.register_manager.isRegFree(reg)) {
tracking_log.debug("%{d} => {} (live-out)", .{ inst, self.* });
continue;
Expand All @@ -701,7 +701,7 @@ const InstTracking = struct {
// Disable death.
var found_reg = false;
var remaining_reg: Register = .none;
for (tracking.short.getRegs()) |tracked_reg| if (tracked_reg.id() == reg.id()) {
for (tracking.getRegs()) |tracked_reg| if (tracked_reg.id() == reg.id()) {
assert(!found_reg);
found_reg = true;
} else {
Expand Down Expand Up @@ -10885,12 +10885,12 @@ fn airRet(self: *Self, inst: Air.Inst.Index) !void {
else => unreachable,
}
self.ret_mcv.liveOut(self, inst);
try self.finishAir(inst, .unreach, .{ un_op, .none, .none });

// TODO optimization opportunity: figure out when we can emit this as a 2 byte instruction
// which is available if the jump is 127 bytes or less forward.
const jmp_reloc = try self.asmJmpReloc(undefined);
try self.exitlude_jump_relocs.append(self.gpa, jmp_reloc);
return self.finishAir(inst, .unreach, .{ un_op, .none, .none });
}

fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
Expand All @@ -10905,12 +10905,12 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
else => unreachable,
}
self.ret_mcv.liveOut(self, inst);
try self.finishAir(inst, .unreach, .{ un_op, .none, .none });

// TODO optimization opportunity: figure out when we can emit this as a 2 byte instruction
// which is available if the jump is 127 bytes or less forward.
const jmp_reloc = try self.asmJmpReloc(undefined);
try self.exitlude_jump_relocs.append(self.gpa, jmp_reloc);
return self.finishAir(inst, .unreach, .{ un_op, .none, .none });
}

fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
Expand Down Expand Up @@ -11991,7 +11991,6 @@ fn performReloc(self: *Self, reloc: Mir.Inst.Index) !void {
fn airBr(self: *Self, inst: Air.Inst.Index) !void {
const mod = self.bin_file.options.module.?;
const br = self.air.instructions.items(.data)[inst].br;
const src_mcv = try self.resolveInst(br.operand);

const block_ty = self.typeOfIndex(br.block_inst);
const block_unused =
Expand All @@ -12002,23 +12001,25 @@ fn airBr(self: *Self, inst: Air.Inst.Index) !void {
const block_result = result: {
if (block_unused) break :result .none;

if (!first_br) try self.getValue(block_tracking.short, null);
const src_mcv = try self.resolveInst(br.operand);

if (self.reuseOperandAdvanced(inst, br.operand, 0, src_mcv, br.block_inst)) {
if (first_br) break :result src_mcv;

for (block_tracking.getRegs()) |block_reg|
try self.register_manager.getReg(block_reg, br.block_inst);
try self.getValue(block_tracking.short, br.block_inst);
// .long = .none to avoid merging operand and block result stack frames.
var current_tracking = InstTracking{ .long = .none, .short = src_mcv };
const current_tracking: InstTracking = .{ .long = .none, .short = src_mcv };
try current_tracking.materializeUnsafe(self, br.block_inst, block_tracking.*);
for (src_mcv.getRegs()) |src_reg| self.register_manager.freeReg(src_reg);
for (current_tracking.getRegs()) |src_reg| self.register_manager.freeReg(src_reg);
break :result block_tracking.short;
}

const dst_mcv = if (first_br) try self.allocRegOrMem(br.block_inst, true) else dst: {
try self.getValue(block_tracking.short, br.block_inst);
break :dst block_tracking.short;
};
try self.genCopy(block_ty, dst_mcv, src_mcv);
try self.genCopy(block_ty, dst_mcv, try self.resolveInst(br.operand));
break :result dst_mcv;
};

Expand Down
1 change: 1 addition & 0 deletions src/link/Elf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ pub fn deinit(self: *Elf) void {
self.copy_rel.deinit(gpa);
self.rela_dyn.deinit(gpa);
self.rela_plt.deinit(gpa);
self.zig_got.deinit(gpa);
}

pub fn getDeclVAddr(self: *Elf, decl_index: Module.Decl.Index, reloc_info: link.File.RelocInfo) !u64 {
Expand Down
1 change: 0 additions & 1 deletion test/behavior/packed-struct.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,6 @@ test "modify nested packed struct aligned field" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;

const Options = packed struct {
foo: bool = false,
Expand Down