@@ -47,8 +47,8 @@ using namespace llvm;
4747ExecutionState &DFSSearcher::selectState () { return *states.back (); }
4848
4949void DFSSearcher::update (ExecutionState *current,
50- const std::vector<ExecutionState *> &addedStates,
51- const std::vector<ExecutionState *> &removedStates) {
50+ const StateIterable &addedStates,
51+ const StateIterable &removedStates) {
5252 // insert states
5353 states.insert (states.end (), addedStates.begin (), addedStates.end ());
5454
@@ -73,8 +73,8 @@ void DFSSearcher::printName(llvm::raw_ostream &os) { os << "DFSSearcher\n"; }
7373ExecutionState &BFSSearcher::selectState () { return *states.front (); }
7474
7575void BFSSearcher::update (ExecutionState *current,
76- const std::vector<ExecutionState *> &addedStates,
77- const std::vector<ExecutionState *> &removedStates) {
76+ const StateIterable &addedStates,
77+ const StateIterable &removedStates) {
7878 // update current state
7979 // Assumption: If new states were added KLEE forked, therefore states evolved.
8080 // constraints were added to the current state, it evolved.
@@ -114,9 +114,9 @@ ExecutionState &RandomSearcher::selectState() {
114114 return *states[theRNG.getInt32 () % states.size ()];
115115}
116116
117- void RandomSearcher::update (
118- ExecutionState *current, const std::vector<ExecutionState *> &addedStates,
119- const std::vector<ExecutionState *> &removedStates) {
117+ void RandomSearcher::update (ExecutionState *current,
118+ const StateIterable &addedStates,
119+ const StateIterable &removedStates) {
120120 // insert states
121121 states.insert (states.end (), addedStates.begin (), addedStates.end ());
122122
@@ -167,9 +167,9 @@ TargetedSearcher::TargetedSearcher(ref<Target> target,
167167
168168ExecutionState &TargetedSearcher::selectState () { return *states->choose (0 ); }
169169
170- void TargetedSearcher::update (
171- ExecutionState *current, const std::vector<ExecutionState *> &addedStates,
172- const std::vector<ExecutionState *> &removedStates) {
170+ void TargetedSearcher::update (ExecutionState *current,
171+ const StateIterable &addedStates,
172+ const StateIterable &removedStates) {
173173
174174 // update current
175175 if (current && std::find (removedStates.begin (), removedStates.end (),
@@ -224,9 +224,9 @@ ExecutionState &GuidedSearcher::selectState() {
224224 return *state;
225225}
226226
227- void GuidedSearcher::update (
228- ExecutionState *current, const std::vector<ExecutionState *> &addedStates,
229- const std::vector<ExecutionState *> &removedStates) {
227+ void GuidedSearcher::update (ExecutionState *current,
228+ const StateIterable &addedStates,
229+ const StateIterable &removedStates) {
230230
231231 if (current) {
232232 ref<const TargetsHistory> history = current->history ();
@@ -421,9 +421,9 @@ double WeightedRandomSearcher::getWeight(ExecutionState *es) {
421421 }
422422}
423423
424- void WeightedRandomSearcher::update (
425- ExecutionState *current, const std::vector<ExecutionState *> &addedStates,
426- const std::vector<ExecutionState *> &removedStates) {
424+ void WeightedRandomSearcher::update (ExecutionState *current,
425+ const StateIterable &addedStates,
426+ const StateIterable &removedStates) {
427427
428428 // update current
429429 if (current && updateWeights &&
@@ -514,11 +514,11 @@ ExecutionState &RandomPathSearcher::selectState() {
514514 return *n->state ;
515515}
516516
517- void RandomPathSearcher::update (
518- ExecutionState *current, const std::vector<ExecutionState *> &addedStates,
519- const std::vector<ExecutionState *> &removedStates) {
517+ void RandomPathSearcher::update (ExecutionState *current,
518+ const StateIterable &addedStates,
519+ const StateIterable &removedStates) {
520520 // insert states
521- for (auto & es : addedStates) {
521+ for (auto es : addedStates) {
522522 PTreeNode *pnode = es->ptreeNode , *parent = pnode->parent ;
523523 PTreeNodePtr &root = processForest.getPTrees ().at (pnode->getTreeID ())->root ;
524524 PTreeNodePtr *childPtr;
@@ -618,9 +618,9 @@ ExecutionState &BatchingSearcher::selectState() {
618618 return *lastState;
619619}
620620
621- void BatchingSearcher::update (
622- ExecutionState *current, const std::vector<ExecutionState *> &addedStates,
623- const std::vector<ExecutionState *> &removedStates) {
621+ void BatchingSearcher::update (ExecutionState *current,
622+ const StateIterable &addedStates,
623+ const StateIterable &removedStates) {
624624 // drop memoized state if it is marked for deletion
625625 if (std::find (removedStates.begin (), removedStates.end (), lastState) !=
626626 removedStates.end ())
@@ -697,46 +697,30 @@ ExecutionState &IterativeDeepeningSearcher::selectState() {
697697 return res;
698698}
699699
700- void IterativeDeepeningSearcher::filter (const StatesVector &states,
701- StatesVector &result) const {
702- StatesVector states1 (states);
703- std::sort (states1.begin (), states1.end ());
704- std::set_difference (states1.begin (), states1.end (), pausedStates.begin (),
705- pausedStates.end (), std::back_inserter (result));
706- }
707-
708700void IterativeDeepeningSearcher::update (
709701 const TargetHistoryTargetPairToStatesMap &added,
710702 const TargetHistoryTargetPairToStatesMap &removed) {
711703 if (!tms)
712704 return ;
713- TargetHistoryTargetPairToStatesMap removedRefined (removed.size ());
714- for (const auto &pair : removed) {
715- StatesVector refined;
716- IterativeDeepeningSearcher::filter (pair.second , refined);
717- removedRefined.emplace (pair.first , std::move (refined));
718- }
719- tms->update (added, removedRefined);
705+ added.setWithout (&pausedStates);
706+ removed.setWithout (&pausedStates);
707+ tms->update (added, removed);
708+ added.clearWithout ();
709+ removed.clearWithout ();
720710}
721711
722712void IterativeDeepeningSearcher::update (ExecutionState *current,
723- const StatesVector &addedStates,
724- const StatesVector &removedStates) {
725-
726- // update underlying searcher (filter paused states unknown to underlying
727- // searcher)
728- if (!removedStates.empty ()) {
729- StatesVector alt;
730- IterativeDeepeningSearcher::filter (removedStates, alt);
731- baseSearcher->update (current, addedStates, alt);
732- } else {
733- baseSearcher->update (current, addedStates, removedStates);
734- }
713+ const StateIterable &added,
714+ const StateIterable &removed) {
715+ removed.setWithout (&pausedStates);
716+ baseSearcher->update (current, added, removed);
717+ removed.clearWithout ();
718+
719+ for (auto state : removed)
720+ pausedStates.erase (state);
735721
736- // update current: pause if time exceeded
737722 if (current &&
738- std::find (removedStates.begin (), removedStates.end (), current) ==
739- removedStates.end () &&
723+ std::find (removed.begin (), removed.end (), current) == removed.end () &&
740724 metric->exceeds (*current)) {
741725 pausedStates.insert (current);
742726 baseSearcher->update (nullptr , {}, {current});
@@ -745,8 +729,7 @@ void IterativeDeepeningSearcher::update(ExecutionState *current,
745729 // no states left in underlying searcher: fill with paused states
746730 if (baseSearcher->empty ()) {
747731 metric->increaseLimit ();
748- StatesVector ps (pausedStates.begin (), pausedStates.end ());
749- baseSearcher->update (nullptr , ps, {});
732+ baseSearcher->update (nullptr , pausedStates, {});
750733 pausedStates.clear ();
751734 }
752735}
@@ -775,9 +758,9 @@ ExecutionState &InterleavedSearcher::selectState() {
775758 return s->selectState ();
776759}
777760
778- void InterleavedSearcher::update (
779- ExecutionState *current, const std::vector<ExecutionState *> &addedStates,
780- const std::vector<ExecutionState *> &removedStates) {
761+ void InterleavedSearcher::update (ExecutionState *current,
762+ const StateIterable &addedStates,
763+ const StateIterable &removedStates) {
781764
782765 // update underlying searchers
783766 for (auto &searcher : searchers)
0 commit comments