From e73993709e3f254bea39573adb555cbb41e79891 Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Tue, 10 Oct 2023 10:52:37 +0800 Subject: [PATCH] Use another default pipeline when opt-level is 0 (#2624) According to the description of `buildPerModuleDefaultPipeline()` and `buildLTOPreLinkDefaultPipeline()`, it is not allowed to call them with `O0` level. Use `buildO0DefaultPipeline` instead when the opt-level is 0. --- core/iwasm/compilation/aot_llvm_extra.cpp | 25 ++++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/core/iwasm/compilation/aot_llvm_extra.cpp b/core/iwasm/compilation/aot_llvm_extra.cpp index ab6c621a0..72e163fa2 100644 --- a/core/iwasm/compilation/aot_llvm_extra.cpp +++ b/core/iwasm/compilation/aot_llvm_extra.cpp @@ -343,18 +343,23 @@ aot_apply_llvm_new_pass_manager(AOTCompContext *comp_ctx, LLVMModuleRef module) ExitOnErr(PB.parsePassPipeline(MPM, comp_ctx->llvm_passes)); } - if (!disable_llvm_lto) { - /* Apply LTO for AOT mode */ - if (comp_ctx->comp_data->func_count >= 10 - || comp_ctx->enable_llvm_pgo || comp_ctx->use_prof_file) - /* Add the pre-link optimizations if the func count - is large enough or PGO is enabled */ - MPM.addPass(PB.buildLTOPreLinkDefaultPipeline(OL)); - else - MPM.addPass(PB.buildLTODefaultPipeline(OL, NULL)); + if (OptimizationLevel::O0 == OL) { + MPM.addPass(PB.buildO0DefaultPipeline(OL)); } else { - MPM.addPass(PB.buildPerModuleDefaultPipeline(OL)); + if (!disable_llvm_lto) { + /* Apply LTO for AOT mode */ + if (comp_ctx->comp_data->func_count >= 10 + || comp_ctx->enable_llvm_pgo || comp_ctx->use_prof_file) + /* Add the pre-link optimizations if the func count + is large enough or PGO is enabled */ + MPM.addPass(PB.buildLTOPreLinkDefaultPipeline(OL)); + else + MPM.addPass(PB.buildLTODefaultPipeline(OL, NULL)); + } + else { + MPM.addPass(PB.buildPerModuleDefaultPipeline(OL)); + } } /* Run specific passes for AOT indirect mode in last since general