klee
CallPathManager.cpp
Go to the documentation of this file.
1//===-- CallPathManager.cpp -----------------------------------------------===//
2//
3// The KLEE Symbolic Virtual Machine
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "CallPathManager.h"
11
13
14#include "llvm/IR/Function.h"
15#include "llvm/Support/raw_ostream.h"
16
17#include <map>
18#include <vector>
19
20using namespace klee;
21
23
24CallPathNode::CallPathNode(CallPathNode *_parent,
25 const llvm::Instruction *_callSite,
26 const llvm::Function *_function)
27 : parent(_parent), callSite(_callSite), function(_function), count(0) {}
28
30 llvm::errs() << " (Function: " << this->function->getName() << ", "
31 << "Callsite: " << callSite << ", "
32 << "Count: " << this->count << ")";
33 if (parent && parent->callSite) {
34 llvm::errs() << ";\n";
35 parent->print();
36 }
37 else llvm::errs() << "\n";
38}
39
41
42CallPathManager::CallPathManager() : root(nullptr, nullptr, nullptr) {}
43
45 results.clear();
46
47 for (auto &path : paths)
48 path->summaryStatistics = path->statistics;
49
50 // compute summary bottom up, while building result table
51 for (auto it = paths.rbegin(), ie = paths.rend(); it != ie; ++it) {
52 const auto &cp = (*it);
53 cp->parent->summaryStatistics += cp->summaryStatistics;
54
55 CallSiteInfo &csi = results[cp->callSite][cp->function];
56 csi.count += cp->count;
57 csi.statistics += cp->summaryStatistics;
58 }
59}
60
62 const llvm::Instruction *cs,
63 const llvm::Function *f) {
64 for (CallPathNode *p=parent; p; p=p->parent)
65 if (cs==p->callSite && f==p->function)
66 return p;
67
68 auto cp = std::unique_ptr<CallPathNode>(new CallPathNode(parent, cs, f));
69 auto newCP = cp.get();
70 paths.emplace_back(std::move(cp));
71 return newCP;
72}
73
75 const llvm::Instruction *cs,
76 const llvm::Function *f) {
77 std::pair<const llvm::Instruction *, const llvm::Function *> key(cs, f);
78 if (!parent)
79 parent = &root;
80
81 auto it = parent->children.find(key);
82 if (it==parent->children.end()) {
83 auto cp = computeCallPath(parent, cs, f);
84 parent->children.insert(std::make_pair(key, cp));
85 return cp;
86 } else {
87 return it->second;
88 }
89}
90
std::vector< std::unique_ptr< CallPathNode > > paths
CallPathNode * getCallPath(CallPathNode *parent, const llvm::Instruction *callSite, const llvm::Function *f)
CallPathNode * computeCallPath(CallPathNode *parent, const llvm::Instruction *callSite, const llvm::Function *f)
void getSummaryStatistics(CallSiteSummaryTable &result)
const llvm::Function * function
const llvm::Instruction * callSite
children_ty children
CallPathNode * parent
Definition: main.cpp:291
std::map< const llvm::Instruction *, std::map< const llvm::Function *, CallSiteInfo > > CallSiteSummaryTable
StatisticRecord statistics