mirror of
https://github.com/odin-lang/Odin.git
synced 2026-06-05 02:04:06 +00:00
Compile wasm64; Add lb_run_remove_unused_function_pass
This commit is contained in:
@@ -355,3 +355,52 @@ void lb_run_function_pass_manager(LLVMPassManagerRef fpm, lbProcedure *p) {
|
||||
// are not removed
|
||||
lb_run_remove_dead_instruction_pass(p);
|
||||
}
|
||||
|
||||
|
||||
void lb_run_remove_unused_function_pass(LLVMModuleRef mod) {
|
||||
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);
|
||||
func != nullptr;
|
||||
/**/
|
||||
) {
|
||||
LLVMValueRef curr_func = func;
|
||||
func = LLVMGetNextFunction(func);
|
||||
|
||||
LLVMUseRef first_use = LLVMGetFirstUse(curr_func);
|
||||
if (first_use != nullptr) {
|
||||
continue;
|
||||
}
|
||||
String name = {};
|
||||
name.text = cast(u8 *)LLVMGetValueName2(curr_func, cast(size_t *)&name.len);
|
||||
|
||||
if (LLVMIsDeclaration(curr_func)) {
|
||||
// Ignore for the time being
|
||||
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;
|
||||
}
|
||||
if (!was_dead_function) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user