aboutsummaryrefslogtreecommitdiff
path: root/src/llvm_backend.cpp
diff options
context:
space:
mode:
authorftphikari <ftphikari@gmail.com>2023-07-25 15:32:18 +0300
committerGitHub <noreply@github.com>2023-07-25 15:32:18 +0300
commit699aec331d44da58bceddfb788bf349995473ad9 (patch)
tree3f5ce42c72c18fff1fc79f0229797be72f0e7638 /src/llvm_backend.cpp
parentd2375a79f29d8377c813484bce3127ae9c205974 (diff)
parent5ac7fe453f5fbf0995c24f0c1c12ed439ae3aee9 (diff)
Merge branch 'odin-lang:master' into master
Diffstat (limited to 'src/llvm_backend.cpp')
-rw-r--r--src/llvm_backend.cpp96
1 files changed, 25 insertions, 71 deletions
diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp
index 34a401c33..938c9b2ac 100644
--- a/src/llvm_backend.cpp
+++ b/src/llvm_backend.cpp
@@ -157,10 +157,10 @@ gb_internal lbValue lb_equal_proc_for_type(lbModule *m, Type *type) {
return {compare_proc->value, compare_proc->type};
}
- static u32 proc_index = 0;
+ static std::atomic<u32> proc_index;
char buf[32] = {};
- isize n = gb_snprintf(buf, 32, "__$equal%u", ++proc_index);
+ isize n = gb_snprintf(buf, 32, "__$equal%u", 1+proc_index.fetch_add(1));
char *str = gb_alloc_str_len(permanent_allocator(), buf, n-1);
String proc_name = make_string_c(str);
@@ -218,7 +218,9 @@ gb_internal lbValue lb_equal_proc_for_type(lbModule *m, Type *type) {
LLVMBuildRet(p->builder, LLVMConstInt(lb_type(m, t_bool), 0, false));
} else if (type->kind == Type_Union) {
- if (is_type_union_maybe_pointer(type)) {
+ if (type_size_of(type) == 0) {
+ LLVMBuildRet(p->builder, LLVMConstInt(lb_type(m, t_bool), 1, false));
+ } else if (is_type_union_maybe_pointer(type)) {
Type *v = type->Union.variants[0];
Type *pv = alloc_type_pointer(v);
@@ -656,10 +658,10 @@ gb_internal lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) {
GB_ASSERT(*found != nullptr);
return {(*found)->value, (*found)->type};
}
- static u32 proc_index = 0;
+ static std::atomic<u32> proc_index;
char buf[32] = {};
- isize n = gb_snprintf(buf, 32, "__$map_set-%u", ++proc_index);
+ isize n = gb_snprintf(buf, 32, "__$map_set-%u", 1+proc_index.fetch_add(1));
char *str = gb_alloc_str_len(permanent_allocator(), buf, n-1);
String proc_name = make_string_c(str);
@@ -772,56 +774,6 @@ gb_internal lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) {
return {p->value, p->type};
}
-
-gb_internal lbValue lb_generate_anonymous_proc_lit(lbModule *m, String const &prefix_name, Ast *expr, lbProcedure *parent) {
- MUTEX_GUARD(&m->gen->anonymous_proc_lits_mutex);
-
- lbProcedure **found = map_get(&m->gen->anonymous_proc_lits, expr);
- if (found) {
- return lb_find_procedure_value_from_entity(m, (*found)->entity);
- }
-
- ast_node(pl, ProcLit, expr);
-
- // NOTE(bill): Generate a new name
- // parent$count
- isize name_len = prefix_name.len + 1 + 8 + 1;
- char *name_text = gb_alloc_array(permanent_allocator(), char, name_len);
- i32 name_id = cast(i32)m->gen->anonymous_proc_lits.count;
-
- name_len = gb_snprintf(name_text, name_len, "%.*s$anon-%d", LIT(prefix_name), name_id);
- String name = make_string((u8 *)name_text, name_len-1);
-
- Type *type = type_of_expr(expr);
-
- Token token = {};
- token.pos = ast_token(expr).pos;
- token.kind = Token_Ident;
- token.string = name;
- Entity *e = alloc_entity_procedure(nullptr, token, type, pl->tags);
- e->file = expr->file();
- e->decl_info = pl->decl;
- e->code_gen_module = m;
- e->flags |= EntityFlag_ProcBodyChecked;
- lbProcedure *p = lb_create_procedure(m, e);
-
- lbValue value = {};
- value.value = p->value;
- value.type = p->type;
-
- array_add(&m->procedures_to_generate, p);
- if (parent != nullptr) {
- array_add(&parent->children, p);
- } else {
- string_map_set(&m->members, name, value);
- }
-
- map_set(&m->gen->anonymous_proc_lits, expr, p);
-
- return value;
-}
-
-
gb_internal lbValue lb_gen_map_cell_info_ptr(lbModule *m, Type *type) {
lbAddr *found = map_get(&m->map_cell_info_map, type);
if (found) {
@@ -1048,7 +1000,7 @@ struct lbGlobalVariable {
};
gb_internal lbProcedure *lb_create_startup_type_info(lbModule *m) {
- if (build_context.disallow_rtti) {
+ if (build_context.no_rtti) {
return nullptr;
}
Type *proc_type = alloc_type_proc(nullptr, nullptr, 0, nullptr, 0, false, ProcCC_CDecl);
@@ -1513,7 +1465,7 @@ gb_internal WORKER_TASK_PROC(lb_generate_missing_procedures_to_check_worker_proc
lbModule *m = cast(lbModule *)data;
for (isize i = 0; i < m->missing_procedures_to_check.count; i++) {
lbProcedure *p = m->missing_procedures_to_check[i];
- debugf("Generate missing procedure: %.*s\n", LIT(p->name));
+ debugf("Generate missing procedure: %.*s module %p\n", LIT(p->name), m);
lb_generate_procedure(m, p);
}
return 0;
@@ -1577,7 +1529,6 @@ gb_internal void lb_llvm_module_passes(lbGenerator *gen, bool do_threading) {
thread_pool_wait();
}
-
gb_internal String lb_filepath_ll_for_module(lbModule *m) {
String path = concatenate3_strings(permanent_allocator(),
build_context.build_paths[BuildPath_Output].basename,
@@ -1874,25 +1825,28 @@ gb_internal lbProcedure *lb_create_main_procedure(lbModule *m, lbProcedure *star
TEMPORARY_ALLOCATOR_GUARD();
auto args = array_make<lbValue>(temporary_allocator(), 1);
args[0] = lb_addr_load(p, all_tests_slice);
- lb_emit_call(p, runner, args);
+ lbValue result = lb_emit_call(p, runner, args);
+
+ lbValue exit_runner = lb_find_package_value(m, str_lit("os"), str_lit("exit"));
+ auto exit_args = array_make<lbValue>(temporary_allocator(), 1);
+ exit_args[0] = lb_emit_select(p, result, lb_const_int(m, t_int, 0), lb_const_int(m, t_int, 1));
+ lb_emit_call(p, exit_runner, exit_args, ProcInlining_none);
} else {
if (m->info->entry_point != nullptr) {
lbValue entry_point = lb_find_procedure_value_from_entity(m, m->info->entry_point);
lb_emit_call(p, entry_point, {}, ProcInlining_no_inline);
}
- }
-
-
- if (call_cleanup) {
- lbValue cleanup_runtime_value = {cleanup_runtime->value, cleanup_runtime->type};
- lb_emit_call(p, cleanup_runtime_value, {}, ProcInlining_none);
- }
+ if (call_cleanup) {
+ lbValue cleanup_runtime_value = {cleanup_runtime->value, cleanup_runtime->type};
+ lb_emit_call(p, cleanup_runtime_value, {}, ProcInlining_none);
+ }
- if (is_dll_main) {
- LLVMBuildRet(p->builder, LLVMConstInt(lb_type(m, t_i32), 1, false));
- } else {
- LLVMBuildRet(p->builder, LLVMConstInt(lb_type(m, t_i32), 0, false));
+ if (is_dll_main) {
+ LLVMBuildRet(p->builder, LLVMConstInt(lb_type(m, t_i32), 1, false));
+ } else {
+ LLVMBuildRet(p->builder, LLVMConstInt(lb_type(m, t_i32), 0, false));
+ }
}
lb_end_procedure_body(p);
@@ -2170,7 +2124,7 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
TIME_SECTION("LLVM Global Variables");
- if (!build_context.disallow_rtti) {
+ if (!build_context.no_rtti) {
lbModule *m = default_module;
{ // Add type info data