mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-15 18:32:22 -07:00
Minor clean up for backend
This commit is contained in:
+8
-1
@@ -1142,7 +1142,14 @@ gb_internal void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) {
|
||||
}
|
||||
|
||||
if (ac.link_name.len > 0) {
|
||||
e->Procedure.link_name = ac.link_name;
|
||||
String ln = ac.link_name;
|
||||
e->Procedure.link_name = ln;
|
||||
if (ln == "memcpy" ||
|
||||
ln == "memmove" ||
|
||||
ln == "mem_copy" ||
|
||||
ln == "mem_copy_non_overlapping") {
|
||||
e->Procedure.is_memcpy_like = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (ac.deferred_procedure.entity != nullptr) {
|
||||
|
||||
@@ -256,6 +256,7 @@ struct Entity {
|
||||
bool generated_from_polymorphic : 1;
|
||||
bool entry_point_only : 1;
|
||||
bool has_instrumentation : 1;
|
||||
bool is_memcpy_like : 1;
|
||||
} Procedure;
|
||||
struct {
|
||||
Array<Entity *> entities;
|
||||
|
||||
+76
-54
@@ -1300,18 +1300,14 @@ gb_internal lbProcedure *lb_create_cleanup_runtime(lbModule *main_module) { // C
|
||||
|
||||
gb_internal WORKER_TASK_PROC(lb_generate_procedures_and_types_per_module) {
|
||||
lbModule *m = cast(lbModule *)data;
|
||||
for (Entity *e : m->global_procedures_and_types_to_create) {
|
||||
if (e->kind == Entity_TypeName) {
|
||||
(void)lb_get_entity_name(m, e);
|
||||
lb_type(m, e->type);
|
||||
}
|
||||
for (Entity *e : m->global_types_to_create) {
|
||||
(void)lb_get_entity_name(m, e);
|
||||
(void)lb_type(m, e->type);
|
||||
}
|
||||
|
||||
for (Entity *e : m->global_procedures_and_types_to_create) {
|
||||
if (e->kind == Entity_Procedure) {
|
||||
(void)lb_get_entity_name(m, e);
|
||||
array_add(&m->procedures_to_generate, lb_create_procedure(m, e));
|
||||
}
|
||||
for (Entity *e : m->global_procedures_to_create) {
|
||||
(void)lb_get_entity_name(m, e);
|
||||
array_add(&m->procedures_to_generate, lb_create_procedure(m, e));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1365,16 +1361,24 @@ gb_internal void lb_create_global_procedures_and_types(lbGenerator *gen, Checker
|
||||
m = lb_module_of_entity(gen, e);
|
||||
}
|
||||
|
||||
array_add(&m->global_procedures_and_types_to_create, e);
|
||||
if (e->kind == Entity_Procedure) {
|
||||
array_add(&m->global_procedures_to_create, e);
|
||||
} else if (e->kind == Entity_TypeName) {
|
||||
array_add(&m->global_types_to_create, e);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto const &entry : gen->modules) {
|
||||
lbModule *m = entry.value;
|
||||
if (do_threading) {
|
||||
if (do_threading) {
|
||||
for (auto const &entry : gen->modules) {
|
||||
lbModule *m = entry.value;
|
||||
thread_pool_add_task(lb_generate_procedures_and_types_per_module, m);
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
for (auto const &entry : gen->modules) {
|
||||
lbModule *m = entry.value;
|
||||
lb_generate_procedures_and_types_per_module(m);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
thread_pool_wait();
|
||||
@@ -2405,16 +2409,19 @@ gb_internal WORKER_TASK_PROC(lb_generate_procedures_worker_proc) {
|
||||
}
|
||||
|
||||
gb_internal void lb_generate_procedures(lbGenerator *gen, bool do_threading) {
|
||||
for (auto const &entry : gen->modules) {
|
||||
lbModule *m = entry.value;
|
||||
if (do_threading) {
|
||||
if (do_threading) {
|
||||
for (auto const &entry : gen->modules) {
|
||||
lbModule *m = entry.value;
|
||||
thread_pool_add_task(lb_generate_procedures_worker_proc, m);
|
||||
} else {
|
||||
}
|
||||
|
||||
thread_pool_wait();
|
||||
} else {
|
||||
for (auto const &entry : gen->modules) {
|
||||
lbModule *m = entry.value;
|
||||
lb_generate_procedures_worker_proc(m);
|
||||
}
|
||||
}
|
||||
|
||||
thread_pool_wait();
|
||||
}
|
||||
|
||||
gb_internal WORKER_TASK_PROC(lb_generate_missing_procedures_to_check_worker_proc) {
|
||||
@@ -2428,17 +2435,20 @@ gb_internal WORKER_TASK_PROC(lb_generate_missing_procedures_to_check_worker_proc
|
||||
}
|
||||
|
||||
gb_internal void lb_generate_missing_procedures(lbGenerator *gen, bool do_threading) {
|
||||
for (auto const &entry : gen->modules) {
|
||||
lbModule *m = entry.value;
|
||||
// NOTE(bill): procedures may be added during generation
|
||||
if (do_threading) {
|
||||
if (do_threading) {
|
||||
for (auto const &entry : gen->modules) {
|
||||
lbModule *m = entry.value;
|
||||
// NOTE(bill): procedures may be added during generation
|
||||
thread_pool_add_task(lb_generate_missing_procedures_to_check_worker_proc, m);
|
||||
} else {
|
||||
}
|
||||
thread_pool_wait();
|
||||
} else {
|
||||
for (auto const &entry : gen->modules) {
|
||||
lbModule *m = entry.value;
|
||||
// NOTE(bill): procedures may be added during generation
|
||||
lb_generate_missing_procedures_to_check_worker_proc(m);
|
||||
}
|
||||
}
|
||||
|
||||
thread_pool_wait();
|
||||
}
|
||||
|
||||
gb_internal void lb_debug_info_complete_types_and_finalize(lbGenerator *gen) {
|
||||
@@ -2451,32 +2461,45 @@ gb_internal void lb_debug_info_complete_types_and_finalize(lbGenerator *gen) {
|
||||
}
|
||||
|
||||
gb_internal void lb_llvm_function_passes(lbGenerator *gen, bool do_threading) {
|
||||
for (auto const &entry : gen->modules) {
|
||||
lbModule *m = entry.value;
|
||||
if (do_threading) {
|
||||
if (do_threading) {
|
||||
for (auto const &entry : gen->modules) {
|
||||
lbModule *m = entry.value;
|
||||
thread_pool_add_task(lb_llvm_function_pass_per_module, m);
|
||||
} else {
|
||||
}
|
||||
thread_pool_wait();
|
||||
} else {
|
||||
for (auto const &entry : gen->modules) {
|
||||
lbModule *m = entry.value;
|
||||
lb_llvm_function_pass_per_module(m);
|
||||
}
|
||||
}
|
||||
thread_pool_wait();
|
||||
}
|
||||
|
||||
|
||||
gb_internal void lb_llvm_module_passes(lbGenerator *gen, bool 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;
|
||||
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;
|
||||
|
||||
if (do_threading) {
|
||||
thread_pool_add_task(lb_llvm_module_pass_worker_proc, wd);
|
||||
} else {
|
||||
if (do_threading) {
|
||||
thread_pool_add_task(lb_llvm_module_pass_worker_proc, wd);
|
||||
} else {
|
||||
lb_llvm_module_pass_worker_proc(wd);
|
||||
}
|
||||
}
|
||||
thread_pool_wait();
|
||||
} else {
|
||||
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;
|
||||
lb_llvm_module_pass_worker_proc(wd);
|
||||
}
|
||||
}
|
||||
thread_pool_wait();
|
||||
}
|
||||
|
||||
gb_internal String lb_filepath_ll_for_module(lbModule *m) {
|
||||
@@ -2556,17 +2579,21 @@ gb_internal String lb_filepath_obj_for_module(lbModule *m) {
|
||||
|
||||
|
||||
gb_internal bool lb_llvm_module_verification(lbGenerator *gen, bool do_threading) {
|
||||
for (auto const &entry : gen->modules) {
|
||||
lbModule *m = entry.value;
|
||||
if (do_threading) {
|
||||
if (do_threading) {
|
||||
for (auto const &entry : gen->modules) {
|
||||
lbModule *m = entry.value;
|
||||
thread_pool_add_task(lb_llvm_module_verification_worker_proc, m);
|
||||
} else {
|
||||
}
|
||||
thread_pool_wait();
|
||||
|
||||
} else {
|
||||
for (auto const &entry : gen->modules) {
|
||||
lbModule *m = entry.value;
|
||||
if (lb_llvm_module_verification_worker_proc(m)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
thread_pool_wait();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -2808,13 +2835,8 @@ gb_internal void lb_generate_procedure(lbModule *m, lbProcedure *p) {
|
||||
lb_end_procedure(p);
|
||||
|
||||
// Add Flags
|
||||
if (p->body != nullptr) {
|
||||
if (p->name == "memcpy" || p->name == "memmove" ||
|
||||
p->name == "runtime.mem_copy" || p->name == "mem_copy_non_overlapping" ||
|
||||
string_starts_with(p->name, str_lit("llvm.memcpy")) ||
|
||||
string_starts_with(p->name, str_lit("llvm.memmove"))) {
|
||||
p->flags |= lbProcedureFlag_WithoutMemcpyPass;
|
||||
}
|
||||
if (p->entity && p->entity->kind == Entity_Procedure && p->entity->Procedure.is_memcpy_like) {
|
||||
p->flags |= lbProcedureFlag_WithoutMemcpyPass;
|
||||
}
|
||||
|
||||
lb_verify_function(m, p, true);
|
||||
|
||||
@@ -181,7 +181,8 @@ struct lbModule {
|
||||
std::atomic<u32> nested_type_name_guid;
|
||||
|
||||
Array<lbProcedure *> procedures_to_generate;
|
||||
Array<Entity *> global_procedures_and_types_to_create;
|
||||
Array<Entity *> global_procedures_to_create;
|
||||
Array<Entity *> global_types_to_create;
|
||||
|
||||
lbProcedure *curr_procedure;
|
||||
|
||||
|
||||
@@ -78,7 +78,8 @@ gb_internal void lb_init_module(lbModule *m, Checker *c) {
|
||||
array_init(&m->procedures_to_generate, a, 0, c->info.all_procedures.count);
|
||||
map_init(&m->procedure_values, c->info.all_procedures.count*2);
|
||||
}
|
||||
array_init(&m->global_procedures_and_types_to_create, a, 0, 1024);
|
||||
array_init(&m->global_procedures_to_create, a, 0, 1024);
|
||||
array_init(&m->global_types_to_create, a, 0, 1024);
|
||||
array_init(&m->missing_procedures_to_check, a, 0, 16);
|
||||
map_init(&m->debug_values);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user