mirror of
https://github.com/odin-lang/Odin.git
synced 2026-07-12 10:59:33 +00:00
Remove old pass manager
This commit is contained in:
@@ -1109,7 +1109,6 @@ gb_internal i64 odin_compile_timestamp(void) {
|
||||
return ns_after_1970;
|
||||
}
|
||||
|
||||
gb_internal bool lb_use_new_pass_system(void);
|
||||
|
||||
gb_internal void init_universal(void) {
|
||||
BuildContext *bc = &build_context;
|
||||
@@ -1382,7 +1381,8 @@ gb_internal void init_universal(void) {
|
||||
}
|
||||
|
||||
{
|
||||
bool f16_supported = lb_use_new_pass_system();
|
||||
// Available since LLVM 17 / new pass system, which is the minimum now.
|
||||
bool f16_supported = true;
|
||||
if (is_arch_wasm()) {
|
||||
f16_supported = false;
|
||||
} else if (build_context.metrics.os == TargetOs_darwin && build_context.metrics.arch == TargetArch_amd64) {
|
||||
|
||||
@@ -2408,10 +2408,6 @@ gb_internal WORKER_TASK_PROC(lb_llvm_function_pass_per_module) {
|
||||
LLVMInitializeFunctionPassManager(m->function_pass_managers[i]);
|
||||
}
|
||||
|
||||
lb_populate_function_pass_manager(m, m->function_pass_managers[lbFunctionPassManager_default], false, build_context.optimization_level);
|
||||
lb_populate_function_pass_manager(m, m->function_pass_managers[lbFunctionPassManager_default_without_memcpy], true, build_context.optimization_level);
|
||||
lb_populate_function_pass_manager_specific(m, m->function_pass_managers[lbFunctionPassManager_none], -1);
|
||||
|
||||
for (i32 i = 0; i < lbFunctionPassManager_COUNT; i++) {
|
||||
LLVMFinalizeFunctionPassManager(m->function_pass_managers[i]);
|
||||
}
|
||||
@@ -2480,11 +2476,8 @@ gb_internal WORKER_TASK_PROC(lb_llvm_module_pass_worker_proc) {
|
||||
auto wd = cast(lbLLVMModulePassWorkerData *)data;
|
||||
|
||||
LLVMPassManagerRef module_pass_manager = LLVMCreatePassManager();
|
||||
lb_populate_module_pass_manager(wd->target_machine, module_pass_manager, build_context.optimization_level);
|
||||
LLVMRunPassManager(module_pass_manager, wd->m->mod);
|
||||
|
||||
|
||||
#if LB_USE_NEW_PASS_SYSTEM
|
||||
auto passes = array_make<char const *>(heap_allocator(), 0, 64);
|
||||
defer (array_free(&passes));
|
||||
|
||||
@@ -2560,7 +2553,6 @@ gb_internal WORKER_TASK_PROC(lb_llvm_module_pass_worker_proc) {
|
||||
exit_with_errors();
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (LLVM_IGNORE_VERIFICATION) {
|
||||
return 0;
|
||||
@@ -2855,7 +2847,6 @@ gb_internal bool lb_llvm_object_generation(lbGenerator *gen, bool do_threading)
|
||||
|
||||
gb_internal lbProcedure *lb_create_main_procedure(lbModule *m, lbProcedure *startup_runtime, lbProcedure *cleanup_runtime) {
|
||||
LLVMPassManagerRef default_function_pass_manager = LLVMCreateFunctionPassManagerForModule(m->mod);
|
||||
lb_populate_function_pass_manager(m, default_function_pass_manager, false, build_context.optimization_level);
|
||||
LLVMFinalizeFunctionPassManager(default_function_pass_manager);
|
||||
|
||||
Type *params = alloc_type_tuple();
|
||||
@@ -3164,9 +3155,6 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
|
||||
// GB_ASSERT_MSG(LLVMTargetHasAsmBackend(target));
|
||||
|
||||
LLVMCodeGenOptLevel code_gen_level = LLVMCodeGenLevelNone;
|
||||
if (!LB_USE_NEW_PASS_SYSTEM) {
|
||||
build_context.optimization_level = gb_clamp(build_context.optimization_level, -1, 2);
|
||||
}
|
||||
switch (build_context.optimization_level) {
|
||||
default:/*fallthrough*/
|
||||
case 0: code_gen_level = LLVMCodeGenLevelNone; break;
|
||||
|
||||
@@ -17,17 +17,12 @@
|
||||
#include <llvm-c/DebugInfo.h>
|
||||
#include <llvm-c/Transforms/PassBuilder.h>
|
||||
|
||||
// These two are always available since we're on >= 17
|
||||
#define LB_USE_NEW_PASS_SYSTEM 1
|
||||
|
||||
|
||||
#if LLVM_VERSION_MAJOR >= 19
|
||||
#define LLVMDIBuilderInsertDeclareAtEnd(...) LLVMDIBuilderInsertDeclareRecordAtEnd(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
gb_internal bool lb_use_new_pass_system(void) {
|
||||
return LB_USE_NEW_PASS_SYSTEM;
|
||||
}
|
||||
|
||||
struct lbProcedure;
|
||||
|
||||
struct lbValue {
|
||||
@@ -611,11 +606,7 @@ gb_internal lbValue lb_emit_source_code_location_as_global_ptr(lbProcedure *p, S
|
||||
gb_internal LLVMMetadataRef lb_debug_location_from_token_pos(lbProcedure *p, TokenPos pos);
|
||||
|
||||
gb_internal LLVMTypeRef llvm_array_type(LLVMTypeRef ElementType, uint64_t ElementCount) {
|
||||
#if LB_USE_NEW_PASS_SYSTEM
|
||||
return LLVMArrayType2(ElementType, ElementCount);
|
||||
#else
|
||||
return LLVMArrayType(ElementType, cast(unsigned)ElementCount);
|
||||
#endif
|
||||
}
|
||||
|
||||
gb_internal lbValue lb_emit_struct_iv(lbProcedure *p, lbValue agg, lbValue field, i32 index);
|
||||
|
||||
@@ -32,11 +32,6 @@
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
gb_internal void lb_populate_function_pass_manager(lbModule *m, LLVMPassManagerRef fpm, bool ignore_memcpy_pass, i32 optimization_level);
|
||||
gb_internal void lb_add_function_simplifcation_passes(LLVMPassManagerRef mpm, i32 optimization_level);
|
||||
gb_internal void lb_populate_module_pass_manager(LLVMTargetMachineRef target_machine, LLVMPassManagerRef mpm, i32 optimization_level);
|
||||
gb_internal void lb_populate_function_pass_manager_specific(lbModule *m, LLVMPassManagerRef fpm, i32 optimization_level);
|
||||
|
||||
// gb_internal LLVMBool lb_must_preserve_predicate_callback(LLVMValueRef value, void *user_data) {
|
||||
// lbModule *m = cast(lbModule *)user_data;
|
||||
// if (m == nullptr) {
|
||||
@@ -48,221 +43,6 @@ gb_internal void lb_populate_function_pass_manager_specific(lbModule *m, LLVMPas
|
||||
// return LLVMIsAAllocaInst(value) != nullptr;
|
||||
// }
|
||||
|
||||
gb_internal bool lb_opt_ignore(i32 optimization_level) {
|
||||
return optimization_level < 0;
|
||||
}
|
||||
|
||||
gb_internal void lb_basic_populate_function_pass_manager(LLVMPassManagerRef fpm, i32 optimization_level) {
|
||||
if (lb_opt_ignore(optimization_level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if !LB_USE_NEW_PASS_SYSTEM
|
||||
if (false && optimization_level <= 0 && build_context.ODIN_DEBUG) {
|
||||
LLVMAddMergedLoadStoreMotionPass(fpm);
|
||||
} else {
|
||||
LLVMAddPromoteMemoryToRegisterPass(fpm);
|
||||
LLVMAddMergedLoadStoreMotionPass(fpm);
|
||||
if (!build_context.ODIN_DEBUG) {
|
||||
LLVMAddEarlyCSEPass(fpm);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
gb_internal void lb_populate_function_pass_manager(lbModule *m, LLVMPassManagerRef fpm, bool ignore_memcpy_pass, i32 optimization_level) {
|
||||
if (lb_opt_ignore(optimization_level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if !LB_USE_NEW_PASS_SYSTEM
|
||||
if (ignore_memcpy_pass) {
|
||||
lb_basic_populate_function_pass_manager(fpm, optimization_level);
|
||||
return;
|
||||
} else if (optimization_level <= 0) {
|
||||
LLVMAddMemCpyOptPass(fpm);
|
||||
lb_basic_populate_function_pass_manager(fpm, optimization_level);
|
||||
return;
|
||||
}
|
||||
|
||||
#if 0
|
||||
LLVMPassManagerBuilderRef pmb = LLVMPassManagerBuilderCreate();
|
||||
LLVMPassManagerBuilderSetOptLevel(pmb, optimization_level);
|
||||
LLVMPassManagerBuilderSetSizeLevel(pmb, optimization_level);
|
||||
LLVMPassManagerBuilderPopulateFunctionPassManager(pmb, fpm);
|
||||
#else
|
||||
LLVMAddMemCpyOptPass(fpm);
|
||||
lb_basic_populate_function_pass_manager(fpm, optimization_level);
|
||||
|
||||
LLVMAddSCCPPass(fpm);
|
||||
|
||||
LLVMAddPromoteMemoryToRegisterPass(fpm);
|
||||
LLVMAddUnifyFunctionExitNodesPass(fpm);
|
||||
|
||||
LLVMAddCFGSimplificationPass(fpm);
|
||||
LLVMAddEarlyCSEPass(fpm);
|
||||
LLVMAddLowerExpectIntrinsicPass(fpm);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
gb_internal void lb_populate_function_pass_manager_specific(lbModule *m, LLVMPassManagerRef fpm, i32 optimization_level) {
|
||||
if (lb_opt_ignore(optimization_level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if !LB_USE_NEW_PASS_SYSTEM
|
||||
if (optimization_level <= 0) {
|
||||
LLVMAddMemCpyOptPass(fpm);
|
||||
lb_basic_populate_function_pass_manager(fpm, optimization_level);
|
||||
return;
|
||||
}
|
||||
|
||||
#if 1
|
||||
LLVMPassManagerBuilderRef pmb = LLVMPassManagerBuilderCreate();
|
||||
LLVMPassManagerBuilderSetOptLevel(pmb, optimization_level);
|
||||
LLVMPassManagerBuilderSetSizeLevel(pmb, optimization_level);
|
||||
LLVMPassManagerBuilderPopulateFunctionPassManager(pmb, fpm);
|
||||
#else
|
||||
LLVMAddMemCpyOptPass(fpm);
|
||||
LLVMAddPromoteMemoryToRegisterPass(fpm);
|
||||
LLVMAddMergedLoadStoreMotionPass(fpm);
|
||||
LLVMAddEarlyCSEPass(fpm);
|
||||
|
||||
LLVMAddMergedLoadStoreMotionPass(fpm);
|
||||
LLVMAddPromoteMemoryToRegisterPass(fpm);
|
||||
LLVMAddCFGSimplificationPass(fpm);
|
||||
|
||||
LLVMAddSCCPPass(fpm);
|
||||
|
||||
LLVMAddPromoteMemoryToRegisterPass(fpm);
|
||||
LLVMAddUnifyFunctionExitNodesPass(fpm);
|
||||
|
||||
LLVMAddCFGSimplificationPass(fpm);
|
||||
LLVMAddEarlyCSEPass(fpm);
|
||||
LLVMAddLowerExpectIntrinsicPass(fpm);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
gb_internal void lb_add_function_simplifcation_passes(LLVMPassManagerRef mpm, i32 optimization_level) {
|
||||
#if !LB_USE_NEW_PASS_SYSTEM
|
||||
LLVMAddCFGSimplificationPass(mpm);
|
||||
|
||||
LLVMAddJumpThreadingPass(mpm);
|
||||
|
||||
LLVMAddSimplifyLibCallsPass(mpm);
|
||||
|
||||
LLVMAddTailCallEliminationPass(mpm);
|
||||
LLVMAddCFGSimplificationPass(mpm);
|
||||
LLVMAddReassociatePass(mpm);
|
||||
|
||||
LLVMAddLoopRotatePass(mpm);
|
||||
LLVMAddLICMPass(mpm);
|
||||
LLVMAddLoopUnswitchPass(mpm);
|
||||
|
||||
LLVMAddCFGSimplificationPass(mpm);
|
||||
LLVMAddLoopIdiomPass(mpm);
|
||||
LLVMAddLoopDeletionPass(mpm);
|
||||
|
||||
LLVMAddMergedLoadStoreMotionPass(mpm);
|
||||
|
||||
LLVMAddMemCpyOptPass(mpm);
|
||||
LLVMAddSCCPPass(mpm);
|
||||
|
||||
LLVMAddBitTrackingDCEPass(mpm);
|
||||
|
||||
LLVMAddJumpThreadingPass(mpm);
|
||||
LLVMAddLICMPass(mpm);
|
||||
|
||||
LLVMAddLoopRerollPass(mpm);
|
||||
LLVMAddAggressiveDCEPass(mpm);
|
||||
LLVMAddCFGSimplificationPass(mpm);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
gb_internal void lb_populate_module_pass_manager(LLVMTargetMachineRef target_machine, LLVMPassManagerRef mpm, i32 optimization_level) {
|
||||
|
||||
// NOTE(bill): Treat -opt:3 as if it was -opt:2
|
||||
// TODO(bill): Determine which opt definitions should exist in the first place
|
||||
if (optimization_level <= 0 && build_context.ODIN_DEBUG) {
|
||||
return;
|
||||
}
|
||||
#if !LB_USE_NEW_PASS_SYSTEM
|
||||
LLVMAddAlwaysInlinerPass(mpm);
|
||||
LLVMAddStripDeadPrototypesPass(mpm);
|
||||
LLVMAddAnalysisPasses(target_machine, mpm);
|
||||
LLVMAddPruneEHPass(mpm);
|
||||
if (optimization_level <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
LLVMAddGlobalDCEPass(mpm);
|
||||
|
||||
if (optimization_level >= 2) {
|
||||
// NOTE(bill, 2021-03-29: use this causes invalid code generation)
|
||||
// LLVMPassManagerBuilderRef pmb = LLVMPassManagerBuilderCreate();
|
||||
// LLVMPassManagerBuilderSetOptLevel(pmb, optimization_level);
|
||||
// LLVMPassManagerBuilderPopulateModulePassManager(pmb, mpm);
|
||||
// LLVMPassManagerBuilderPopulateLTOPassManager(pmb, mpm, false, true);
|
||||
// return;
|
||||
}
|
||||
|
||||
|
||||
LLVMAddIPSCCPPass(mpm);
|
||||
LLVMAddCalledValuePropagationPass(mpm);
|
||||
|
||||
LLVMAddGlobalOptimizerPass(mpm);
|
||||
LLVMAddDeadArgEliminationPass(mpm);
|
||||
|
||||
LLVMAddCFGSimplificationPass(mpm);
|
||||
|
||||
LLVMAddPruneEHPass(mpm);
|
||||
if (optimization_level < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
LLVMAddFunctionInliningPass(mpm);
|
||||
|
||||
|
||||
lb_add_function_simplifcation_passes(mpm, optimization_level);
|
||||
|
||||
LLVMAddGlobalDCEPass(mpm);
|
||||
LLVMAddGlobalOptimizerPass(mpm);
|
||||
|
||||
|
||||
LLVMAddLoopRotatePass(mpm);
|
||||
|
||||
LLVMAddLoopVectorizePass(mpm);
|
||||
|
||||
if (optimization_level >= 2) {
|
||||
LLVMAddEarlyCSEPass(mpm);
|
||||
LLVMAddLICMPass(mpm);
|
||||
LLVMAddLoopUnswitchPass(mpm);
|
||||
LLVMAddCFGSimplificationPass(mpm);
|
||||
}
|
||||
|
||||
LLVMAddCFGSimplificationPass(mpm);
|
||||
|
||||
LLVMAddSLPVectorizePass(mpm);
|
||||
LLVMAddLICMPass(mpm);
|
||||
|
||||
LLVMAddAlignmentFromAssumptionsPass(mpm);
|
||||
|
||||
LLVMAddStripDeadPrototypesPass(mpm);
|
||||
|
||||
if (optimization_level >= 2) {
|
||||
LLVMAddGlobalDCEPass(mpm);
|
||||
LLVMAddConstantMergePass(mpm);
|
||||
}
|
||||
|
||||
LLVMAddCFGSimplificationPass(mpm);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
IMPORTANT NOTE(bill, 2021-11-06): Custom Passes
|
||||
|
||||
|
||||
@@ -965,8 +965,7 @@ gb_internal lbValue lb_emit_call_internal(lbProcedure *p, lbValue value, lbValue
|
||||
for (unsigned i = 0; i < param_count; i++) {
|
||||
LLVMTypeRef param_type = param_types[i];
|
||||
LLVMTypeRef arg_type = LLVMTypeOf(args[i]);
|
||||
if (LB_USE_NEW_PASS_SYSTEM &&
|
||||
arg_type != param_type) {
|
||||
if (arg_type != param_type) {
|
||||
LLVMTypeKind arg_kind = LLVMGetTypeKind(arg_type);
|
||||
LLVMTypeKind param_kind = LLVMGetTypeKind(param_type);
|
||||
if (arg_kind == param_kind) {
|
||||
|
||||
@@ -875,7 +875,7 @@ gb_internal bool parse_build_flags(Array<String> args) {
|
||||
} else if (value.value_string == "speed") {
|
||||
build_context.custom_optimization_level = true;
|
||||
build_context.optimization_level = 2;
|
||||
} else if (value.value_string == "aggressive" && LB_USE_NEW_PASS_SYSTEM) {
|
||||
} else if (value.value_string == "aggressive") {
|
||||
build_context.custom_optimization_level = true;
|
||||
build_context.optimization_level = 3;
|
||||
} else {
|
||||
@@ -884,9 +884,7 @@ gb_internal bool parse_build_flags(Array<String> args) {
|
||||
gb_printf_err("\tminimal\n");
|
||||
gb_printf_err("\tsize\n");
|
||||
gb_printf_err("\tspeed\n");
|
||||
if (LB_USE_NEW_PASS_SYSTEM) {
|
||||
gb_printf_err("\taggressive\n");
|
||||
}
|
||||
gb_printf_err("\taggressive\n");
|
||||
gb_printf_err("\tnone (useful for -debug builds)\n");
|
||||
bad_flags = true;
|
||||
}
|
||||
@@ -3041,9 +3039,7 @@ gb_internal int print_show_help(String const arg0, String command, String option
|
||||
print_usage_line(3, "-o:minimal");
|
||||
print_usage_line(3, "-o:size");
|
||||
print_usage_line(3, "-o:speed");
|
||||
if (LB_USE_NEW_PASS_SYSTEM) {
|
||||
print_usage_line(3, "-o:aggressive (use this with caution)");
|
||||
}
|
||||
print_usage_line(2, "The default is -o:minimal. If -debug is set, the default is -o:none.");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user