From 52d871844c643f396a2bddee0753d24ff71ca3bb Mon Sep 17 00:00:00 2001 From: Min-Yih Hsu Date: Fri, 9 Apr 2021 13:00:46 -0700 Subject: [PATCH] llvm new-pm: Build O0 pipeline in the correct way Use `PassBuilder::buildO0DefaultPipeline` to build pipeline for -O0 in replacement of `PassBuilder::buildPerModuleDefaultPipeline`. This affects both normal and LTO settings. Two redundant Passes - which were added by accident - were also removed from LTO pipeline. --- src/zig_llvm.cpp | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/zig_llvm.cpp b/src/zig_llvm.cpp index 0d60d7a4ac..7866537c64 100644 --- a/src/zig_llvm.cpp +++ b/src/zig_llvm.cpp @@ -277,15 +277,8 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM }); } - // Passes for either debug or release build - if (is_debug) { - // NOTE: Always inliner will go away (in debug build) - // when the self-hosted compiler becomes mature. - pass_builder.registerPipelineStartEPCallback( - [](ModulePassManager &module_pm, OptimizationLevel OL) { - module_pm.addPass(AlwaysInlinerPass()); - }); - } else { + // Passes specific for release build + if (!is_debug) { pass_builder.registerPipelineStartEPCallback( [](ModulePassManager &module_pm, OptimizationLevel OL) { module_pm.addPass( @@ -312,10 +305,10 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM opt_level = OptimizationLevel::O3; // Initialize the PassManager - if (lto) { + if (opt_level == OptimizationLevel::O0) { + module_pm = pass_builder.buildO0DefaultPipeline(opt_level, lto); + } else if (lto) { module_pm = pass_builder.buildLTOPreLinkDefaultPipeline(opt_level); - module_pm.addPass(CanonicalizeAliasesPass()); - module_pm.addPass(NameAnonGlobalPass()); } else { module_pm = pass_builder.buildPerModuleDefaultPipeline(opt_level); }