Skip to content

Commit 284a13f

Browse files
Short names with both NPM and Legacy, updated test, solved nits
1 parent 825b711 commit 284a13f

File tree

5 files changed

+52
-24
lines changed

5 files changed

+52
-24
lines changed

llvm/include/llvm/Pass.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ class LLVM_ABI Pass {
114114
/// Registration templates, but can be overloaded directly.
115115
virtual StringRef getPassName() const;
116116

117+
/// getPassArgument - Return a nice clean name for a pass
118+
/// corresponding to that used to enable the pass in opt
119+
virtual StringRef getPassArgument() const;
120+
117121
/// getPassID - Return the PassID number that corresponds to this pass.
118122
AnalysisID getPassID() const {
119123
return PassID;

llvm/lib/IR/OptBisect.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ bool OptBisect::shouldRunPass(StringRef PassName,
7575
static void printDisablePassMessage(const StringRef &Name, StringRef TargetDesc,
7676
bool Running) {
7777
StringRef Status = Running ? "" : "NOT ";
78-
dbgs() << "DISABLE: " << Status << "running pass " << Name << " on "
78+
dbgs() << "OptDisable: " << Status << "running pass " << Name << " on "
7979
<< TargetDesc << "\n";
8080
}
8181

@@ -87,7 +87,7 @@ bool OptDisable::shouldRunPass(StringRef PassName,
8787
StringRef IRDescription) const {
8888
assert(isEnabled());
8989

90-
bool ShouldRun = !DisabledPasses.contains(PassName.lower());
90+
const bool ShouldRun = !DisabledPasses.contains(PassName.lower());
9191
if (OptDisableVerbose)
9292
printDisablePassMessage(PassName, IRDescription, ShouldRun);
9393
return ShouldRun;

llvm/lib/IR/Pass.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,13 @@ static std::string getDescription(const Module &M) {
6262

6363
bool ModulePass::skipModule(const Module &M) const {
6464
const OptPassGate &Gate = M.getContext().getOptPassGate();
65+
66+
StringRef PassName = this->getPassArgument();
67+
if (PassName.empty())
68+
PassName = this->getPassName();
69+
6570
return Gate.isEnabled() &&
66-
!Gate.shouldRunPass(this->getPassName(), getDescription(M));
71+
!Gate.shouldRunPass(PassName, getDescription(M));
6772
}
6873

6974
bool Pass::mustPreserveAnalysisID(char &AID) const {
@@ -86,6 +91,16 @@ StringRef Pass::getPassName() const {
8691
return "Unnamed pass: implement Pass::getPassName()";
8792
}
8893

94+
/// getPassArgument - Return a nice clean name for a pass
95+
/// corresponding to that used to enable the pass in opt
96+
StringRef Pass::getPassArgument() const {
97+
AnalysisID AID = getPassID();
98+
const PassInfo *PI = PassRegistry::getPassRegistry()->getPassInfo(AID);
99+
if (PI)
100+
return PI->getPassArgument();
101+
return "";
102+
}
103+
89104
void Pass::preparePassManager(PMStack &) {
90105
// By default, don't do anything.
91106
}
@@ -173,8 +188,13 @@ static std::string getDescription(const Function &F) {
173188

174189
bool FunctionPass::skipFunction(const Function &F) const {
175190
OptPassGate &Gate = F.getContext().getOptPassGate();
191+
192+
StringRef PassName = this->getPassArgument();
193+
if (PassName.empty())
194+
PassName = this->getPassName();
195+
176196
if (Gate.isEnabled() &&
177-
!Gate.shouldRunPass(this->getPassName(), getDescription(F)))
197+
!Gate.shouldRunPass(PassName, getDescription(F)))
178198
return true;
179199

180200
if (F.hasOptNone()) {

llvm/lib/Passes/StandardInstrumentations.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,9 +1078,13 @@ void OptPassGateInstrumentation::registerCallbacks(
10781078
if (!PassGate.isEnabled())
10791079
return;
10801080

1081-
PIC.registerShouldRunOptionalPassCallback([this](StringRef PassName, Any IR) {
1082-
return this->shouldRun(PassName, IR);
1083-
});
1081+
PIC.registerShouldRunOptionalPassCallback(
1082+
[this, &PIC](StringRef ClassName, Any IR) {
1083+
StringRef PassName = PIC.getPassNameForClassName(ClassName);
1084+
if (PassName.empty())
1085+
return this->shouldRun(ClassName, IR);
1086+
return this->shouldRun(PassName, IR);
1087+
});
10841088
}
10851089

10861090
raw_ostream &PrintPassInstrumentation::print() {

llvm/test/Other/opt-disable.ll

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,33 @@
44

55
; RUN: opt -disable-output -disable-verify \
66
; RUN: -opt-disable-enable-verbosity \
7-
; RUN: -passes=inferattrs -opt-disable=inferfunctionattrspass %s 2>&1 \
7+
; RUN: -passes=inferattrs -opt-disable=inferattrs %s 2>&1 \
88
; RUN: | FileCheck %s --check-prefix=CHECK-MODULE-PASS
9-
; CHECK-MODULE-PASS: DISABLE: NOT running pass InferFunctionAttrsPass on [module]
9+
; CHECK-MODULE-PASS: OptDisable: NOT running pass inferattrs on [module]
1010

1111
; RUN: opt -disable-output -disable-verify \
1212
; RUN: -opt-disable-enable-verbosity \
13-
; RUN: -passes=sroa -opt-disable=sroapass %s 2>&1 \
13+
; RUN: -passes=sroa -opt-disable=sroa %s 2>&1 \
1414
; RUN: | FileCheck %s --check-prefix=CHECK-FUNCTION-PASS
15-
; CHECK-FUNCTION-PASS: DISABLE: NOT running pass SROAPass on f1
16-
; CHECK-FUNCTION-PASS: DISABLE: NOT running pass SROAPass on f2
17-
; CHECK-FUNCTION-PASS: DISABLE: NOT running pass SROAPass on f3
18-
; CHECK-FUNCTION-PASS: DISABLE: NOT running pass SROAPass on f4
15+
; CHECK-FUNCTION-PASS: OptDisable: NOT running pass sroa on f1
16+
; CHECK-FUNCTION-PASS: OptDisable: NOT running pass sroa on f2
17+
; CHECK-FUNCTION-PASS: OptDisable: NOT running pass sroa on f3
18+
; CHECK-FUNCTION-PASS: OptDisable: NOT running pass sroa on f4
1919

2020
; RUN: opt -disable-output -disable-verify \
21-
; RUN: -opt-disable=inferfunctionattrspass,PostOrderFunctionAttrsPass \
21+
; RUN: -opt-disable=inferattrs,function-attrs \
2222
; RUN: -opt-disable-enable-verbosity \
2323
; RUN: -passes='inferattrs,cgscc(function-attrs,function(early-cse))' %s 2>&1 \
2424
; RUN: | FileCheck %s --check-prefix=CHECK-MULTI-PASS
25-
; CHECK-MULTI-PASS: DISABLE: NOT running pass InferFunctionAttrsPass on [module]
26-
; CHECK-MULTI-PASS: DISABLE: NOT running pass PostOrderFunctionAttrsPass on (f1)
27-
; CHECK-MULTI-PASS: DISABLE: running pass EarlyCSEPass on f1
28-
; CHECK-MULTI-PASS: DISABLE: NOT running pass PostOrderFunctionAttrsPass on (f2)
29-
; CHECK-MULTI-PASS: DISABLE: running pass EarlyCSEPass on f2
30-
; CHECK-MULTI-PASS: DISABLE: NOT running pass PostOrderFunctionAttrsPass on (f3)
31-
; CHECK-MULTI-PASS: DISABLE: running pass EarlyCSEPass on f3
32-
; CHECK-MULTI-PASS: DISABLE: NOT running pass PostOrderFunctionAttrsPass on (f4)
33-
; CHECK-MULTI-PASS: DISABLE: running pass EarlyCSEPass on f4
25+
; CHECK-MULTI-PASS: OptDisable: NOT running pass inferattrs on [module]
26+
; CHECK-MULTI-PASS: OptDisable: NOT running pass function-attrs on (f1)
27+
; CHECK-MULTI-PASS: OptDisable: running pass early-cse on f1
28+
; CHECK-MULTI-PASS: OptDisable: NOT running pass function-attrs on (f2)
29+
; CHECK-MULTI-PASS: OptDisable: running pass early-cse on f2
30+
; CHECK-MULTI-PASS: OptDisable: NOT running pass function-attrs on (f3)
31+
; CHECK-MULTI-PASS: OptDisable: running pass early-cse on f3
32+
; CHECK-MULTI-PASS: OptDisable: NOT running pass function-attrs on (f4)
33+
; CHECK-MULTI-PASS: OptDisable: running pass early-cse on f4
3434

3535
declare i32 @g()
3636

0 commit comments

Comments
 (0)