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 | |
parent | 488e65f76e49e28e3db1a845276bf3dac49a2dc1 (diff) | |
download | klee-d5ce6b3b2c62badebc7534550f09f1b5592a7aa3.tar.gz |
Refactor InstructionInfoTable
Better debug information
Diffstat (limited to 'lib/Core')
-rw-r--r-- | lib/Core/CallPathManager.cpp | 62 | ||||
-rw-r--r-- | lib/Core/CallPathManager.h | 43 | ||||
-rw-r--r-- | lib/Core/Executor.cpp | 7 |
3 files changed, 48 insertions, 64 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 { diff --git a/lib/Core/CallPathManager.h b/lib/Core/CallPathManager.h index 2e16d72b..0a648777 100644 --- a/lib/Core/CallPathManager.h +++ b/lib/Core/CallPathManager.h @@ -13,6 +13,7 @@ #include "klee/Statistics.h" #include <map> +#include <memory> #include <vector> namespace llvm { @@ -31,20 +32,23 @@ namespace klee { CallSiteInfo() : count(0) {} }; - typedef std::map<llvm::Instruction*, - std::map<llvm::Function*, CallSiteInfo> > CallSiteSummaryTable; - + typedef std::map<const llvm::Instruction *, + std::map<const llvm::Function *, CallSiteInfo>> + CallSiteSummaryTable; + class CallPathNode { friend class CallPathManager; public: - typedef std::map<std::pair<llvm::Instruction*, - llvm::Function*>, CallPathNode*> children_ty; + typedef std::map< + std::pair<const llvm::Instruction *, const llvm::Function *>, + CallPathNode *> + children_ty; // form list of (callSite,function) path CallPathNode *parent; - llvm::Instruction *callSite; - llvm::Function *function; + const llvm::Instruction *callSite; + const llvm::Function *function; children_ty children; StatisticRecord statistics; @@ -52,31 +56,30 @@ namespace klee { unsigned count; public: - CallPathNode(CallPathNode *parent, - llvm::Instruction *callSite, - llvm::Function *function); + CallPathNode(CallPathNode *parent, const llvm::Instruction *callSite, + const llvm::Function *function); void print(); }; class CallPathManager { CallPathNode root; - std::vector<CallPathNode*> paths; + std::vector<std::unique_ptr<CallPathNode>> paths; private: - CallPathNode *computeCallPath(CallPathNode *parent, - llvm::Instruction *callSite, - llvm::Function *f); - + CallPathNode *computeCallPath(CallPathNode *parent, + const llvm::Instruction *callSite, + const llvm::Function *f); + public: CallPathManager(); - ~CallPathManager(); + ~CallPathManager() = default; void getSummaryStatistics(CallSiteSummaryTable &result); - - CallPathNode *getCallPath(CallPathNode *parent, - llvm::Instruction *callSite, - llvm::Function *f); + + CallPathNode *getCallPath(CallPathNode *parent, + const llvm::Instruction *callSite, + const llvm::Function *f); }; } diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp index 70561216..cd0f6078 100644 --- a/lib/Core/Executor.cpp +++ b/lib/Core/Executor.cpp @@ -1587,11 +1587,6 @@ Function* Executor::getTargetFunction(Value *calledVal, ExecutionState &state) { } } -/// TODO remove? -static bool isDebugIntrinsic(const Function *f, KModule *KM) { - return false; -} - static inline const llvm::fltSemantics * fpWidthToSemantics(unsigned width) { switch(width) { #if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0) @@ -1921,7 +1916,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { Function *f = getTargetFunction(fp, state); // Skip debug intrinsics, we can't evaluate their metadata arguments. - if (f && isDebugIntrinsic(f, kmodule.get())) + if (isa<DbgInfoIntrinsic>(i)) break; if (isa<InlineAsm>(fp)) { |