Skip to content

Commit

Permalink
stage2: rip out multi-compilation-unit compiler-rt
Browse files Browse the repository at this point in the history
After doing performance testing, it seems that multi-compilation-unit
compiler-rt did not bring the performance improvements that we expected
it to. The idea is that it makes linking faster, however, it incurred a
cost in the frontend that was not offset by any gains in linking.

Furthermore, the single-object compiler-rt (with -ffunction-sections and
--gc-sections) ends up being fewer bytes on disk and so it's actually
the same or faster linking speed than the multi-compilation-unit
version.

So we are planning to keep using single-compilation-unit compiler-rt for
the foreseeable future, but may experiment with this again in the
future, in which case this commit can be reverted.
  • Loading branch information
andrewrk committed Jun 18, 2022
1 parent 2064d86 commit e4092d4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 451 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Expand Up @@ -735,7 +735,6 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/src/codegen/c.zig"
"${CMAKE_SOURCE_DIR}/src/codegen/llvm.zig"
"${CMAKE_SOURCE_DIR}/src/codegen/llvm/bindings.zig"
"${CMAKE_SOURCE_DIR}/src/compiler_rt.zig"
"${CMAKE_SOURCE_DIR}/src/glibc.zig"
"${CMAKE_SOURCE_DIR}/src/introspect.zig"
"${CMAKE_SOURCE_DIR}/src/libc_installation.zig"
Expand Down
54 changes: 10 additions & 44 deletions src/Compilation.zig
Expand Up @@ -23,7 +23,6 @@ const mingw = @import("mingw.zig");
const libunwind = @import("libunwind.zig");
const libcxx = @import("libcxx.zig");
const wasi_libc = @import("wasi_libc.zig");
const compiler_rt = @import("compiler_rt.zig");
const fatal = @import("main.zig").fatal;
const clangMain = @import("main.zig").clangMain;
const Module = @import("Module.zig");
Expand Down Expand Up @@ -2745,10 +2744,6 @@ pub fn performAllTheWork(
var embed_file_prog_node = main_progress_node.start("Detect @embedFile updates", comp.embed_file_work_queue.count);
defer embed_file_prog_node.end();

// +1 for the link step
var compiler_rt_prog_node = main_progress_node.start("compiler_rt", compiler_rt.sources.len + 1);
defer compiler_rt_prog_node.end();

comp.work_queue_wait_group.reset();
defer comp.work_queue_wait_group.wait();

Expand Down Expand Up @@ -2796,28 +2791,6 @@ pub fn performAllTheWork(
comp, c_object, &c_obj_prog_node, &comp.work_queue_wait_group,
});
}

if (comp.job_queued_compiler_rt_lib) {
comp.job_queued_compiler_rt_lib = false;

// I have disabled the multi-threaded compiler-rt for now until
// the threading deadlock is resolved.
if (use_stage1 or true) {
// stage1 LLVM backend uses the global context and thus cannot be used in
// a multi-threaded context.
buildCompilerRtOneShot(comp, .Lib, &comp.compiler_rt_lib);
} else {
comp.work_queue_wait_group.start();
try comp.thread_pool.spawn(workerBuildCompilerRtLib, .{
comp, &compiler_rt_prog_node, &comp.work_queue_wait_group,
});
}
}

if (comp.job_queued_compiler_rt_obj) {
comp.job_queued_compiler_rt_obj = false;
buildCompilerRtOneShot(comp, .Obj, &comp.compiler_rt_obj);
}
}

if (!use_stage1) {
Expand Down Expand Up @@ -2862,6 +2835,16 @@ pub fn performAllTheWork(
}
break;
}

if (comp.job_queued_compiler_rt_lib) {
comp.job_queued_compiler_rt_lib = false;
buildCompilerRtOneShot(comp, .Lib, &comp.compiler_rt_lib);
}

if (comp.job_queued_compiler_rt_obj) {
comp.job_queued_compiler_rt_obj = false;
buildCompilerRtOneShot(comp, .Obj, &comp.compiler_rt_obj);
}
}

fn processOneJob(comp: *Compilation, job: Job) !void {
Expand Down Expand Up @@ -3534,23 +3517,6 @@ fn buildCompilerRtOneShot(
};
}

fn workerBuildCompilerRtLib(
comp: *Compilation,
progress_node: *std.Progress.Node,
wg: *WaitGroup,
) void {
defer wg.finish();

compiler_rt.buildCompilerRtLib(comp, progress_node) catch |err| switch (err) {
error.SubCompilationFailed => return, // error reported already
else => comp.lockAndSetMiscFailure(
.compiler_rt,
"unable to build compiler_rt: {s}",
.{@errorName(err)},
),
};
}

fn reportRetryableCObjectError(
comp: *Compilation,
c_object: *CObject,
Expand Down

0 comments on commit e4092d4

Please sign in to comment.