From 83c7bddf7db2814422e8fd5bedddf15028fb003b Mon Sep 17 00:00:00 2001 From: Arthur Eubanks Date: Tue, 2 Mar 2021 14:49:46 -0800 Subject: [PATCH] [opt] Error if -debug-pass is specified alongside the new PM Reviewed By: ychen Differential Revision: https://reviews.llvm.org/D97810 --- include/llvm/IR/LegacyPassManager.h | 4 ++++ lib/IR/LegacyPassManager.cpp | 2 ++ test/Other/debug-pass-npm.ll | 4 ++++ tools/opt/opt.cpp | 6 ++++++ 4 files changed, 16 insertions(+) create mode 100644 test/Other/debug-pass-npm.ll diff --git a/include/llvm/IR/LegacyPassManager.h b/include/llvm/IR/LegacyPassManager.h index 2b87143276b..2459f0a5450 100644 --- a/include/llvm/IR/LegacyPassManager.h +++ b/include/llvm/IR/LegacyPassManager.h @@ -26,6 +26,10 @@ class Module; namespace legacy { +// Whether or not -debug-pass has been specified. For use to check if it's +// specified alongside the new PM. +bool debugPassSpecified(); + class PassManagerImpl; class FunctionPassManagerImpl; diff --git a/lib/IR/LegacyPassManager.cpp b/lib/IR/LegacyPassManager.cpp index 94be208617c..32840fdeddf 100644 --- a/lib/IR/LegacyPassManager.cpp +++ b/lib/IR/LegacyPassManager.cpp @@ -242,6 +242,8 @@ void PassManagerPrettyStackEntry::print(raw_ostream &OS) const { namespace llvm { namespace legacy { +bool debugPassSpecified() { return PassDebugging != Disabled; } + //===----------------------------------------------------------------------===// // FunctionPassManagerImpl // diff --git a/test/Other/debug-pass-npm.ll b/test/Other/debug-pass-npm.ll new file mode 100644 index 00000000000..55c9baa6c57 --- /dev/null +++ b/test/Other/debug-pass-npm.ll @@ -0,0 +1,4 @@ +; RUN: opt -enable-new-pm=0 -O1 %s -debug-pass=Structure +; RUN: not opt -enable-new-pm=1 -O1 %s -debug-pass=Structure 2>&1 | FileCheck %s + +; CHECK: does not work diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index 48b0e397c98..f690d5f1a78 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -775,6 +775,12 @@ int main(int argc, char **argv) { "full list of passes, see the '--print-passes' flag.\n"; return 1; } + if (legacy::debugPassSpecified()) { + errs() + << "-debug-pass does not work with the new PM, either use " + "-debug-pass-manager, or use the legacy PM (-enable-new-pm=0)\n"; + return 1; + } if (PassPipeline.getNumOccurrences() > 0 && PassList.size() > 0) { errs() << "Cannot specify passes via both -foo-pass and --passes=foo-pass\n";