diff options
author | Martin Nowack <m.nowack@imperial.ac.uk> | 2018-08-07 17:03:22 +0100 |
---|---|---|
committer | Cristian Cadar <c.cadar@imperial.ac.uk> | 2019-03-19 15:37:46 +0000 |
commit | d5ce6b3b2c62badebc7534550f09f1b5592a7aa3 (patch) | |
tree | b8733065d645291db4ee0728b834c8dfc48fd42e /lib/Core/CallPathManager.cpp | |
parent | 488e65f76e49e28e3db1a845276bf3dac49a2dc1 (diff) | |
download | klee-d5ce6b3b2c62badebc7534550f09f1b5592a7aa3.tar.gz |
Refactor InstructionInfoTable
Better debug information
Diffstat (limited to 'lib/Core/CallPathManager.cpp')
-rw-r--r-- | lib/Core/CallPathManager.cpp | 62 |
1 files changed, 24 insertions, 38 deletions
diff --git a/lib/Core/CallPathManager.cpp b/lib/Core/CallPathManager.cpp index 42be3735..6d5ef1a8 100644 --- a/lib/Core/CallPathManager.cpp +++ b/lib/Core/CallPathManager.cpp @@ -17,19 +17,14 @@ #include "llvm/Support/raw_ostream.h" -using namespace llvm; using namespace klee; /// -CallPathNode::CallPathNode(CallPathNode *_parent, - Instruction *_callSite, - Function *_function) - : parent(_parent), - callSite(_callSite), - function(_function), - count(0) { -} +CallPathNode::CallPathNode(CallPathNode *_parent, + const llvm::Instruction *_callSite, + const llvm::Function *_function) + : parent(_parent), callSite(_callSite), function(_function), count(0) {} void CallPathNode::print() { llvm::errs() << " (Function: " << this->function->getName() << ", " @@ -44,26 +39,17 @@ void CallPathNode::print() { /// -CallPathManager::CallPathManager() : root(0, 0, 0) { -} - -CallPathManager::~CallPathManager() { - for (std::vector<CallPathNode*>::iterator it = paths.begin(), - ie = paths.end(); it != ie; ++it) - delete *it; -} +CallPathManager::CallPathManager() : root(nullptr, nullptr, nullptr) {} void CallPathManager::getSummaryStatistics(CallSiteSummaryTable &results) { results.clear(); - for (std::vector<CallPathNode*>::iterator it = paths.begin(), - ie = paths.end(); it != ie; ++it) - (*it)->summaryStatistics = (*it)->statistics; + for (auto &path : paths) + path->summaryStatistics = path->statistics; // compute summary bottom up, while building result table - for (std::vector<CallPathNode*>::reverse_iterator it = paths.rbegin(), - ie = paths.rend(); it != ie; ++it) { - CallPathNode *cp = *it; + for (auto it = paths.rbegin(), ie = paths.rend(); it != ie; ++it) { + const auto &cp = (*it); cp->parent->summaryStatistics += cp->summaryStatistics; CallSiteInfo &csi = results[cp->callSite][cp->function]; @@ -72,29 +58,29 @@ void CallPathManager::getSummaryStatistics(CallSiteSummaryTable &results) { } } - -CallPathNode *CallPathManager::computeCallPath(CallPathNode *parent, - Instruction *cs, - Function *f) { +CallPathNode *CallPathManager::computeCallPath(CallPathNode *parent, + const llvm::Instruction *cs, + const llvm::Function *f) { for (CallPathNode *p=parent; p; p=p->parent) if (cs==p->callSite && f==p->function) return p; - - CallPathNode *cp = new CallPathNode(parent, cs, f); - paths.push_back(cp); - return cp; + + auto cp = std::unique_ptr<CallPathNode>(new CallPathNode(parent, cs, f)); + auto newCP = cp.get(); + paths.emplace_back(std::move(cp)); + return newCP; } -CallPathNode *CallPathManager::getCallPath(CallPathNode *parent, - Instruction *cs, - Function *f) { - std::pair<Instruction*,Function*> key(cs, f); +CallPathNode *CallPathManager::getCallPath(CallPathNode *parent, + const llvm::Instruction *cs, + const llvm::Function *f) { + std::pair<const llvm::Instruction *, const llvm::Function *> key(cs, f); if (!parent) parent = &root; - - CallPathNode::children_ty::iterator it = parent->children.find(key); + + auto it = parent->children.find(key); if (it==parent->children.end()) { - CallPathNode *cp = computeCallPath(parent, cs, f); + auto cp = computeCallPath(parent, cs, f); parent->children.insert(std::make_pair(key, cp)); return cp; } else { |