about summary refs log tree commit diff homepage
path: root/lib/Core/CallPathManager.h
blob: 0a6487778e3edadd11fd37e7aa85844b492bf85c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//===-- CallPathManager.h ---------------------------------------*- C++ -*-===//
//
//                     The KLEE Symbolic Virtual Machine
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef __UTIL_CALLPATHMANAGER_H__
#define __UTIL_CALLPATHMANAGER_H__

#include "klee/Statistics.h"

#include <map>
#include <memory>
#include <vector>

namespace llvm {
  class Instruction;
  class Function;
}

namespace klee {
  class StatisticRecord;

  struct CallSiteInfo {
    unsigned count;
    StatisticRecord statistics;

  public:
    CallSiteInfo() : count(0) {}
  };

  typedef std::map<const llvm::Instruction *,
                   std::map<const llvm::Function *, CallSiteInfo>>
      CallSiteSummaryTable;

  class CallPathNode {
    friend class CallPathManager;

  public:
    typedef std::map<
        std::pair<const llvm::Instruction *, const llvm::Function *>,
        CallPathNode *>
        children_ty;

    // form list of (callSite,function) path
    CallPathNode *parent;
    const llvm::Instruction *callSite;
    const llvm::Function *function;
    children_ty children;

    StatisticRecord statistics;
    StatisticRecord summaryStatistics;
    unsigned count;

  public:
    CallPathNode(CallPathNode *parent, const llvm::Instruction *callSite,
                 const llvm::Function *function);

    void print();
  };

  class CallPathManager {
    CallPathNode root;
    std::vector<std::unique_ptr<CallPathNode>> paths;

  private:
    CallPathNode *computeCallPath(CallPathNode *parent,
                                  const llvm::Instruction *callSite,
                                  const llvm::Function *f);

  public:
    CallPathManager();
    ~CallPathManager() = default;

    void getSummaryStatistics(CallSiteSummaryTable &result);

    CallPathNode *getCallPath(CallPathNode *parent,
                              const llvm::Instruction *callSite,
                              const llvm::Function *f);
  };
}

#endif