Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NewPM] Add disable-passes command line option #76714

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion llvm/lib/Passes/PassBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
//===----------------------------------------------------------------------===//

#include "llvm/Passes/PassBuilder.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Analysis/AliasAnalysisEvaluator.h"
#include "llvm/Analysis/AliasSetTracker.h"
Expand Down Expand Up @@ -288,6 +289,10 @@ using namespace llvm;
static const Regex DefaultAliasRegex(
"^(default|thinlto-pre-link|thinlto|lto-pre-link|lto)<(O[0123sz])>$");

static cl::list<std::string>
DisablePasses("disable-passes", llvm::cl::desc("Disable specified passes"),
cl::CommaSeparated, cl::Hidden);

namespace llvm {
cl::opt<bool> PrintPipelinePasses(
"print-pipeline-passes",
Expand Down Expand Up @@ -406,7 +411,8 @@ AnalysisKey NoOpLoopAnalysis::Key;
/// We currently only use this for --print-before/after.
bool shouldPopulateClassToPassNames() {
return PrintPipelinePasses || !printBeforePasses().empty() ||
!printAfterPasses().empty() || !isFilterPassesEmpty();
!printAfterPasses().empty() || !isFilterPassesEmpty() ||
!DisablePasses.empty();
}

// A pass for testing -print-on-crash.
Expand Down Expand Up @@ -482,6 +488,16 @@ PassBuilder::PassBuilder(TargetMachine *TM, PipelineTuningOptions PTO,
#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
#include "PassRegistry.def"

if (!DisablePasses.empty()) {
SmallSet<StringRef, 8> S;
for (const auto &P : DisablePasses)
S.insert(P);
PIC->registerShouldRunOptionalPassCallback(
[PassNameSet = std::move(S), PIC](StringRef Name, Any IR) {
return !PassNameSet.contains(PIC->getPassNameForClassName(Name));
});
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions llvm/test/tools/opt/disable-passes.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
; RUN: opt --disable-output --debug-pass-manager \
; RUN: --passes='default<O2>' --disable-passes=early-cse,inline < %s 2>&1 | FileCheck %s
define void @test() {
ret void
}

; CHECK: Skipping pass: InlinerPass on (test)
; CHECK: Skipping pass: EarlyCSEPass on test
Loading