diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -1149,6 +1149,9 @@ SI.registerCallbacks(PIC); PassBuilder PB(CodeGenOpts.DebugPassManager, TM.get(), PTO, PGOOpt, &PIC); + // Sets legacy pass manager OptBisect to the same one as npm so passes are properly skipped + TheModule->getContext().setOptPassGate(SI.getOptBisect()); + // Attempt to load pass plugins and register their callbacks with PB. for (auto &PluginFN : CodeGenOpts.PassPlugins) { auto PassPlugin = PassPlugin::Load(PluginFN); diff --git a/clang/test/CodeGen/new-pass-manager-O1-opt-bisect.c b/clang/test/CodeGen/new-pass-manager-O1-opt-bisect.c new file mode 100644 --- /dev/null +++ b/clang/test/CodeGen/new-pass-manager-O1-opt-bisect.c @@ -0,0 +1,8 @@ +// Test NPM with -O1/opt-bisect +// +// RUN: %clang_cc1 -triple x86_64-linux-gnu -O1 -fexperimental-new-pass-manager %s -fdebug-pass-manager -mllvm -opt-bisect-limit=-1 -emit-llvm -o /dev/null 2>&1 | FileCheck %s + +// CHECK: BISECT: running pass (1) +// CHECK-NOT: BISECT: running pass (1) + +int func(int a) { return a; } diff --git a/llvm/include/llvm/Passes/StandardInstrumentations.h b/llvm/include/llvm/Passes/StandardInstrumentations.h --- a/llvm/include/llvm/Passes/StandardInstrumentations.h +++ b/llvm/include/llvm/Passes/StandardInstrumentations.h @@ -281,6 +281,7 @@ void registerCallbacks(PassInstrumentationCallbacks &PIC); TimePassesHandler &getTimePasses() { return TimePasses; } + OptBisectInstrumentation &getOptBisect() { return OptBisect; } }; extern template class ChangeReporter;