Minor reordering

This commit is contained in:
gingerBill
2026-03-18 15:11:36 +00:00
parent 0fafa30bfe
commit 36abc80aac
3 changed files with 43 additions and 28 deletions

View File

@@ -2562,9 +2562,23 @@ gb_internal WORKER_TASK_PROC(lb_llvm_module_pass_worker_proc) {
gb_internal WORKER_TASK_PROC(lb_generate_procedures_worker_proc) {
lbModule *m = cast(lbModule *)data;
lbGenerator *gen = m->gen;
for (lbProcedure *p = nullptr; mpsc_dequeue(&m->procedures_to_generate, &p); /**/) {
lb_generate_procedure(p->module, p);
}
// NOTE(bill): When the module has generated its procedures, then we can verify the procedures and module
// the exception to his being the `gen->default_module` which must be done AFTER everything else
if (m != &gen->default_module &&
gen->do_threading && !build_context.ODIN_DEBUG) {
auto wd = permanent_alloc_item<lbLLVMModulePassWorkerData>();
wd->m = m;
wd->target_machine = m->target_machine;
wd->do_threading = true;
thread_pool_add_task(lb_llvm_function_pass_per_module, wd);
}
return 0;
}
@@ -2602,10 +2616,6 @@ gb_internal void lb_generate_procedures(lbGenerator *gen, bool do_threading) {
}
thread_pool_add_task(lb_generate_procedures_worker_proc, m);
}
thread_pool_wait();
lb_generate_procedures_worker_proc(&gen->default_module);
} else {
for (auto const &entry : gen->modules) {
lbModule *m = entry.value;
@@ -2615,6 +2625,10 @@ gb_internal void lb_generate_procedures(lbGenerator *gen, bool do_threading) {
}
gb_internal void lb_generate_check_missing_procedures(lbGenerator *gen, bool do_threading) {
thread_pool_wait();
lb_generate_procedures_worker_proc(&gen->default_module);
for (auto const &entry : gen->modules) {
lbModule *m = entry.value;
GB_ASSERT_MSG(m->procedures_to_generate.count == 0, "%s, %td remaining", m->module_name, m->procedures_to_generate.count.load());
@@ -2631,16 +2645,20 @@ gb_internal void lb_debug_info_complete_types_and_finalize(lbGenerator *gen) {
}
gb_internal void lb_llvm_function_passes(lbGenerator *gen, bool do_threading) {
if (do_threading) {
for (auto const &entry : gen->modules) {
lbModule *m = entry.value;
auto wd = permanent_alloc_item<lbLLVMModulePassWorkerData>();
wd->m = m;
wd->target_machine = m->target_machine;
wd->do_threading = true;
if (do_threading && !build_context.ODIN_DEBUG) {
// NOTE(bill): When the module has generated its procedures, then we can verify the procedures and module
// the exception to his being the `gen->default_module` which must be done AFTER everything else
//
// This is place where the default module gets analyzed
lbModule *m = &gen->default_module;
auto wd = permanent_alloc_item<lbLLVMModulePassWorkerData>();
wd->m = m;
wd->target_machine = m->target_machine;
wd->do_threading = true;
lb_llvm_function_pass_per_module(wd);
thread_pool_add_task(lb_llvm_function_pass_per_module, wd);
}
thread_pool_wait();
} else {
for (auto const &entry : gen->modules) {
@@ -3725,12 +3743,12 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
}
}
TIME_SECTION("LLVM Function Pass (And Remove Unused) & Module Pass + Verification");
lb_llvm_function_passes(gen, do_threading);
TIME_SECTION("LLVM Add Foreign Library Paths");
lb_add_foreign_library_paths(gen);
TIME_SECTION("LLVM Function Pass (And Remove Unused) & Module Pass + Verification");
lb_llvm_function_passes(gen, do_threading && !build_context.ODIN_DEBUG);
TIME_SECTION("LLVM Correct Entity Linkage");
lb_correct_entity_linkage(gen);

View File

@@ -220,6 +220,8 @@ struct lbObjCGlobal {
struct lbGenerator : LinkerData {
CheckerInfo *info;
bool do_threading;
PtrMap<void *, lbModule *> modules; // key is `AstPackage *` (`void *` is used for future use)
PtrMap<LLVMContextRef, lbModule *> modules_through_ctx;
lbModule default_module;

View File

@@ -148,6 +148,7 @@ gb_internal bool lb_init_generator(lbGenerator *gen, Checker *c) {
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);
gen->do_threading = do_threading;
String init_fullpath = c->parser->init_fullpath;
linker_data_init(gen, &c->info, init_fullpath);
@@ -1801,7 +1802,7 @@ gb_internal LLVMTypeRef lb_type_internal_for_procedures_raw(lbModule *m, Type *t
"\n\tFuncTypeCtx: %p\n\tCurrentCtx: %p\n\tGlobalCtx: %p",
LLVMGetTypeContext(new_abi_fn_type), m->ctx, LLVMGetGlobalContext());
// map_set(&m->func_raw_types, type, new_abi_fn_type);
map_set(&m->func_raw_types, type, new_abi_fn_type);
return new_abi_fn_type;
}
@@ -3327,8 +3328,7 @@ gb_internal lbValue lb_generate_anonymous_proc_lit(lbModule *m, String const &pr
e->Procedure.is_anonymous = true;
e->flags |= EntityFlag_ProcBodyChecked;
pl->decl->entity.store(e);
lbValue value = {};
if (target_module != m) {
GB_ASSERT_MSG(m == &gen->default_module, "%s %s", m->module_name, target_module->module_name);
@@ -3343,13 +3343,8 @@ gb_internal lbValue lb_generate_anonymous_proc_lit(lbModule *m, String const &pr
}
lbProcedure *proto = lb_create_procedure(m, e, true);
lbValue value = {};
value.value = proto->value;
value.type = proto->type;
return value;
} else {
lbProcedure *local = lb_create_procedure(m, e, false);
@@ -3360,13 +3355,13 @@ gb_internal lbValue lb_generate_anonymous_proc_lit(lbModule *m, String const &pr
string_map_set(&m->members, name, {local->value, local->type});
}
lbValue value = {};
value.value = local->value;
value.type = local->type;
return value;
}
pl->decl->entity.store(e);
return value;
}