From 15799911c7e0c964c7d3ec6bda62626ed6d851a5 Mon Sep 17 00:00:00 2001 From: Frank Busse Date: Wed, 7 Oct 2020 19:32:39 +0100 Subject: searchers: move implementations from .h to .cpp --- lib/Core/Searcher.cpp | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) (limited to 'lib/Core/Searcher.cpp') diff --git a/lib/Core/Searcher.cpp b/lib/Core/Searcher.cpp index f8fd2aea..0dffcf2c 100644 --- a/lib/Core/Searcher.cpp +++ b/lib/Core/Searcher.cpp @@ -70,6 +70,15 @@ void DFSSearcher::update(ExecutionState *current, } } +bool DFSSearcher::empty() { + return states.empty(); +} + +void DFSSearcher::printName(llvm::raw_ostream &os) { + os << "DFSSearcher\n"; +} + + /// ExecutionState &BFSSearcher::selectState() { @@ -115,8 +124,19 @@ void BFSSearcher::update(ExecutionState *current, } } +bool BFSSearcher::empty() { + return states.empty(); +} + +void BFSSearcher::printName(llvm::raw_ostream &os) { + os << "BFSSearcher\n"; +} + + /// +RandomSearcher::RandomSearcher(RNG &rng) : theRNG{rng} {} + ExecutionState &RandomSearcher::selectState() { return *states[theRNG.getInt32() % states.size()]; } @@ -144,6 +164,15 @@ void RandomSearcher::update(ExecutionState *current, } } +bool RandomSearcher::empty() { + return states.empty(); +} + +void RandomSearcher::printName(llvm::raw_ostream &os) { + os << "RandomSearcher\n"; +} + + /// WeightedRandomSearcher::WeightedRandomSearcher(WeightType type, RNG &rng) @@ -236,12 +265,32 @@ bool WeightedRandomSearcher::empty() { return states->empty(); } +void WeightedRandomSearcher::printName(llvm::raw_ostream &os) { + os << "WeightedRandomSearcher::"; + switch(type) { + case Depth : os << "Depth\n"; return; + case RP : os << "RandomPath\n"; return; + case QueryCost : os << "QueryCost\n"; return; + case InstCount : os << "InstCount\n"; return; + case CPInstCount : os << "CPInstCount\n"; return; + case MinDistToUncovered : os << "MinDistToUncovered\n"; return; + case CoveringNew : os << "CoveringNew\n"; return; + default : os << "\n"; return; + } +} + + /// // Check if n is a valid pointer and a node belonging to us #define IS_OUR_NODE_VALID(n) \ (((n).getPointer() != nullptr) && (((n).getInt() & idBitMask) != 0)) +RandomPathSearcher::RandomPathSearcher(PTree &processTree, RNG &rng) + : processTree{processTree}, + theRNG{rng}, + idBitMask{processTree.getNextId()} {}; + ExecutionState &RandomPathSearcher::selectState() { unsigned flips=0, bits=0; assert(processTree.root.getInt() & idBitMask && @@ -317,8 +366,29 @@ bool RandomPathSearcher::empty() { return !IS_OUR_NODE_VALID(processTree.root); } +void RandomPathSearcher::printName(llvm::raw_ostream &os) { + os << "RandomPathSearcher\n"; +} + + /// +MergingSearcher::MergingSearcher(Searcher *baseSearcher) + : baseSearcher{baseSearcher} {}; + +void MergingSearcher::pauseState(ExecutionState &state) { + assert(std::find(pausedStates.begin(), pausedStates.end(), &state) == pausedStates.end()); + pausedStates.push_back(&state); + baseSearcher->update(nullptr, {}, {&state}); +} + +void MergingSearcher::continueState(ExecutionState &state) { + auto it = std::find(pausedStates.begin(), pausedStates.end(), &state); + assert(it != pausedStates.end()); + pausedStates.erase(it); + baseSearcher->update(nullptr, {&state}, {}); +} + ExecutionState& MergingSearcher::selectState() { assert(!baseSearcher->empty() && "base searcher is empty"); @@ -348,8 +418,32 @@ ExecutionState& MergingSearcher::selectState() { return baseSearcher->selectState(); } +void MergingSearcher::update(ExecutionState *current, + const std::vector &addedStates, + const std::vector &removedStates) { + // We have to check if the current execution state was just deleted, as to + // not confuse the nurs searchers + if (std::find(pausedStates.begin(), pausedStates.end(), current) == pausedStates.end()) { + baseSearcher->update(current, addedStates, removedStates); + } +} + +bool MergingSearcher::empty() { + return baseSearcher->empty(); +} + +void MergingSearcher::printName(llvm::raw_ostream &os) { + os << "MergingSearcher\n"; +} + + /// +BatchingSearcher::BatchingSearcher(Searcher *baseSearcher, time::Span timeBudget, unsigned instructionBudget) + : baseSearcher{baseSearcher}, + timeBudget{timeBudget}, + instructionBudget{instructionBudget} {}; + ExecutionState &BatchingSearcher::selectState() { if (!lastState || (((timeBudget.toSeconds() > 0) && @@ -385,8 +479,24 @@ void BatchingSearcher::update(ExecutionState *current, baseSearcher->update(current, addedStates, removedStates); } +bool BatchingSearcher::empty() { + return baseSearcher->empty(); +} + +void BatchingSearcher::printName(llvm::raw_ostream &os) { + os << " timeBudget: " << timeBudget + << ", instructionBudget: " << instructionBudget + << ", baseSearcher:\n"; + baseSearcher->printName(os); + os << "\n"; +} + + /// +IterativeDeepeningTimeSearcher::IterativeDeepeningTimeSearcher(Searcher *baseSearcher) + : baseSearcher{baseSearcher} {}; + ExecutionState &IterativeDeepeningTimeSearcher::selectState() { ExecutionState &res = baseSearcher->selectState(); startTime = time::getWallTime(); @@ -433,6 +543,15 @@ void IterativeDeepeningTimeSearcher::update( } } +bool IterativeDeepeningTimeSearcher::empty() { + return baseSearcher->empty() && pausedStates.empty(); +} + +void IterativeDeepeningTimeSearcher::printName(llvm::raw_ostream &os) { + os << "IterativeDeepeningTimeSearcher\n"; +} + + /// InterleavedSearcher::InterleavedSearcher(const std::vector &_searchers) { @@ -455,3 +574,14 @@ void InterleavedSearcher::update( for (auto &searcher : searchers) searcher->update(current, addedStates, removedStates); } + +bool InterleavedSearcher::empty() { + return searchers[0]->empty(); +} + +void InterleavedSearcher::printName(llvm::raw_ostream &os) { + os << " containing " << searchers.size() << " searchers:\n"; + for (const auto &searcher : searchers) + searcher->printName(os); + os << "\n"; +} -- cgit 1.4.1