authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-24 18:24:00-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-24 18:24:00-07:00
log3844b91db72d5c3c98f2b2d97043a0c3de1a3d86
treee89fa901487e0a467bc1ea894ac769fbb9489d2c
parentf4f5b2bc41e09ed68caf3c839433e44bd9b33249

Compilation: build compiler_rt and fuzzer in parallel

With the rest of the pipeline. Tracked by #9188

1 files changed, 18 insertions(+), 25 deletions(-)

src/Compilation.zig+18-25
...@@ -262,9 +262,6 @@ emit_asm: ?EmitLoc,...@@ -262,9 +262,6 @@ emit_asm: ?EmitLoc,
262emit_llvm_ir: ?EmitLoc,262emit_llvm_ir: ?EmitLoc,
263emit_llvm_bc: ?EmitLoc,263emit_llvm_bc: ?EmitLoc,
264264
265work_queue_wait_group: WaitGroup = .{},
266astgen_wait_group: WaitGroup = .{},
267
268llvm_opt_bisect_limit: c_int,265llvm_opt_bisect_limit: c_int,
269266
270file_system_inputs: ?*std.ArrayListUnmanaged(u8),267file_system_inputs: ?*std.ArrayListUnmanaged(u8),
...@@ -3535,13 +3532,13 @@ fn performAllTheWorkInner(...@@ -3535,13 +3532,13 @@ fn performAllTheWorkInner(
3535 // (at least for now) single-threaded main work queue. However, C object compilation3532 // (at least for now) single-threaded main work queue. However, C object compilation
3536 // only needs to be finished by the end of this function.3533 // only needs to be finished by the end of this function.
35373534
3538 comp.work_queue_wait_group.reset();3535 var work_queue_wait_group: WaitGroup = .{};
3539 defer comp.work_queue_wait_group.wait();3536 defer work_queue_wait_group.wait();
35403537
3541 if (comp.docs_emit != null) {3538 if (comp.docs_emit != null) {
3542 dev.check(.docs_emit);3539 dev.check(.docs_emit);
3543 comp.thread_pool.spawnWg(&comp.work_queue_wait_group, workerDocsCopy, .{comp});3540 comp.thread_pool.spawnWg(&work_queue_wait_group, workerDocsCopy, .{comp});
3544 comp.work_queue_wait_group.spawnManager(workerDocsWasm, .{ comp, main_progress_node });3541 work_queue_wait_group.spawnManager(workerDocsWasm, .{ comp, main_progress_node });
3545 }3542 }
35463543
3547 {3544 {
...@@ -3551,8 +3548,8 @@ fn performAllTheWorkInner(...@@ -3551,8 +3548,8 @@ fn performAllTheWorkInner(
3551 const zir_prog_node = main_progress_node.start("AST Lowering", 0);3548 const zir_prog_node = main_progress_node.start("AST Lowering", 0);
3552 defer zir_prog_node.end();3549 defer zir_prog_node.end();
35533550
3554 comp.astgen_wait_group.reset();3551 var astgen_wait_group: WaitGroup = .{};
3555 defer comp.astgen_wait_group.wait();3552 defer astgen_wait_group.wait();
35563553
3557 // builtin.zig is handled specially for two reasons:3554 // builtin.zig is handled specially for two reasons:
3558 // 1. to avoid race condition of zig processes truncating each other's builtin.zig files3555 // 1. to avoid race condition of zig processes truncating each other's builtin.zig files
...@@ -3574,7 +3571,7 @@ fn performAllTheWorkInner(...@@ -3574,7 +3571,7 @@ fn performAllTheWorkInner(
35743571
3575 const file = mod.builtin_file orelse continue;3572 const file = mod.builtin_file orelse continue;
35763573
3577 comp.thread_pool.spawnWg(&comp.astgen_wait_group, workerUpdateBuiltinZigFile, .{3574 comp.thread_pool.spawnWg(&astgen_wait_group, workerUpdateBuiltinZigFile, .{
3578 comp, mod, file,3575 comp, mod, file,
3579 });3576 });
3580 }3577 }
...@@ -3594,32 +3591,36 @@ fn performAllTheWorkInner(...@@ -3594,32 +3591,36 @@ fn performAllTheWorkInner(
3594 const path_digest = zcu.filePathDigest(file_index);3591 const path_digest = zcu.filePathDigest(file_index);
3595 const root_decl = zcu.fileRootDecl(file_index);3592 const root_decl = zcu.fileRootDecl(file_index);
3596 const file = zcu.fileByIndex(file_index);3593 const file = zcu.fileByIndex(file_index);
3597 comp.thread_pool.spawnWgId(&comp.astgen_wait_group, workerAstGenFile, .{3594 comp.thread_pool.spawnWgId(&astgen_wait_group, workerAstGenFile, .{
3598 comp, file, file_index, path_digest, root_decl, zir_prog_node, &comp.astgen_wait_group, .root,3595 comp, file, file_index, path_digest, root_decl, zir_prog_node, &astgen_wait_group, .root,
3599 });3596 });
3600 }3597 }
3601 }3598 }
36023599
3603 while (comp.embed_file_work_queue.readItem()) |embed_file| {3600 while (comp.embed_file_work_queue.readItem()) |embed_file| {
3604 comp.thread_pool.spawnWg(&comp.astgen_wait_group, workerCheckEmbedFile, .{3601 comp.thread_pool.spawnWg(&astgen_wait_group, workerCheckEmbedFile, .{
3605 comp, embed_file,3602 comp, embed_file,
3606 });3603 });
3607 }3604 }
3608 }3605 }
36093606
3610 while (comp.c_object_work_queue.readItem()) |c_object| {3607 while (comp.c_object_work_queue.readItem()) |c_object| {
3611 comp.thread_pool.spawnWg(&comp.work_queue_wait_group, workerUpdateCObject, .{3608 comp.thread_pool.spawnWg(&work_queue_wait_group, workerUpdateCObject, .{
3612 comp, c_object, main_progress_node,3609 comp, c_object, main_progress_node,
3613 });3610 });
3614 }3611 }
36153612
3616 while (comp.win32_resource_work_queue.readItem()) |win32_resource| {3613 while (comp.win32_resource_work_queue.readItem()) |win32_resource| {
3617 comp.thread_pool.spawnWg(&comp.work_queue_wait_group, workerUpdateWin32Resource, .{3614 comp.thread_pool.spawnWg(&work_queue_wait_group, workerUpdateWin32Resource, .{
3618 comp, win32_resource, main_progress_node,3615 comp, win32_resource, main_progress_node,
3619 });3616 });
3620 }3617 }
3621 }3618 }
36223619
3620 if (comp.job_queued_compiler_rt_lib) work_queue_wait_group.spawnManager(buildRt, .{ comp, "compiler_rt.zig", .compiler_rt, .Lib, &comp.compiler_rt_lib, main_progress_node });
3621 if (comp.job_queued_compiler_rt_obj) work_queue_wait_group.spawnManager(buildRt, .{ comp, "compiler_rt.zig", .compiler_rt, .Obj, &comp.compiler_rt_obj, main_progress_node });
3622 if (comp.job_queued_fuzzer_lib) work_queue_wait_group.spawnManager(buildRt, .{ comp, "fuzzer.zig", .libfuzzer, .Lib, &comp.fuzzer_lib, main_progress_node });
3623
3623 if (comp.module) |zcu| {3624 if (comp.module) |zcu| {
3624 const pt: Zcu.PerThread = .{ .zcu = zcu, .tid = .main };3625 const pt: Zcu.PerThread = .{ .zcu = zcu, .tid = .main };
3625 if (comp.incremental) {3626 if (comp.incremental) {
...@@ -3633,7 +3634,7 @@ fn performAllTheWorkInner(...@@ -3633,7 +3634,7 @@ fn performAllTheWorkInner(
3633 zcu.codegen_prog_node = main_progress_node.start("Code Generation", 0);3634 zcu.codegen_prog_node = main_progress_node.start("Code Generation", 0);
3634 }3635 }
36353636
3636 if (!InternPool.single_threaded) comp.thread_pool.spawnWgId(&comp.work_queue_wait_group, codegenThread, .{comp});3637 if (!InternPool.single_threaded) comp.thread_pool.spawnWgId(&work_queue_wait_group, codegenThread, .{comp});
3637 defer if (!InternPool.single_threaded) {3638 defer if (!InternPool.single_threaded) {
3638 {3639 {
3639 comp.codegen_work.mutex.lock();3640 comp.codegen_work.mutex.lock();
...@@ -3661,10 +3662,6 @@ fn performAllTheWorkInner(...@@ -3661,10 +3662,6 @@ fn performAllTheWorkInner(
3661 }3662 }
3662 break;3663 break;
3663 }3664 }
3664
3665 buildCompilerRtOneShot(comp, &comp.job_queued_compiler_rt_lib, "compiler_rt.zig", .compiler_rt, .Lib, &comp.compiler_rt_lib, main_progress_node);
3666 buildCompilerRtOneShot(comp, &comp.job_queued_compiler_rt_obj, "compiler_rt.zig", .compiler_rt, .Obj, &comp.compiler_rt_obj, main_progress_node);
3667 buildCompilerRtOneShot(comp, &comp.job_queued_fuzzer_lib, "fuzzer.zig", .libfuzzer, .Lib, &comp.fuzzer_lib, main_progress_node);
3668}3665}
36693666
3670const JobError = Allocator.Error;3667const JobError = Allocator.Error;
...@@ -4668,18 +4665,14 @@ fn workerUpdateWin32Resource(...@@ -4668,18 +4665,14 @@ fn workerUpdateWin32Resource(
4668 };4665 };
4669}4666}
46704667
4671fn buildCompilerRtOneShot(4668fn buildRt(
4672 comp: *Compilation,4669 comp: *Compilation,
4673 job_queued: *bool,
4674 root_source_name: []const u8,4670 root_source_name: []const u8,
4675 misc_task: MiscTask,4671 misc_task: MiscTask,
4676 output_mode: std.builtin.OutputMode,4672 output_mode: std.builtin.OutputMode,
4677 out: *?CRTFile,4673 out: *?CRTFile,
4678 prog_node: std.Progress.Node,4674 prog_node: std.Progress.Node,
4679) void {4675) void {
4680 if (!job_queued.*) return;
4681 job_queued.* = false;
4682
4683 comp.buildOutputFromZig(4676 comp.buildOutputFromZig(
4684 root_source_name,4677 root_source_name,
4685 output_mode,4678 output_mode,