mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Add module stuff to -para-poly-diagnostics
This commit is contained in:
+26
-11
@@ -3245,10 +3245,6 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (!ptr_set_exists(min_dep_set, e)) {
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
|
|
||||||
DeclInfo *decl = decl_info_of_entity(e);
|
DeclInfo *decl = decl_info_of_entity(e);
|
||||||
if (decl == nullptr) {
|
if (decl == nullptr) {
|
||||||
continue;
|
continue;
|
||||||
@@ -3259,8 +3255,16 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
|
|||||||
bool is_foreign = e->Variable.is_foreign;
|
bool is_foreign = e->Variable.is_foreign;
|
||||||
bool is_export = e->Variable.is_export;
|
bool is_export = e->Variable.is_export;
|
||||||
|
|
||||||
|
lbModule *default_module = &gen->default_module;
|
||||||
|
|
||||||
|
lbModule *m = default_module;
|
||||||
|
lbModule *e_module = lb_module_of_entity(gen, e, default_module);
|
||||||
|
|
||||||
|
bool const split_globals_across_modules = false;
|
||||||
|
if (split_globals_across_modules) {
|
||||||
|
m = e_module;
|
||||||
|
}
|
||||||
|
|
||||||
lbModule *m = &gen->default_module;
|
|
||||||
String name = lb_get_entity_name(m, e);
|
String name = lb_get_entity_name(m, e);
|
||||||
|
|
||||||
lbGlobalVariable var = {};
|
lbGlobalVariable var = {};
|
||||||
@@ -3361,15 +3365,26 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g.value = LLVMConstPointerCast(g.value, lb_type(m, alloc_type_pointer(e->type)));
|
if (default_module == m) {
|
||||||
|
g.value = LLVMConstPointerCast(g.value, lb_type(m, alloc_type_pointer(e->type)));
|
||||||
|
|
||||||
var.var = g;
|
var.var = g;
|
||||||
array_add(&global_variables, var);
|
array_add(&global_variables, var);
|
||||||
|
} else {
|
||||||
|
lbValue local_g = {};
|
||||||
|
local_g.type = alloc_type_pointer(e->type);
|
||||||
|
local_g.value = LLVMAddGlobal(default_module->mod, lb_type(default_module, e->type), alloc_cstring(permanent_allocator(), name));
|
||||||
|
LLVMSetLinkage(local_g.value, LLVMExternalLinkage);
|
||||||
|
|
||||||
|
var.var = local_g;
|
||||||
|
array_add(&global_variables, var);
|
||||||
|
|
||||||
|
lb_add_entity(default_module, e, local_g);
|
||||||
|
lb_add_member(default_module, name, local_g);
|
||||||
|
}
|
||||||
|
|
||||||
lb_add_entity(m, e, g);
|
lb_add_entity(m, e, g);
|
||||||
lb_add_member(m, name, g);
|
lb_add_member(m, name, g);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (build_context.ODIN_DEBUG) {
|
if (build_context.ODIN_DEBUG) {
|
||||||
@@ -3557,7 +3572,7 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
|
|||||||
lb_correct_entity_linkage(gen);
|
lb_correct_entity_linkage(gen);
|
||||||
|
|
||||||
if (build_context.para_poly_diagnostics) {
|
if (build_context.para_poly_diagnostics) {
|
||||||
lb_do_para_poly_diagnostics(gen);
|
lb_do_code_gen_diagnostics(gen);
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm_error = nullptr;
|
llvm_error = nullptr;
|
||||||
|
|||||||
+100
-12
@@ -2790,7 +2790,7 @@ gb_internal LLVMAtomicOrdering llvm_atomic_ordering_from_odin(Ast *expr) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct lbParaPolyEntry {
|
struct lbDiagParaPolyEntry {
|
||||||
Entity *entity;
|
Entity *entity;
|
||||||
String canonical_name;
|
String canonical_name;
|
||||||
isize count;
|
isize count;
|
||||||
@@ -2812,7 +2812,7 @@ gb_internal isize lb_total_code_size(lbProcedure *p) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gb_internal void lb_do_para_poly_diagnostics(lbGenerator *gen) {
|
gb_internal void lb_do_para_poly_diagnostics(lbGenerator *gen) {
|
||||||
PtrMap<Entity * /* Parent */, lbParaPolyEntry> procs = {};
|
PtrMap<Entity * /* Parent */, lbDiagParaPolyEntry> procs = {};
|
||||||
map_init(&procs);
|
map_init(&procs);
|
||||||
defer (map_destroy(&procs));
|
defer (map_destroy(&procs));
|
||||||
|
|
||||||
@@ -2833,9 +2833,9 @@ gb_internal void lb_do_para_poly_diagnostics(lbGenerator *gen) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
lbParaPolyEntry *entry = map_get(&procs, para_poly_parent);
|
lbDiagParaPolyEntry *entry = map_get(&procs, para_poly_parent);
|
||||||
if (entry == nullptr) {
|
if (entry == nullptr) {
|
||||||
lbParaPolyEntry entry = {};
|
lbDiagParaPolyEntry entry = {};
|
||||||
entry.entity = para_poly_parent;
|
entry.entity = para_poly_parent;
|
||||||
entry.count = 0;
|
entry.count = 0;
|
||||||
|
|
||||||
@@ -2863,7 +2863,7 @@ gb_internal void lb_do_para_poly_diagnostics(lbGenerator *gen) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
auto entries = array_make<lbParaPolyEntry>(heap_allocator(), 0, procs.count);
|
auto entries = array_make<lbDiagParaPolyEntry>(heap_allocator(), 0, procs.count);
|
||||||
defer (array_free(&entries));
|
defer (array_free(&entries));
|
||||||
|
|
||||||
for (auto &entry : procs) {
|
for (auto &entry : procs) {
|
||||||
@@ -2871,8 +2871,8 @@ gb_internal void lb_do_para_poly_diagnostics(lbGenerator *gen) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
array_sort(entries, [](void const *a, void const *b) -> int {
|
array_sort(entries, [](void const *a, void const *b) -> int {
|
||||||
lbParaPolyEntry *x = cast(lbParaPolyEntry *)a;
|
lbDiagParaPolyEntry *x = cast(lbDiagParaPolyEntry *)a;
|
||||||
lbParaPolyEntry *y = cast(lbParaPolyEntry *)b;
|
lbDiagParaPolyEntry *y = cast(lbDiagParaPolyEntry *)b;
|
||||||
if (x->total_code_size > y->total_code_size) {
|
if (x->total_code_size > y->total_code_size) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -2906,8 +2906,8 @@ gb_internal void lb_do_para_poly_diagnostics(lbGenerator *gen) {
|
|||||||
gb_printf("------------------------------------------------------------------------------------------\n");
|
gb_printf("------------------------------------------------------------------------------------------\n");
|
||||||
|
|
||||||
array_sort(entries, [](void const *a, void const *b) -> int {
|
array_sort(entries, [](void const *a, void const *b) -> int {
|
||||||
lbParaPolyEntry *x = cast(lbParaPolyEntry *)a;
|
lbDiagParaPolyEntry *x = cast(lbDiagParaPolyEntry *)a;
|
||||||
lbParaPolyEntry *y = cast(lbParaPolyEntry *)b;
|
lbDiagParaPolyEntry *y = cast(lbDiagParaPolyEntry *)b;
|
||||||
if (x->count > y->count) {
|
if (x->count > y->count) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -2940,8 +2940,8 @@ gb_internal void lb_do_para_poly_diagnostics(lbGenerator *gen) {
|
|||||||
|
|
||||||
|
|
||||||
array_sort(entries, [](void const *a, void const *b) -> int {
|
array_sort(entries, [](void const *a, void const *b) -> int {
|
||||||
lbParaPolyEntry *x = cast(lbParaPolyEntry *)a;
|
lbDiagParaPolyEntry *x = cast(lbDiagParaPolyEntry *)a;
|
||||||
lbParaPolyEntry *y = cast(lbParaPolyEntry *)b;
|
lbDiagParaPolyEntry *y = cast(lbDiagParaPolyEntry *)b;
|
||||||
if (x->count < y->count) {
|
if (x->count < y->count) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -2972,5 +2972,93 @@ gb_internal void lb_do_para_poly_diagnostics(lbGenerator *gen) {
|
|||||||
gb_printf("%17td | %.*s\n", code_size, LIT(name));
|
gb_printf("%17td | %.*s\n", code_size, LIT(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
gb_printf("------------------------------------------------------------------------------------------\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct lbDiagModuleEntry {
|
||||||
|
lbModule *m;
|
||||||
|
String name;
|
||||||
|
isize global_internal_count;
|
||||||
|
isize global_external_count;
|
||||||
|
isize proc_internal_count;
|
||||||
|
isize proc_external_count;
|
||||||
|
isize total_instruction_count;
|
||||||
|
};
|
||||||
|
|
||||||
|
gb_internal void lb_do_module_diagnostics(lbGenerator *gen) {
|
||||||
|
Array<lbDiagModuleEntry> modules = {};
|
||||||
|
array_init(&modules, heap_allocator());
|
||||||
|
defer (array_free(&modules));
|
||||||
|
|
||||||
|
for (auto &entry : gen->modules) {
|
||||||
|
lbModule *m = entry.value;
|
||||||
|
|
||||||
|
{
|
||||||
|
lbDiagModuleEntry entry = {};
|
||||||
|
entry.m = m;
|
||||||
|
entry.name = make_string_c(m->module_name);
|
||||||
|
array_add(&modules, entry);
|
||||||
|
}
|
||||||
|
lbDiagModuleEntry &entry = modules[modules.count-1];
|
||||||
|
|
||||||
|
for (LLVMValueRef p = LLVMGetFirstFunction(m->mod); p != nullptr; p = LLVMGetNextFunction(p)) {
|
||||||
|
LLVMBasicBlockRef block = LLVMGetFirstBasicBlock(p);
|
||||||
|
if (block == nullptr) {
|
||||||
|
entry.proc_external_count += 1;
|
||||||
|
} else {
|
||||||
|
entry.proc_internal_count += 1;
|
||||||
|
|
||||||
|
for (; block != nullptr; block = LLVMGetNextBasicBlock(block)) {
|
||||||
|
for (LLVMValueRef i = LLVMGetFirstInstruction(block); i != nullptr; i = LLVMGetNextInstruction(i)) {
|
||||||
|
entry.total_instruction_count += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (LLVMValueRef g = LLVMGetFirstGlobal(m->mod); g != nullptr; g = LLVMGetNextGlobal(g)) {
|
||||||
|
LLVMLinkage linkage = LLVMGetLinkage(g);
|
||||||
|
if (linkage == LLVMExternalLinkage) {
|
||||||
|
entry.global_external_count += 1;
|
||||||
|
} else {
|
||||||
|
entry.global_internal_count += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
array_sort(modules, [](void const *a, void const *b) -> int {
|
||||||
|
lbDiagModuleEntry *x = cast(lbDiagModuleEntry *)a;
|
||||||
|
lbDiagModuleEntry *y = cast(lbDiagModuleEntry *)b;
|
||||||
|
|
||||||
|
if (x->total_instruction_count > y->total_instruction_count) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (x->total_instruction_count < y->total_instruction_count) {
|
||||||
|
return +1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return string_compare(x->name, y->name);
|
||||||
|
});
|
||||||
|
|
||||||
|
gb_printf("Module Diagnostics\n\n");
|
||||||
|
gb_printf("Total Instructions | Global Internals | Global Externals | Proc Internals | Proc Externals | Module Name\n");
|
||||||
|
for (auto &entry : modules) {
|
||||||
|
gb_printf("%18td | %16td | %16td | %14td | %14d | %s \n",
|
||||||
|
entry.total_instruction_count,
|
||||||
|
entry.global_internal_count,
|
||||||
|
entry.global_external_count,
|
||||||
|
entry.proc_internal_count,
|
||||||
|
entry.proc_external_count,
|
||||||
|
entry.m->module_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
gb_internal void lb_do_code_gen_diagnostics(lbGenerator *gen) {
|
||||||
|
lb_do_para_poly_diagnostics(gen);
|
||||||
|
gb_printf("------------------------------------------------------------------------------------------\n");
|
||||||
|
gb_printf("------------------------------------------------------------------------------------------\n\n");
|
||||||
|
lb_do_module_diagnostics(gen);
|
||||||
|
gb_printf("------------------------------------------------------------------------------------------\n");
|
||||||
|
gb_printf("------------------------------------------------------------------------------------------\n\n");
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user