summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/docs/MIRLangRef.rst5
-rw-r--r--llvm/include/llvm/CodeGen/TargetPassConfig.h13
-rw-r--r--llvm/lib/CodeGen/TargetPassConfig.cpp46
-rw-r--r--llvm/test/CodeGen/Generic/llc-start-stop-instance-errors.ll4
-rw-r--r--llvm/test/CodeGen/Generic/llc-start-stop-instance.ll50
5 files changed, 110 insertions, 8 deletions
diff --git a/llvm/docs/MIRLangRef.rst b/llvm/docs/MIRLangRef.rst
index 9a7e18c091c..ca6c0107fa6 100644
--- a/llvm/docs/MIRLangRef.rst
+++ b/llvm/docs/MIRLangRef.rst
@@ -60,6 +60,11 @@ runs just before the pass that we are trying to test:
``llc -stop-after=machine-cp bug-trigger.ll > test.mir``
+If the same pass is run multiple times, a run index can be included
+after the name with a comma.
+
+ ``llc -stop-after=dead-mi-elimination,1 bug-trigger.ll > test.mir``
+
After generating the input MIR file, you'll have to add a run line that uses
the ``-run-pass`` option to it. In order to test the post register allocation
pseudo instruction expansion pass on X86-64, a run line like the one shown
diff --git a/llvm/include/llvm/CodeGen/TargetPassConfig.h b/llvm/include/llvm/CodeGen/TargetPassConfig.h
index 7fda8751d40..3288711a335 100644
--- a/llvm/include/llvm/CodeGen/TargetPassConfig.h
+++ b/llvm/include/llvm/CodeGen/TargetPassConfig.h
@@ -90,6 +90,19 @@ private:
AnalysisID StartAfter = nullptr;
AnalysisID StopBefore = nullptr;
AnalysisID StopAfter = nullptr;
+
+ unsigned StartBeforeInstanceNum = 0;
+ unsigned StartBeforeCount = 0;
+
+ unsigned StartAfterInstanceNum = 0;
+ unsigned StartAfterCount = 0;
+
+ unsigned StopBeforeInstanceNum = 0;
+ unsigned StopBeforeCount = 0;
+
+ unsigned StopAfterInstanceNum = 0;
+ unsigned StopAfterCount = 0;
+
bool Started = true;
bool Stopped = false;
bool AddingMachinePasses = false;
diff --git a/llvm/lib/CodeGen/TargetPassConfig.cpp b/llvm/lib/CodeGen/TargetPassConfig.cpp
index 4d767c2f0f8..defb165fe0f 100644
--- a/llvm/lib/CodeGen/TargetPassConfig.cpp
+++ b/llvm/lib/CodeGen/TargetPassConfig.cpp
@@ -345,11 +345,39 @@ static AnalysisID getPassIDFromName(StringRef PassName) {
return PI ? PI->getTypeInfo() : nullptr;
}
+static std::pair<StringRef, unsigned>
+getPassNameAndInstanceNum(StringRef PassName) {
+ StringRef Name, InstanceNumStr;
+ std::tie(Name, InstanceNumStr) = PassName.split(',');
+
+ unsigned InstanceNum = 0;
+ if (!InstanceNumStr.empty() && InstanceNumStr.getAsInteger(10, InstanceNum))
+ report_fatal_error("invalid pass instance specifier " + PassName);
+
+ return std::make_pair(Name, InstanceNum);
+}
+
void TargetPassConfig::setStartStopPasses() {
- StartBefore = getPassIDFromName(StartBeforeOpt);
- StartAfter = getPassIDFromName(StartAfterOpt);
- StopBefore = getPassIDFromName(StopBeforeOpt);
- StopAfter = getPassIDFromName(StopAfterOpt);
+ StringRef StartBeforeName;
+ std::tie(StartBeforeName, StartBeforeInstanceNum) =
+ getPassNameAndInstanceNum(StartBeforeOpt);
+
+ StringRef StartAfterName;
+ std::tie(StartAfterName, StartAfterInstanceNum) =
+ getPassNameAndInstanceNum(StartAfterOpt);
+
+ StringRef StopBeforeName;
+ std::tie(StopBeforeName, StopBeforeInstanceNum)
+ = getPassNameAndInstanceNum(StopBeforeOpt);
+
+ StringRef StopAfterName;
+ std::tie(StopAfterName, StopAfterInstanceNum)
+ = getPassNameAndInstanceNum(StopAfterOpt);
+
+ StartBefore = getPassIDFromName(StartBeforeName);
+ StartAfter = getPassIDFromName(StartAfterName);
+ StopBefore = getPassIDFromName(StopBeforeName);
+ StopAfter = getPassIDFromName(StopAfterName);
if (StartBefore && StartAfter)
report_fatal_error(Twine(StartBeforeOptName) + Twine(" and ") +
Twine(StartAfterOptName) + Twine(" specified!"));
@@ -493,9 +521,9 @@ void TargetPassConfig::addPass(Pass *P, bool verifyAfter, bool printAfter) {
// and shouldn't reference it.
AnalysisID PassID = P->getPassID();
- if (StartBefore == PassID)
+ if (StartBefore == PassID && StartBeforeCount++ == StartBeforeInstanceNum)
Started = true;
- if (StopBefore == PassID)
+ if (StopBefore == PassID && StopBeforeCount++ == StopBeforeInstanceNum)
Stopped = true;
if (Started && !Stopped) {
std::string Banner;
@@ -518,9 +546,11 @@ void TargetPassConfig::addPass(Pass *P, bool verifyAfter, bool printAfter) {
} else {
delete P;
}
- if (StopAfter == PassID)
+
+ if (StopAfter == PassID && StopAfterCount++ == StopAfterInstanceNum)
Stopped = true;
- if (StartAfter == PassID)
+
+ if (StartAfter == PassID && StartAfterCount++ == StartAfterInstanceNum)
Started = true;
if (Stopped && !Started)
report_fatal_error("Cannot stop compilation after pass that is not run");
diff --git a/llvm/test/CodeGen/Generic/llc-start-stop-instance-errors.ll b/llvm/test/CodeGen/Generic/llc-start-stop-instance-errors.ll
new file mode 100644
index 00000000000..cb1b30f3a81
--- /dev/null
+++ b/llvm/test/CodeGen/Generic/llc-start-stop-instance-errors.ll
@@ -0,0 +1,4 @@
+; RUN: not llc -debug-pass=Structure -stop-after=dead-mi-elimination,arst %s -o /dev/null 2>&1 \
+; RUN: | FileCheck -check-prefix=NOT-NUM %s
+
+; NOT-NUM: LLVM ERROR: invalid pass instance specifier dead-mi-elimination,arst
diff --git a/llvm/test/CodeGen/Generic/llc-start-stop-instance.ll b/llvm/test/CodeGen/Generic/llc-start-stop-instance.ll
new file mode 100644
index 00000000000..bf88a2c3793
--- /dev/null
+++ b/llvm/test/CodeGen/Generic/llc-start-stop-instance.ll
@@ -0,0 +1,50 @@
+; RUN: llc -debug-pass=Structure -stop-after=dead-mi-elimination,1 %s -o /dev/null 2>&1 \
+; RUN: | FileCheck -check-prefix=STOP-AFTER-DEAD1 %s
+
+; RUN: llc -debug-pass=Structure -stop-after=dead-mi-elimination,0 %s -o /dev/null 2>&1 \
+; RUN: | FileCheck -check-prefix=STOP-AFTER-DEAD0 %s
+
+
+; RUN: llc -debug-pass=Structure -stop-before=dead-mi-elimination,1 %s -o /dev/null 2>&1 \
+; RUN: | FileCheck -check-prefix=STOP-BEFORE-DEAD1 %s
+
+
+; RUN: llc -debug-pass=Structure -start-before=dead-mi-elimination,1 %s -o /dev/null 2>&1 \
+; RUN: | FileCheck -check-prefix=START-BEFORE-DEAD1 %s
+
+; RUN: llc -debug-pass=Structure -start-after=dead-mi-elimination,1 %s -o /dev/null 2>&1 \
+; RUN: | FileCheck -check-prefix=START-AFTER-DEAD1 %s
+
+
+
+; STOP-AFTER-DEAD1: -dead-mi-elimination
+; STOP-AFTER-DEAD1-SAME: -dead-mi-elimination
+
+; STOP-AFTER-DEAD1: Remove dead machine instructions
+; STOP-AFTER-DEAD1: Remove dead machine instructions
+
+
+
+; STOP-AFTER-DEAD0: -dead-mi-elimination
+
+; STOP-AFTER-DEAD0-NOT: Remove dead machine instructions
+; STOP-AFTER-DEAD0: Remove dead machine instructions
+; STOP-AFTER-DEAD0-NOT: Remove dead machine instructions
+
+
+
+; STOP-BEFORE-DEAD1: -dead-mi-elimination
+; STOP-BEFORE-DEAD1: Remove dead machine instructions
+; STOP-BEFORE-DEAD1-NOT: Remove dead machine instructions
+
+
+
+; START-BEFORE-DEAD1: -dead-mi-elimination
+; START-BEFORE-DEAD1-NOT: Remove dead machine instructions
+; START-BEFORE-DEAD1: Remove dead machine instructions
+; START-BEFORE-DEAD1-NOT: Remove dead machine instructions
+
+
+
+; START-AFTER-DEAD1-NOT: -dead-mi-elimination
+; START-AFTER-DEAD1-NOT: Remove dead machine instructions
OpenPOWER on IntegriCloud