Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support running LLVM backend in a separate thread #21068

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 13 additions & 1 deletion src/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2442,7 +2442,15 @@ fn flush(
try link.File.C.flushEmitH(zcu);

if (zcu.llvm_object) |llvm_object| {
try emitLlvmObject(comp, arena, default_artifact_directory, null, llvm_object, prog_node);
try emitLlvmObject(
comp,
arena,
default_artifact_directory,
null,
llvm_object,
prog_node,
tid,
);
}
}
}
Expand Down Expand Up @@ -2725,11 +2733,15 @@ pub fn emitLlvmObject(
bin_emit_loc: ?EmitLoc,
llvm_object: LlvmObject.Ptr,
prog_node: std.Progress.Node,
tid: Zcu.PerThread.Id,
) !void {
const sub_prog_node = prog_node.start("LLVM Emit Object", 0);
defer sub_prog_node.end();

try llvm_object.emit(.{
.zcu = comp.zcu.?,
.tid = tid,
}, .{
.pre_ir_path = comp.verbose_llvm_ir,
.pre_bc_path = comp.verbose_llvm_bc,
.bin_path = try resolveEmitLoc(arena, default_artifact_directory, bin_emit_loc),
Expand Down
2 changes: 2 additions & 0 deletions src/Sema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10235,6 +10235,8 @@ fn finishFunc(
// lower this fn type.
const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace");
try unresolved_stack_trace_ty.resolveFields(pt);

if (zcu.stack_trace_type == .none) zcu.stack_trace_type = unresolved_stack_trace_ty.toIntern();
}

return Air.internedToRef(if (opt_func_index != .none) opt_func_index else func_ty);
Expand Down
1 change: 1 addition & 0 deletions src/Zcu.zig
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ panic_messages: [PanicId.len]InternPool.Nav.Index.Optional = .{.none} ** PanicId
/// The panic function body.
panic_func_index: InternPool.Index = .none,
null_stack_trace: InternPool.Index = .none,
stack_trace_type: InternPool.Index = .none,

generation: u32 = 0,

Expand Down
1,208 changes: 608 additions & 600 deletions src/codegen/llvm.zig

Large diffs are not rendered by default.

22 changes: 15 additions & 7 deletions src/link.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1348,14 +1348,22 @@ pub const File = struct {
arena: Allocator,
llvm_object: LlvmObject.Ptr,
prog_node: std.Progress.Node,
tid: Zcu.PerThread.Id,
) !void {
return base.comp.emitLlvmObject(arena, .{
.root_dir = base.emit.root_dir,
.sub_path = std.fs.path.dirname(base.emit.sub_path) orelse "",
}, .{
.directory = null,
.basename = base.zcu_object_sub_path.?,
}, llvm_object, prog_node);
return base.comp.emitLlvmObject(
arena,
.{
.root_dir = base.emit.root_dir,
.sub_path = std.fs.path.dirname(base.emit.sub_path) orelse "",
},
.{
.directory = null,
.basename = base.zcu_object_sub_path.?,
},
llvm_object,
prog_node,
tid,
);
}

pub const C = @import("link/C.zig");
Expand Down
2 changes: 1 addition & 1 deletion src/link/Coff.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2216,7 +2216,7 @@ pub fn flushModule(coff: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_no
const diags = &comp.link_diags;

if (coff.llvm_object) |llvm_object| {
try coff.base.emitLlvmObject(arena, llvm_object, prog_node);
try coff.base.emitLlvmObject(arena, llvm_object, prog_node, tid);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/link/Elf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ pub fn flushModule(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_nod
const diags = &comp.link_diags;

if (self.llvm_object) |llvm_object| {
try self.base.emitLlvmObject(arena, llvm_object, prog_node);
try self.base.emitLlvmObject(arena, llvm_object, prog_node, tid);
const use_lld = build_options.have_llvm and comp.config.use_lld;
if (use_lld) return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/link/MachO.zig
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ pub fn flushModule(self: *MachO, arena: Allocator, tid: Zcu.PerThread.Id, prog_n
const diags = &self.base.comp.link_diags;

if (self.llvm_object) |llvm_object| {
try self.base.emitLlvmObject(arena, llvm_object, prog_node);
try self.base.emitLlvmObject(arena, llvm_object, prog_node, tid);
}

const sub_prog_node = prog_node.start("MachO Flush", 0);
Expand Down
2 changes: 1 addition & 1 deletion src/link/Wasm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2626,7 +2626,7 @@ pub fn flushModule(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_no
const comp = wasm.base.comp;
const diags = &comp.link_diags;
if (wasm.llvm_object) |llvm_object| {
try wasm.base.emitLlvmObject(arena, llvm_object, prog_node);
try wasm.base.emitLlvmObject(arena, llvm_object, prog_node, tid);
const use_lld = build_options.have_llvm and comp.config.use_lld;
if (use_lld) return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ pub inline fn backendSupportsFeature(backend: std.builtin.CompilerBackend, compt
else => false,
},
.separate_thread => switch (backend) {
.stage2_llvm => false,
.stage2_llvm => true,
else => true,
},
};
Expand Down
Loading