[llvm] c3bc72c - llvm-reduce: Improve delta pass flag handling

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 12 17:25:34 PDT 2022


Author: Matt Arsenault
Date: 2022-10-12T17:25:23-07:00
New Revision: c3bc72ccb23eb13aa6efba81adf68a0518eebc52

URL: https://github.com/llvm/llvm-project/commit/c3bc72ccb23eb13aa6efba81adf68a0518eebc52
DIFF: https://github.com/llvm/llvm-project/commit/c3bc72ccb23eb13aa6efba81adf68a0518eebc52.diff

LOG: llvm-reduce: Improve delta pass flag handling

Verify all the requested passes exist before trying to run any.
For long reductions, it was really annoying for it to get halfway through
and then I come back later to an incomplete reduction.

Also add a new skip-delta-passes flag. Most of the time I want to opt out
of specific reductions, rather than run a select few.

Added: 
    llvm/test/tools/llvm-reduce/skip-delta-passes.ll

Modified: 
    llvm/tools/llvm-reduce/DeltaManager.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-reduce/skip-delta-passes.ll b/llvm/test/tools/llvm-reduce/skip-delta-passes.ll
new file mode 100644
index 0000000000000..b1f9cfc9a2bfa
--- /dev/null
+++ b/llvm/test/tools/llvm-reduce/skip-delta-passes.ll
@@ -0,0 +1,22 @@
+; RUN: llvm-reduce --delta-passes=attributes --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
+; RUN: FileCheck -check-prefix=RESULT %s < %t
+
+; RUN: llvm-reduce --delta-passes=instructions,attributes --skip-delta-passes=instructions --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
+; RUN: FileCheck -check-prefix=RESULT %s < %t
+
+; RUN: not llvm-reduce --skip-delta-passes=foo --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t 2>&1 | FileCheck %s --check-prefix=ERROR
+
+
+; CHECK-INTERESTINGNESS: @foo
+; RESULT: define void @foo() {
+; RESULT-NEXT: store i32
+; RESULT-NEXT: ret void
+; RESULT0-NOT: attributes
+
+; ERROR: unknown pass "foo"
+define void @foo() #0 {
+  store i32 0, ptr null
+  ret void
+}
+
+attributes #0 = { "arstarstarst" }

diff  --git a/llvm/tools/llvm-reduce/DeltaManager.cpp b/llvm/tools/llvm-reduce/DeltaManager.cpp
index 9d7b4342429cb..2bd9b2850f680 100644
--- a/llvm/tools/llvm-reduce/DeltaManager.cpp
+++ b/llvm/tools/llvm-reduce/DeltaManager.cpp
@@ -48,12 +48,20 @@
 
 using namespace llvm;
 
+using SmallStringSet = SmallSet<StringRef, 8>;
+
 extern cl::OptionCategory LLVMReduceOptions;
-static cl::opt<std::string>
+static cl::list<std::string>
     DeltaPasses("delta-passes",
                 cl::desc("Delta passes to run, separated by commas. By "
                          "default, run all delta passes."),
-                cl::cat(LLVMReduceOptions));
+                cl::cat(LLVMReduceOptions), cl::CommaSeparated);
+
+static cl::list<std::string>
+    SkipDeltaPasses("skip-delta-passes",
+                    cl::desc("Delta passes to not run, separated by commas. By "
+                             "default, run all delta passes."),
+                    cl::cat(LLVMReduceOptions), cl::CommaSeparated);
 
 #define DELTA_PASSES                                                           \
   do {                                                                         \
@@ -97,8 +105,12 @@ static cl::opt<std::string>
     DELTA_PASS("register-masks", reduceRegisterMasksMIRDeltaPass)              \
   } while (false)
 
-static void runAllDeltaPasses(TestRunner &Tester) {
-#define DELTA_PASS(NAME, FUNC) FUNC(Tester);
+static void runAllDeltaPasses(TestRunner &Tester,
+                              const SmallStringSet &SkipPass) {
+#define DELTA_PASS(NAME, FUNC)                                                 \
+  if (!SkipPass.count(NAME)) {                                                 \
+    FUNC(Tester);                                                              \
+  }
   if (Tester.getProgram().isMIR()) {
     DELTA_PASSES_MIR;
   } else {
@@ -119,8 +131,10 @@ static void runDeltaPassName(TestRunner &Tester, StringRef PassName) {
     DELTA_PASSES;
   }
 #undef DELTA_PASS
-  errs() << "unknown pass \"" << PassName << "\"\n";
-  exit(1);
+
+  // We should have errored on unrecognized passes before trying to run
+  // anything.
+  llvm_unreachable("unknown delta pass");
 }
 
 void llvm::printDeltaPasses(raw_ostream &OS) {
@@ -133,19 +147,59 @@ void llvm::printDeltaPasses(raw_ostream &OS) {
 #undef DELTA_PASS
 }
 
+// Built a set of available delta passes.
+static void collectPassNames(const TestRunner &Tester,
+                             SmallStringSet &NameSet) {
+#define DELTA_PASS(NAME, FUNC) NameSet.insert(NAME);
+  if (Tester.getProgram().isMIR()) {
+    DELTA_PASSES_MIR;
+  } else {
+    DELTA_PASSES;
+  }
+#undef DELTA_PASS
+}
+
+/// Verify all requested or skipped passes are valid names, and return them in a
+/// set.
+static SmallStringSet handlePassList(const TestRunner &Tester,
+                                     const cl::list<std::string> &PassList) {
+  SmallStringSet AllPasses;
+  collectPassNames(Tester, AllPasses);
+
+  SmallStringSet PassSet;
+  for (StringRef PassName : PassList) {
+    if (!AllPasses.count(PassName)) {
+      errs() << "unknown pass \"" << PassName << "\"\n";
+      exit(1);
+    }
+
+    PassSet.insert(PassName);
+  }
+
+  return PassSet;
+}
+
 void llvm::runDeltaPasses(TestRunner &Tester, int MaxPassIterations) {
   uint64_t OldComplexity = Tester.getProgram().getComplexityScore();
+
+  SmallStringSet RunPassSet, SkipPassSet;
+
+  if (!DeltaPasses.empty())
+    RunPassSet = handlePassList(Tester, DeltaPasses);
+
+  if (!SkipDeltaPasses.empty())
+    SkipPassSet = handlePassList(Tester, SkipDeltaPasses);
+
   for (int Iter = 0; Iter < MaxPassIterations; ++Iter) {
     if (DeltaPasses.empty()) {
-      runAllDeltaPasses(Tester);
+      runAllDeltaPasses(Tester, SkipPassSet);
     } else {
-      StringRef Passes = DeltaPasses;
-      while (!Passes.empty()) {
-        auto Split = Passes.split(",");
-        runDeltaPassName(Tester, Split.first);
-        Passes = Split.second;
+      for (StringRef PassName : DeltaPasses) {
+        if (!SkipPassSet.count(PassName))
+          runDeltaPassName(Tester, PassName);
       }
     }
+
     uint64_t NewComplexity = Tester.getProgram().getComplexityScore();
     if (NewComplexity >= OldComplexity)
       break;


        


More information about the llvm-commits mailing list