diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2025-09-18 23:26:11 +0100 |
|---|---|---|
| committer | gingerBill <gingerBill@users.noreply.github.com> | 2025-09-18 23:26:11 +0100 |
| commit | 5d14df4112368617b9b534745f8ce8934be74ffd (patch) | |
| tree | ae104886e05a823e553b65be550c032416427617 /src | |
| parent | 9cf69576ab8cb220af5802a04a0aa53dc92046a5 (diff) | |
Multithread `lb_module_init`
Diffstat (limited to 'src')
| -rw-r--r-- | src/llvm_backend.hpp | 2 | ||||
| -rw-r--r-- | src/llvm_backend_general.cpp | 34 |
2 files changed, 30 insertions, 6 deletions
diff --git a/src/llvm_backend.hpp b/src/llvm_backend.hpp index 698e7657f..370a6f2ca 100644 --- a/src/llvm_backend.hpp +++ b/src/llvm_backend.hpp @@ -147,6 +147,8 @@ struct lbModule { LLVMModuleRef mod; LLVMContextRef ctx; + Checker *checker; + struct lbGenerator *gen; LLVMTargetMachineRef target_machine; diff --git a/src/llvm_backend_general.cpp b/src/llvm_backend_general.cpp index fb9fa4cea..64d574920 100644 --- a/src/llvm_backend_general.cpp +++ b/src/llvm_backend_general.cpp @@ -15,7 +15,9 @@ gb_global isize lb_global_type_info_member_offsets_index = 0; gb_global isize lb_global_type_info_member_usings_index = 0; gb_global isize lb_global_type_info_member_tags_index = 0; -gb_internal void lb_init_module(lbModule *m, Checker *c) { +gb_internal WORKER_TASK_PROC(lb_init_module_worker_proc) { + lbModule *m = cast(lbModule *)data; + Checker *c = m->checker; m->info = &c->info; @@ -119,6 +121,15 @@ gb_internal void lb_init_module(lbModule *m, Checker *c) { m->const_dummy_builder = LLVMCreateBuilderInContext(m->ctx); + return 0; +} + +gb_internal void lb_init_module(lbModule *m, bool do_threading) { + if (do_threading) { + thread_pool_add_task(lb_init_module_worker_proc, m); + } else { + lb_init_module_worker_proc(m); + } } gb_internal bool lb_init_generator(lbGenerator *gen, Checker *c) { @@ -131,6 +142,10 @@ gb_internal bool lb_init_generator(lbGenerator *gen, Checker *c) { return false; } + isize thread_count = gb_max(build_context.thread_count, 1); + isize worker_count = thread_count-1; + bool do_threading = !!(LLVMIsMultithreaded() && USE_SEPARATE_MODULES && MULTITHREAD_OBJECT_GENERATION && worker_count > 0); + String init_fullpath = c->parser->init_fullpath; linker_data_init(gen, &c->info, init_fullpath); @@ -151,19 +166,21 @@ gb_internal bool lb_init_generator(lbGenerator *gen, Checker *c) { auto m = gb_alloc_item(permanent_allocator(), lbModule); m->pkg = pkg; m->gen = gen; + m->checker = c; map_set(&gen->modules, cast(void *)pkg, m); - lb_init_module(m, c); + lb_init_module(m, do_threading); if (LLVM_WEAK_MONOMORPHIZATION) { auto pm = gb_alloc_item(permanent_allocator(), lbModule); pm->pkg = pkg; pm->gen = gen; + pm->checker = c; 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 - lb_init_module(pm, c); + lb_init_module(pm, do_threading); } if (pkg->kind == Package_Runtime) { @@ -177,8 +194,9 @@ gb_internal bool lb_init_generator(lbGenerator *gen, Checker *c) { m->file = file; m->pkg = pkg; m->gen = gen; + m->checker = c; map_set(&gen->modules, cast(void *)file, m); - lb_init_module(m, c); + lb_init_module(m, do_threading); if (LLVM_WEAK_MONOMORPHIZATION) { @@ -186,20 +204,24 @@ gb_internal bool lb_init_generator(lbGenerator *gen, Checker *c) { pm->file = file; pm->pkg = pkg; pm->gen = gen; + pm->checker = c; 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 - lb_init_module(pm, c); + lb_init_module(pm, do_threading); } } } } gen->default_module.gen = gen; + gen->default_module.checker = c; map_set(&gen->modules, cast(void *)1, &gen->default_module); - lb_init_module(&gen->default_module, c); + lb_init_module(&gen->default_module, do_threading); + + thread_pool_wait(); for (auto const &entry : gen->modules) { lbModule *m = entry.value; |