mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 16:18:52 +00:00
Try moving parapoly procs into a separate module when doing weak monomorphization
This commit is contained in:
@@ -554,6 +554,7 @@ struct BuildContext {
|
|||||||
|
|
||||||
bool internal_no_inline;
|
bool internal_no_inline;
|
||||||
bool internal_by_value;
|
bool internal_by_value;
|
||||||
|
bool internal_weak_monomorphization;
|
||||||
|
|
||||||
bool no_threaded_checker;
|
bool no_threaded_checker;
|
||||||
|
|
||||||
|
|||||||
@@ -2145,7 +2145,7 @@ gb_internal void lb_create_global_procedures_and_types(lbGenerator *gen, Checker
|
|||||||
|
|
||||||
lbModule *m = &gen->default_module;
|
lbModule *m = &gen->default_module;
|
||||||
if (USE_SEPARATE_MODULES) {
|
if (USE_SEPARATE_MODULES) {
|
||||||
m = lb_module_of_entity(gen, e);
|
m = lb_module_of_entity(gen, e, m);
|
||||||
}
|
}
|
||||||
GB_ASSERT(m != nullptr);
|
GB_ASSERT(m != nullptr);
|
||||||
|
|
||||||
|
|||||||
@@ -150,6 +150,8 @@ struct lbModule {
|
|||||||
struct lbGenerator *gen;
|
struct lbGenerator *gen;
|
||||||
LLVMTargetMachineRef target_machine;
|
LLVMTargetMachineRef target_machine;
|
||||||
|
|
||||||
|
lbModule *polymorphic_module;
|
||||||
|
|
||||||
CheckerInfo *info;
|
CheckerInfo *info;
|
||||||
AstPackage *pkg; // possibly associated
|
AstPackage *pkg; // possibly associated
|
||||||
AstFile *file; // possibly associated
|
AstFile *file; // possibly associated
|
||||||
|
|||||||
@@ -1327,7 +1327,7 @@ gb_internal void lb_add_debug_info_for_global_constant_from_entity(lbGenerator *
|
|||||||
}
|
}
|
||||||
lbModule *m = &gen->default_module;
|
lbModule *m = &gen->default_module;
|
||||||
if (USE_SEPARATE_MODULES) {
|
if (USE_SEPARATE_MODULES) {
|
||||||
m = lb_module_of_entity(gen, e);
|
m = lb_module_of_entity(gen, e, m);
|
||||||
}
|
}
|
||||||
GB_ASSERT(m != nullptr);
|
GB_ASSERT(m != nullptr);
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,12 @@ gb_internal void lb_init_module(lbModule *m, Checker *c) {
|
|||||||
}
|
}
|
||||||
module_name = gb_string_appendc(module_name, "builtin");
|
module_name = gb_string_appendc(module_name, "builtin");
|
||||||
}
|
}
|
||||||
|
if (m->polymorphic_module == m) {
|
||||||
|
if (gb_string_length(module_name)) {
|
||||||
|
module_name = gb_string_appendc(module_name, "-");
|
||||||
|
}
|
||||||
|
module_name = gb_string_appendc(module_name, "$parapoly");
|
||||||
|
}
|
||||||
|
|
||||||
m->module_name = module_name;
|
m->module_name = module_name;
|
||||||
m->ctx = LLVMContextCreate();
|
m->ctx = LLVMContextCreate();
|
||||||
@@ -147,17 +153,42 @@ gb_internal bool lb_init_generator(lbGenerator *gen, Checker *c) {
|
|||||||
m->gen = gen;
|
m->gen = gen;
|
||||||
map_set(&gen->modules, cast(void *)pkg, m);
|
map_set(&gen->modules, cast(void *)pkg, m);
|
||||||
lb_init_module(m, c);
|
lb_init_module(m, c);
|
||||||
|
|
||||||
|
if (build_context.internal_weak_monomorphization) {
|
||||||
|
auto pm = gb_alloc_item(permanent_allocator(), lbModule);
|
||||||
|
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
|
||||||
|
|
||||||
|
lb_init_module(pm, c);
|
||||||
|
}
|
||||||
|
|
||||||
if (!module_per_file) {
|
if (!module_per_file) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// NOTE(bill): Probably per file is not a good idea, so leave this for later
|
// NOTE(bill): Probably per file is not a good idea, so leave this for later
|
||||||
for (AstFile *file : pkg->files) {
|
for (AstFile *file : pkg->files) {
|
||||||
auto m = gb_alloc_item(permanent_allocator(), lbModule);
|
auto m = gb_alloc_item(permanent_allocator(), lbModule);
|
||||||
m->file = file;
|
m->file = file;
|
||||||
m->pkg = pkg;
|
m->pkg = pkg;
|
||||||
m->gen = gen;
|
m->gen = gen;
|
||||||
map_set(&gen->modules, cast(void *)file, m);
|
map_set(&gen->modules, cast(void *)file, m);
|
||||||
lb_init_module(m, c);
|
lb_init_module(m, c);
|
||||||
|
|
||||||
|
|
||||||
|
if (build_context.internal_weak_monomorphization) {
|
||||||
|
auto pm = gb_alloc_item(permanent_allocator(), lbModule);
|
||||||
|
pm->file = file;
|
||||||
|
pm->gen = gen;
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -403,9 +434,9 @@ gb_internal lbModule *lb_module_of_expr(lbGenerator *gen, Ast *expr) {
|
|||||||
return &gen->default_module;
|
return &gen->default_module;
|
||||||
}
|
}
|
||||||
|
|
||||||
gb_internal lbModule *lb_module_of_entity(lbGenerator *gen, Entity *e) {
|
gb_internal lbModule *lb_module_of_entity_internal(lbGenerator *gen, Entity *e, lbModule *curr_module) {
|
||||||
GB_ASSERT(e != nullptr);
|
|
||||||
lbModule **found = nullptr;
|
lbModule **found = nullptr;
|
||||||
|
|
||||||
if (e->kind == Entity_Procedure &&
|
if (e->kind == Entity_Procedure &&
|
||||||
e->decl_info &&
|
e->decl_info &&
|
||||||
e->decl_info->code_gen_module) {
|
e->decl_info->code_gen_module) {
|
||||||
@@ -428,6 +459,22 @@ gb_internal lbModule *lb_module_of_entity(lbGenerator *gen, Entity *e) {
|
|||||||
return &gen->default_module;
|
return &gen->default_module;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
gb_internal lbModule *lb_module_of_entity(lbGenerator *gen, Entity *e, lbModule *curr_module) {
|
||||||
|
GB_ASSERT(e != nullptr);
|
||||||
|
GB_ASSERT(curr_module != nullptr);
|
||||||
|
lbModule *m = lb_module_of_entity_internal(gen, e, curr_module);
|
||||||
|
|
||||||
|
if (USE_SEPARATE_MODULES && build_context.internal_weak_monomorphization) {
|
||||||
|
if (e->kind == Entity_Procedure && e->Procedure.generated_from_polymorphic) {
|
||||||
|
if (m->polymorphic_module) {
|
||||||
|
return m->polymorphic_module;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
gb_internal lbAddr lb_addr(lbValue addr) {
|
gb_internal lbAddr lb_addr(lbValue addr) {
|
||||||
lbAddr v = {lbAddr_Default, addr};
|
lbAddr v = {lbAddr_Default, addr};
|
||||||
return v;
|
return v;
|
||||||
@@ -2914,7 +2961,7 @@ gb_internal lbValue lb_find_ident(lbProcedure *p, lbModule *m, Entity *e, Ast *e
|
|||||||
return lb_find_procedure_value_from_entity(m, e);
|
return lb_find_procedure_value_from_entity(m, e);
|
||||||
}
|
}
|
||||||
if (USE_SEPARATE_MODULES) {
|
if (USE_SEPARATE_MODULES) {
|
||||||
lbModule *other_module = lb_module_of_entity(m->gen, e);
|
lbModule *other_module = lb_module_of_entity(m->gen, e, m);
|
||||||
if (other_module != m) {
|
if (other_module != m) {
|
||||||
String name = lb_get_entity_name(other_module, e);
|
String name = lb_get_entity_name(other_module, e);
|
||||||
|
|
||||||
@@ -2962,7 +3009,7 @@ gb_internal lbValue lb_find_procedure_value_from_entity(lbModule *m, Entity *e)
|
|||||||
|
|
||||||
lbModule *other_module = m;
|
lbModule *other_module = m;
|
||||||
if (USE_SEPARATE_MODULES) {
|
if (USE_SEPARATE_MODULES) {
|
||||||
other_module = lb_module_of_entity(gen, e);
|
other_module = lb_module_of_entity(gen, e, m);
|
||||||
}
|
}
|
||||||
if (other_module == m) {
|
if (other_module == m) {
|
||||||
debugf("Missing Procedure (lb_find_procedure_value_from_entity): %.*s module %p\n", LIT(e->token.string), m);
|
debugf("Missing Procedure (lb_find_procedure_value_from_entity): %.*s module %p\n", LIT(e->token.string), m);
|
||||||
@@ -3145,7 +3192,7 @@ gb_internal lbValue lb_find_value_from_entity(lbModule *m, Entity *e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (USE_SEPARATE_MODULES) {
|
if (USE_SEPARATE_MODULES) {
|
||||||
lbModule *other_module = lb_module_of_entity(m->gen, e);
|
lbModule *other_module = lb_module_of_entity(m->gen, e, m);
|
||||||
|
|
||||||
bool is_external = other_module != m;
|
bool is_external = other_module != m;
|
||||||
if (!is_external) {
|
if (!is_external) {
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ gb_internal lbProcedure *lb_create_procedure(lbModule *m, Entity *entity, bool i
|
|||||||
String link_name = {};
|
String link_name = {};
|
||||||
|
|
||||||
if (ignore_body) {
|
if (ignore_body) {
|
||||||
lbModule *other_module = lb_module_of_entity(m->gen, entity);
|
lbModule *other_module = lb_module_of_entity(m->gen, entity, m);
|
||||||
link_name = lb_get_entity_name(other_module, entity);
|
link_name = lb_get_entity_name(other_module, entity);
|
||||||
} else {
|
} else {
|
||||||
link_name = lb_get_entity_name(m, entity);
|
link_name = lb_get_entity_name(m, entity);
|
||||||
|
|||||||
@@ -403,6 +403,7 @@ enum BuildFlagKind {
|
|||||||
BuildFlag_InternalCached,
|
BuildFlag_InternalCached,
|
||||||
BuildFlag_InternalNoInline,
|
BuildFlag_InternalNoInline,
|
||||||
BuildFlag_InternalByValue,
|
BuildFlag_InternalByValue,
|
||||||
|
BuildFlag_InternalWeakMonomorphization,
|
||||||
|
|
||||||
BuildFlag_Tilde,
|
BuildFlag_Tilde,
|
||||||
|
|
||||||
@@ -626,6 +627,7 @@ gb_internal bool parse_build_flags(Array<String> args) {
|
|||||||
add_flag(&build_flags, BuildFlag_InternalCached, str_lit("internal-cached"), BuildFlagParam_None, Command_all);
|
add_flag(&build_flags, BuildFlag_InternalCached, str_lit("internal-cached"), BuildFlagParam_None, Command_all);
|
||||||
add_flag(&build_flags, BuildFlag_InternalNoInline, str_lit("internal-no-inline"), BuildFlagParam_None, Command_all);
|
add_flag(&build_flags, BuildFlag_InternalNoInline, str_lit("internal-no-inline"), BuildFlagParam_None, Command_all);
|
||||||
add_flag(&build_flags, BuildFlag_InternalByValue, str_lit("internal-by-value"), BuildFlagParam_None, Command_all);
|
add_flag(&build_flags, BuildFlag_InternalByValue, str_lit("internal-by-value"), BuildFlagParam_None, Command_all);
|
||||||
|
add_flag(&build_flags, BuildFlag_InternalWeakMonomorphization, str_lit("internal-weak-monomorphization"), BuildFlagParam_None, Command_all);
|
||||||
|
|
||||||
#if ALLOW_TILDE
|
#if ALLOW_TILDE
|
||||||
add_flag(&build_flags, BuildFlag_Tilde, str_lit("tilde"), BuildFlagParam_None, Command__does_build);
|
add_flag(&build_flags, BuildFlag_Tilde, str_lit("tilde"), BuildFlagParam_None, Command__does_build);
|
||||||
@@ -1584,6 +1586,9 @@ gb_internal bool parse_build_flags(Array<String> args) {
|
|||||||
case BuildFlag_InternalByValue:
|
case BuildFlag_InternalByValue:
|
||||||
build_context.internal_by_value = true;
|
build_context.internal_by_value = true;
|
||||||
break;
|
break;
|
||||||
|
case BuildFlag_InternalWeakMonomorphization:
|
||||||
|
build_context.internal_weak_monomorphization = true;
|
||||||
|
break;
|
||||||
|
|
||||||
case BuildFlag_Tilde:
|
case BuildFlag_Tilde:
|
||||||
build_context.tilde_backend = true;
|
build_context.tilde_backend = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user