From 6ded538546cca4f1e50a011a64932f7f3c784cc2 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Thu, 4 Nov 2021 12:40:50 +0000 Subject: `@(linkage=)` for procedures and variables; `@(require)` for procedures; `package runtime` linkage improvements; Subsequence improvements to `lb_run_remove_unused_function_pass` --- src/llvm_backend_opt.cpp | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) (limited to 'src/llvm_backend_opt.cpp') diff --git a/src/llvm_backend_opt.cpp b/src/llvm_backend_opt.cpp index 75a377e5b..2648863e2 100644 --- a/src/llvm_backend_opt.cpp +++ b/src/llvm_backend_opt.cpp @@ -357,14 +357,14 @@ void lb_run_function_pass_manager(LLVMPassManagerRef fpm, lbProcedure *p) { } -void lb_run_remove_unused_function_pass(LLVMModuleRef mod) { +void lb_run_remove_unused_function_pass(lbModule *m) { isize removal_count = 0; isize pass_count = 0; isize const max_pass_count = 10; // Custom remove dead function pass for (; pass_count < max_pass_count; pass_count++) { bool was_dead_function = false; - for (LLVMValueRef func = LLVMGetFirstFunction(mod); + for (LLVMValueRef func = LLVMGetFirstFunction(m->mod); func != nullptr; /**/ ) { @@ -382,30 +382,20 @@ void lb_run_remove_unused_function_pass(LLVMModuleRef mod) { // Ignore for the time being continue; } - - if (name == "memset" || - name == "memmove" || - name == "memcpy") { + LLVMLinkage linkage = LLVMGetLinkage(curr_func); + if (linkage != LLVMInternalLinkage) { continue; } - if (is_arch_wasm()) { - if (name == "__ashlti3") { - LLVMSetLinkage(curr_func, LLVMExternalLinkage); + + Entity **found = map_get(&m->procedure_values, hash_pointer(curr_func)); + if (found && *found) { + Entity *e = *found; + bool is_required = (e->flags & EntityFlag_Require) == EntityFlag_Require; + if (is_required) { continue; } } - - LLVMLinkage linkage = LLVMGetLinkage(curr_func); - - switch (linkage) { - case LLVMExternalLinkage: - case LLVMDLLImportLinkage: - case LLVMDLLExportLinkage: - default: - continue; - case LLVMInternalLinkage: - break; - } + LLVMDeleteFunction(curr_func); was_dead_function = true; removal_count += 1; -- cgit v1.2.3