// 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;
+ virtual TestResult doTest(std::vector<ElTy> &Prefix,
+ 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) {
+ bool reduceList(std::vector<ElTy> &TheList) {
+ std::vector<ElTy> empty;
+ switch (doTest(TheList, empty)) {
+ case KeepPrefix:
+ if (TheList.size() == 1) // we are done, it's the base case and it fails
+ return true;
+ else
+ break; // there's definitely an error, but we need to narrow it down
+
+ case KeepSuffix:
+ // cannot be reached!
+ std::cerr << "bugpoint ListReducer internal error: selected empty set.\n";
+ abort();
+
+ case NoFailure:
+ return false; // there is no failure with the full set of passes/funcs!
+ }
+
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);
+ std::vector<ElTy> Prefix(TheList.begin(), TheList.begin()+Mid);
+ std::vector<ElTy> Suffix(TheList.begin()+Mid, TheList.end());
- switch (doTest(Prefix, Kept)) {
+ switch (doTest(Prefix, Suffix)) {
case KeepSuffix:
// The property still holds. We can just drop the prefix elements, and
// shorten the list to the "kept" elements.
- TheList.swap(Kept);
+ TheList.swap(Suffix);
MidTop = TheList.size();
break;
case KeepPrefix:
break;
case NoFailure:
// Otherwise the property doesn't hold. Some of the elements we removed
- // must be neccesary to maintain the property.
+ // must be necessary to maintain the property.
MidTop = Mid;
break;
}
}
}
}
+
+ return true; // there are some failure and we've narrowed them down
}
};