[PATCH] D116871: [llvm-reduce] optionally keep running delta passes until they stop making the IR smaller
John Regehr via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 10 18:37:55 PST 2022
regehr updated this revision to Diff 398805.
regehr added a comment.
add FIXME suggested by @aeubanks
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D116871/new/
https://reviews.llvm.org/D116871
Files:
llvm/tools/llvm-reduce/DeltaManager.cpp
llvm/tools/llvm-reduce/DeltaManager.h
llvm/tools/llvm-reduce/llvm-reduce.cpp
Index: llvm/tools/llvm-reduce/llvm-reduce.cpp
===================================================================
--- llvm/tools/llvm-reduce/llvm-reduce.cpp
+++ llvm/tools/llvm-reduce/llvm-reduce.cpp
@@ -88,6 +88,12 @@
cl::desc("Set the target triple"),
cl::cat(Options));
+static cl::opt<int>
+ MaxPassIterations("max-pass-iterations",
+ cl::desc("Maximum number of times to run the full set "
+ "of delta passes (default=1)"),
+ cl::init(1), cl::cat(Options));
+
static codegen::RegisterCodeGenFlags CGF;
void writeOutput(ReducerWorkItem &M, StringRef Message) {
@@ -161,7 +167,7 @@
TestRunner Tester(TestFilename, TestArguments, std::move(OriginalProgram));
// Try to reduce code
- runDeltaPasses(Tester);
+ runDeltaPasses(Tester, MaxPassIterations);
// Print reduced file to STDOUT
if (OutputFilename == "-")
Index: llvm/tools/llvm-reduce/DeltaManager.h
===================================================================
--- llvm/tools/llvm-reduce/DeltaManager.h
+++ llvm/tools/llvm-reduce/DeltaManager.h
@@ -19,7 +19,7 @@
class TestRunner;
void printDeltaPasses(raw_ostream &OS);
-void runDeltaPasses(TestRunner &Tester);
+void runDeltaPasses(TestRunner &Tester, int MaxPassIterations);
} // namespace llvm
#endif
Index: llvm/tools/llvm-reduce/DeltaManager.cpp
===================================================================
--- llvm/tools/llvm-reduce/DeltaManager.cpp
+++ llvm/tools/llvm-reduce/DeltaManager.cpp
@@ -103,15 +103,32 @@
#undef DELTA_PASS
}
-void llvm::runDeltaPasses(TestRunner &Tester) {
- if (DeltaPasses.empty()) {
- runAllDeltaPasses(Tester);
- } else {
- StringRef Passes = DeltaPasses;
- while (!Passes.empty()) {
- auto Split = Passes.split(",");
- runDeltaPassName(Tester, Split.first);
- Passes = Split.second;
+// FIXME: We might want to use a different metric than "number of
+// bytes in serialized IR" to detect non-progress of the main delta
+// loop
+static int getIRSize(TestRunner &Tester) {
+ std::string Str;
+ raw_string_ostream SS(Str);
+ Tester.getProgram().print(SS, /*AnnotationWriter=*/nullptr);
+ return Str.length();
+}
+
+void llvm::runDeltaPasses(TestRunner &Tester, int MaxPassIterations) {
+ int OldSize = getIRSize(Tester);
+ for (int Iter = 0; Iter < MaxPassIterations; ++Iter) {
+ if (DeltaPasses.empty()) {
+ runAllDeltaPasses(Tester);
+ } else {
+ StringRef Passes = DeltaPasses;
+ while (!Passes.empty()) {
+ auto Split = Passes.split(",");
+ runDeltaPassName(Tester, Split.first);
+ Passes = Split.second;
+ }
}
+ int NewSize = getIRSize(Tester);
+ if (NewSize >= OldSize)
+ break;
+ OldSize = NewSize;
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116871.398805.patch
Type: text/x-patch
Size: 2867 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220111/920ffd15/attachment.bin>
More information about the llvm-commits
mailing list