From c07584400134bb5f1be80b4f5df96eb1d8c94324 Mon Sep 17 00:00:00 2001 From: Petr Penzin Date: Thu, 28 Jul 2022 19:29:02 -0700 Subject: [PATCH] Add our own legacy loop unswitch pass (#1339) Since legacy binding for loop unswitch pass was removed and we can't get it back. Implement its equivalent in `aot_llvm_extra.cpp` and use it in `aot_compiler.c`. Follow up to #1183. --- core/iwasm/compilation/aot_compiler.c | 5 ++--- core/iwasm/compilation/aot_llvm.h | 3 +++ core/iwasm/compilation/aot_llvm_extra.cpp | 9 +++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/core/iwasm/compilation/aot_compiler.c b/core/iwasm/compilation/aot_compiler.c index 7491023c..3cece0a5 100644 --- a/core/iwasm/compilation/aot_compiler.c +++ b/core/iwasm/compilation/aot_compiler.c @@ -2643,9 +2643,8 @@ apply_func_passes(AOTCompContext *comp_ctx) LLVMAddLoopRotatePass(pass_mgr); #if LLVM_VERSION_MAJOR < 15 LLVMAddLoopUnswitchPass(pass_mgr); - /* Binding disabled in LLVM 15, don't add the pass util we can either - add a binding to SimpleLoopUnswitchPass, or add it to - aot_llvm_extra.cpp */ +#else + aot_add_simple_loop_unswitch_pass(pass_mgr); #endif LLVMAddInstructionCombiningPass(pass_mgr); LLVMAddCFGSimplificationPass(pass_mgr); diff --git a/core/iwasm/compilation/aot_llvm.h b/core/iwasm/compilation/aot_llvm.h index 28967cc7..7964c3ac 100644 --- a/core/iwasm/compilation/aot_llvm.h +++ b/core/iwasm/compilation/aot_llvm.h @@ -499,6 +499,9 @@ aot_check_simd_compatibility(const char *arch_c_str, const char *cpu_c_str); void aot_add_expand_memory_op_pass(LLVMPassManagerRef pass); +void +aot_add_simple_loop_unswitch_pass(LLVMPassManagerRef pass); + void aot_apply_llvm_new_pass_manager(AOTCompContext *comp_ctx); diff --git a/core/iwasm/compilation/aot_llvm_extra.cpp b/core/iwasm/compilation/aot_llvm_extra.cpp index 5cc2019a..ed9fabd9 100644 --- a/core/iwasm/compilation/aot_llvm_extra.cpp +++ b/core/iwasm/compilation/aot_llvm_extra.cpp @@ -66,6 +66,9 @@ aot_check_simd_compatibility(const char *arch_c_str, const char *cpu_c_str); void aot_add_expand_memory_op_pass(LLVMPassManagerRef pass); +void +aot_add_simple_loop_unswitch_pass(LLVMPassManagerRef pass); + void aot_func_disable_tce(LLVMValueRef func); @@ -258,6 +261,12 @@ aot_add_expand_memory_op_pass(LLVMPassManagerRef pass) unwrap(pass)->add(new ExpandMemoryOpPass()); } +void +aot_add_simple_loop_unswitch_pass(LLVMPassManagerRef pass) +{ + unwrap(pass)->add(createSimpleLoopUnswitchLegacyPass()); +} + bool aot_check_simd_compatibility(const char *arch_c_str, const char *cpu_c_str) {