Move the ListReducer Class into it's own header file instead of living in Miscompilat...
authorChris Lattner <sabre@nondot.org>
Thu, 24 Apr 2003 20:16:29 +0000 (20:16 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 24 Apr 2003 20:16:29 +0000 (20:16 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5907 91177308-0d34-0410-b5e6-96231b3b80d8

tools/bugpoint/ListReducer.h [new file with mode: 0644]
tools/bugpoint/Miscompilation.cpp

diff --git a/tools/bugpoint/ListReducer.h b/tools/bugpoint/ListReducer.h
new file mode 100644 (file)
index 0000000..1751c77
--- /dev/null
@@ -0,0 +1,86 @@
+//===- ListReducer.h - Trim down list while retaining property --*- C++ -*-===//
+//
+// This class is to be used as a base class for operations that want to zero in
+// on a subset of the input which still causes the bug we are tracking.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef BUGPOINT_LIST_REDUCER_H
+#define BUGPOINT_LIST_REDUCER_H
+
+#include <vector>
+
+template<typename ElTy>
+struct ListReducer {
+  enum TestResult {
+    NoFailure,         // No failure of the predicate was detected
+    KeepSuffix,        // The suffix alone satisfies the predicate
+    KeepPrefix,        // The prefix alone satisfies the predicate
+  };
+
+  // doTest - This virtual function should be overriden by subclasses to
+  // implement the test desired.  The testcase is only required to test to see
+  // if the Kept list still satisfies the property, but if it is going to check
+  // the prefix anyway, it can.
+  //
+  virtual TestResult doTest(const std::vector<ElTy> &Prefix,
+                            const std::vector<ElTy> &Kept) = 0;
+
+  // reduceList - This function attempts to reduce the length of the specified
+  // list while still maintaining the "test" property.  This is the core of the
+  // "work" that bugpoint does.
+  //
+  void reduceList(std::vector<ElTy> &TheList) {
+    unsigned MidTop = TheList.size();
+    while (MidTop > 1) {
+      unsigned Mid = MidTop / 2;
+      std::vector<ElTy> Prefix(TheList.begin()+Mid, TheList.end());
+      std::vector<ElTy> Kept  (TheList.begin(), TheList.begin()+Mid);
+
+      switch (doTest(Prefix, Kept)) {
+      case KeepSuffix:
+        // The property still holds.  We can just drop the prefix elements, and
+        // shorten the list to the "kept" elements.
+        TheList.swap(Kept);
+        MidTop = TheList.size();
+        break;
+      case KeepPrefix:
+        // The predicate still holds, shorten the list to the prefix elements.
+        TheList.swap(Prefix);
+        MidTop = TheList.size();
+        break;
+      case NoFailure:
+        // Otherwise the property doesn't hold.  Some of the elements we removed
+        // must be neccesary to maintain the property.
+        MidTop = Mid;
+        break;
+      }
+    }
+
+    // Okay, we trimmed as much off the top and the bottom of the list as we
+    // could.  If there is more two elements in the list, try deleting interior
+    // elements and testing that.
+    //
+    if (TheList.size() > 2) {
+      bool Changed = true;
+      std::vector<ElTy> EmptyList;
+      while (Changed) {
+        Changed = false;
+        std::vector<ElTy> TrimmedList;
+        for (unsigned i = 1; i < TheList.size()-1; ++i) { // Check interior elts
+          std::vector<ElTy> TestList(TheList);
+          TestList.erase(TestList.begin()+i);
+
+          if (doTest(EmptyList, TestList) == KeepSuffix) {
+            // We can trim down the list!
+            TheList.swap(TestList);
+            --i;  // Don't skip an element of the list
+            Changed = true;
+          }
+        }
+      }
+    }
+  }
+};
+
+#endif
index 4960b8205de5cde957858d47a8d9f9448cf5b1e2..89854f52c3feac705b16a2dbd392455c3677d698 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "BugDriver.h"
 #include "SystemUtils.h"
+#include "ListReducer.h"
 #include "llvm/Pass.h"
 #include "llvm/Module.h"
 #include "llvm/Transforms/Utils/Cloning.h"
@@ -26,79 +27,6 @@ namespace {
                            "(for miscompilation detection)"));
 }
 
-template<typename ElTy>
-struct ListReducer {
-  enum TestResult {
-    NoFailure,         // No failure of the predicate was detected
-    KeepSuffix,        // The suffix alone satisfies the predicate
-    KeepPrefix,        // The prefix alone satisfies the predicate
-  };
-
-  // doTest - This virtual function should be overriden by subclasses to
-  // implement the test desired.  The testcase is only required to test to see
-  // if the Kept list still satisfies the property, but if it is going to check
-  // the prefix anyway, it can.
-  //
-  virtual TestResult doTest(const std::vector<ElTy> &Prefix,
-                            const std::vector<ElTy> &Kept) = 0;
-
-  // reduceList - This function attempts to reduce the length of the specified
-  // list while still maintaining the "test" property.  This is the core of the
-  // "work" that bugpoint does.
-  //
-  void reduceList(std::vector<ElTy> &TheList) {
-    unsigned MidTop = TheList.size();
-    while (MidTop > 1) {
-      unsigned Mid = MidTop / 2;
-      std::vector<ElTy> Prefix(TheList.begin()+Mid, TheList.end());
-      std::vector<ElTy> Kept  (TheList.begin(), TheList.begin()+Mid);
-
-      switch (doTest(Prefix, Kept)) {
-      case KeepSuffix:
-        // The property still holds.  We can just drop the prefix elements, and
-        // shorten the list to the "kept" elements.
-        TheList.swap(Kept);
-        MidTop = TheList.size();
-        break;
-      case KeepPrefix:
-        // The predicate still holds, shorten the list to the prefix elements.
-        TheList.swap(Prefix);
-        MidTop = TheList.size();
-        break;
-      case NoFailure:
-        // Otherwise the property doesn't hold.  Some of the elements we removed
-        // must be neccesary to maintain the property.
-        MidTop = Mid;
-        break;
-      }
-    }
-
-    // Okay, we trimmed as much off the top and the bottom of the list as we
-    // could.  If there is more two elements in the list, try deleting interior
-    // elements and testing that.
-    //
-    if (TheList.size() > 2) {
-      bool Changed = true;
-      std::vector<ElTy> EmptyList;
-      while (Changed) {
-        Changed = false;
-        std::vector<ElTy> TrimmedList;
-        for (unsigned i = 1; i < TheList.size()-1; ++i) { // Check interior elts
-          std::vector<ElTy> TestList(TheList);
-          TestList.erase(TestList.begin()+i);
-
-          if (doTest(EmptyList, TestList) == KeepSuffix) {
-            // We can trim down the list!
-            TheList.swap(TestList);
-            --i;  // Don't skip an element of the list
-            Changed = true;
-          }
-        }
-      }
-    }
-  }
-};
-
 class ReduceMiscompilingPasses : public ListReducer<const PassInfo*> {
   BugDriver &BD;
 public: