aboutsummaryrefslogtreecommitdiff
path: root/src/libs
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2025-05-29 05:38:55 +0100
committermlugg <mlugg@mlugg.co.uk>2025-06-12 13:55:40 +0100
commit9eb400ef19391261a3b61129d8665602c89959c5 (patch)
treefc7046857c3271294a8ebfcd462ece05b0be5f46 /src/libs
parent66d15d9d0974e1b493b717cf02deb435ebd13858 (diff)
downloadzig-9eb400ef19391261a3b61129d8665602c89959c5.tar.gz
zig-9eb400ef19391261a3b61129d8665602c89959c5.zip
compiler: rework backend pipeline to separate codegen and link
The idea here is that instead of the linker calling into codegen, instead codegen should run before we touch the linker, and after MIR is produced, it is sent to the linker. Aside from simplifying the call graph (by preventing N linkers from each calling into M codegen backends!), this has the huge benefit that it is possible to parallellize codegen separately from linking. The threading model can look like this: * 1 semantic analysis thread, which generates AIR * N codegen threads, which process AIR into MIR * 1 linker thread, which emits MIR to the binary The codegen threads are also responsible for `Air.Legalize` and `Air.Liveness`; it's more efficient to do this work here instead of blocking the main thread for this trivially parallel task. I have repurposed the `Zcu.Feature.separate_thread` backend feature to indicate support for this 1:N:1 threading pattern. This commit makes the C backend support this feature, since it was relatively easy to divorce from `link.C`: it just required eliminating some shared buffers. Other backends don't currently support this feature. In fact, they don't even compile -- the next few commits will fix them back up.
Diffstat (limited to 'src/libs')
-rw-r--r--src/libs/freebsd.zig2
-rw-r--r--src/libs/glibc.zig2
-rw-r--r--src/libs/libcxx.zig4
-rw-r--r--src/libs/libtsan.zig2
-rw-r--r--src/libs/libunwind.zig2
-rw-r--r--src/libs/musl.zig2
-rw-r--r--src/libs/netbsd.zig2
7 files changed, 8 insertions, 8 deletions
diff --git a/src/libs/freebsd.zig b/src/libs/freebsd.zig
index 47fef32773..98d4a42f91 100644
--- a/src/libs/freebsd.zig
+++ b/src/libs/freebsd.zig
@@ -1004,7 +1004,7 @@ fn queueSharedObjects(comp: *Compilation, so_files: BuiltSharedObjects) void {
}
}
- comp.queueLinkTasks(task_buffer[0..task_buffer_i]);
+ comp.queuePrelinkTasks(task_buffer[0..task_buffer_i]);
}
fn buildSharedLib(
diff --git a/src/libs/glibc.zig b/src/libs/glibc.zig
index cc781c5472..c1146d933d 100644
--- a/src/libs/glibc.zig
+++ b/src/libs/glibc.zig
@@ -1170,7 +1170,7 @@ fn queueSharedObjects(comp: *Compilation, so_files: BuiltSharedObjects) void {
}
}
- comp.queueLinkTasks(task_buffer[0..task_buffer_i]);
+ comp.queuePrelinkTasks(task_buffer[0..task_buffer_i]);
}
fn buildSharedLib(
diff --git a/src/libs/libcxx.zig b/src/libs/libcxx.zig
index 17a7d3d29e..eb9f5df855 100644
--- a/src/libs/libcxx.zig
+++ b/src/libs/libcxx.zig
@@ -308,7 +308,7 @@ pub fn buildLibCxx(comp: *Compilation, prog_node: std.Progress.Node) BuildError!
assert(comp.libcxx_static_lib == null);
const crt_file = try sub_compilation.toCrtFile();
comp.libcxx_static_lib = crt_file;
- comp.queueLinkTaskMode(crt_file.full_object_path, &config);
+ comp.queuePrelinkTaskMode(crt_file.full_object_path, &config);
}
pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildError!void {
@@ -504,7 +504,7 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
assert(comp.libcxxabi_static_lib == null);
const crt_file = try sub_compilation.toCrtFile();
comp.libcxxabi_static_lib = crt_file;
- comp.queueLinkTaskMode(crt_file.full_object_path, &config);
+ comp.queuePrelinkTaskMode(crt_file.full_object_path, &config);
}
pub fn addCxxArgs(
diff --git a/src/libs/libtsan.zig b/src/libs/libtsan.zig
index 8a5ffd2eab..0c59d85bc5 100644
--- a/src/libs/libtsan.zig
+++ b/src/libs/libtsan.zig
@@ -325,7 +325,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo
};
const crt_file = try sub_compilation.toCrtFile();
- comp.queueLinkTaskMode(crt_file.full_object_path, &config);
+ comp.queuePrelinkTaskMode(crt_file.full_object_path, &config);
assert(comp.tsan_lib == null);
comp.tsan_lib = crt_file;
}
diff --git a/src/libs/libunwind.zig b/src/libs/libunwind.zig
index 945689ebab..ccea649c17 100644
--- a/src/libs/libunwind.zig
+++ b/src/libs/libunwind.zig
@@ -195,7 +195,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
};
const crt_file = try sub_compilation.toCrtFile();
- comp.queueLinkTaskMode(crt_file.full_object_path, &config);
+ comp.queuePrelinkTaskMode(crt_file.full_object_path, &config);
assert(comp.libunwind_static_lib == null);
comp.libunwind_static_lib = crt_file;
}
diff --git a/src/libs/musl.zig b/src/libs/musl.zig
index d208b09827..21aeee98b5 100644
--- a/src/libs/musl.zig
+++ b/src/libs/musl.zig
@@ -278,7 +278,7 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
errdefer comp.gpa.free(basename);
const crt_file = try sub_compilation.toCrtFile();
- comp.queueLinkTaskMode(crt_file.full_object_path, &config);
+ comp.queuePrelinkTaskMode(crt_file.full_object_path, &config);
{
comp.mutex.lock();
defer comp.mutex.unlock();
diff --git a/src/libs/netbsd.zig b/src/libs/netbsd.zig
index 718861bf5c..aab75cce49 100644
--- a/src/libs/netbsd.zig
+++ b/src/libs/netbsd.zig
@@ -669,7 +669,7 @@ fn queueSharedObjects(comp: *Compilation, so_files: BuiltSharedObjects) void {
}
}
- comp.queueLinkTasks(task_buffer[0..task_buffer_i]);
+ comp.queuePrelinkTasks(task_buffer[0..task_buffer_i]);
}
fn buildSharedLib(