Use multiple modules per file in package runtime

This commit is contained in:
gingerBill
2025-09-18 15:34:19 +01:00
parent 738a72943b
commit 0f307fbc5d
3 changed files with 23 additions and 37 deletions

View File

@@ -2303,6 +2303,7 @@ gb_internal WORKER_TASK_PROC(lb_llvm_function_pass_per_module) {
struct lbLLVMModulePassWorkerData {
lbModule *m;
LLVMTargetMachineRef target_machine;
bool do_threading;
};
gb_internal WORKER_TASK_PROC(lb_llvm_module_pass_worker_proc) {
@@ -2386,6 +2387,13 @@ gb_internal WORKER_TASK_PROC(lb_llvm_module_pass_worker_proc) {
return 1;
}
#endif
if (wd->do_threading) {
thread_pool_add_task(lb_llvm_module_verification_worker_proc, wd->m);
} else {
lb_llvm_module_verification_worker_proc(wd->m);
}
return 0;
}
@@ -2468,19 +2476,16 @@ gb_internal void lb_llvm_function_passes(lbGenerator *gen, bool do_threading) {
}
gb_internal void lb_llvm_module_passes(lbGenerator *gen, bool do_threading) {
gb_internal void lb_llvm_module_passes_and_verification(lbGenerator *gen, bool do_threading) {
if (do_threading) {
for (auto const &entry : gen->modules) {
lbModule *m = entry.value;
auto wd = gb_alloc_item(permanent_allocator(), lbLLVMModulePassWorkerData);
wd->m = m;
wd->target_machine = m->target_machine;
wd->do_threading = true;
if (do_threading) {
thread_pool_add_task(lb_llvm_module_pass_worker_proc, wd);
} else {
lb_llvm_module_pass_worker_proc(wd);
}
thread_pool_add_task(lb_llvm_module_pass_worker_proc, wd);
}
thread_pool_wait();
} else {
@@ -2489,6 +2494,7 @@ gb_internal void lb_llvm_module_passes(lbGenerator *gen, bool do_threading) {
auto wd = gb_alloc_item(permanent_allocator(), lbLLVMModulePassWorkerData);
wd->m = m;
wd->target_machine = m->target_machine;
wd->do_threading = false;
lb_llvm_module_pass_worker_proc(wd);
}
}
@@ -2569,31 +2575,6 @@ gb_internal String lb_filepath_obj_for_module(lbModule *m) {
}
gb_internal bool lb_llvm_module_verification(lbGenerator *gen, bool do_threading) {
if (LLVM_IGNORE_VERIFICATION) {
return true;
}
if (do_threading) {
for (auto const &entry : gen->modules) {
lbModule *m = entry.value;
thread_pool_add_task(lb_llvm_module_verification_worker_proc, m);
}
thread_pool_wait();
} else {
for (auto const &entry : gen->modules) {
lbModule *m = entry.value;
if (lb_llvm_module_verification_worker_proc(m)) {
return false;
}
}
}
return true;
}
gb_internal void lb_add_foreign_library_paths(lbGenerator *gen) {
for (auto const &entry : gen->modules) {
lbModule *m = entry.value;
@@ -3479,11 +3460,10 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
TIME_SECTION("LLVM Function Pass");
lb_llvm_function_passes(gen, do_threading && !build_context.ODIN_DEBUG);
TIME_SECTION("LLVM Module Pass");
lb_llvm_module_passes(gen, do_threading);
TIME_SECTION("LLVM Module Pass and Verification");
lb_llvm_module_passes_and_verification(gen, do_threading);
TIME_SECTION("LLVM Module Verification");
if (!lb_llvm_module_verification(gen, do_threading)) {
if (gen->module_verification_failed.load(std::memory_order_relaxed)) {
return false;
}

View File

@@ -239,6 +239,8 @@ struct lbGenerator : LinkerData {
isize used_module_count;
std::atomic<bool> module_verification_failed;
lbProcedure *startup_runtime;
lbProcedure *cleanup_runtime;
lbProcedure *objc_names;

View File

@@ -158,7 +158,7 @@ gb_internal bool lb_init_generator(lbGenerator *gen, Checker *c) {
auto pm = gb_alloc_item(permanent_allocator(), lbModule);
pm->pkg = pkg;
pm->gen = gen;
m->polymorphic_module = pm;
m->polymorphic_module = pm;
pm->polymorphic_module = pm;
map_set(&gen->modules, cast(void *)pm, pm); // point to itself just add it to the list
@@ -166,7 +166,9 @@ gb_internal bool lb_init_generator(lbGenerator *gen, Checker *c) {
lb_init_module(pm, c);
}
if (!module_per_file) {
if (pkg->kind == Package_Runtime) {
// allow this to be per file
} else if (!module_per_file) {
continue;
}
// NOTE(bill): Probably per file is not a good idea, so leave this for later
@@ -182,7 +184,9 @@ gb_internal bool lb_init_generator(lbGenerator *gen, Checker *c) {
if (build_context.internal_weak_monomorphization) {
auto pm = gb_alloc_item(permanent_allocator(), lbModule);
pm->file = file;
pm->pkg = pkg;
pm->gen = gen;
m->polymorphic_module = pm;
pm->polymorphic_module = pm;
map_set(&gen->modules, cast(void *)pm, pm); // point to itself just add it to the list