Coverage Report

Created: 2018-09-25 23:22

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/StaticAnalyzer/Core/PathSensitive/FunctionSummary.h
Line
Count
Source (jump to first uncovered line)
1
//===- FunctionSummary.h - Stores summaries of functions. -------*- C++ -*-===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
// This file defines a summary of a function gathered/used by static analysis.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_FUNCTIONSUMMARY_H
15
#define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_FUNCTIONSUMMARY_H
16
17
#include "clang/AST/Decl.h"
18
#include "clang/Basic/LLVM.h"
19
#include "llvm/ADT/DenseMap.h"
20
#include "llvm/ADT/DenseSet.h"
21
#include "llvm/ADT/None.h"
22
#include "llvm/ADT/Optional.h"
23
#include "llvm/ADT/SmallBitVector.h"
24
#include <cassert>
25
#include <deque>
26
#include <utility>
27
28
namespace clang {
29
namespace ento {
30
31
using SetOfDecls = std::deque<Decl *>;
32
using SetOfConstDecls = llvm::DenseSet<const Decl *>;
33
34
class FunctionSummariesTy {
35
  class FunctionSummary {
36
  public:
37
    /// Marks the IDs of the basic blocks visited during the analyzes.
38
    llvm::SmallBitVector VisitedBasicBlocks;
39
40
    /// Total number of blocks in the function.
41
    unsigned TotalBasicBlocks : 30;
42
43
    /// True if this function has been checked against the rules for which
44
    /// functions may be inlined.
45
    unsigned InlineChecked : 1;
46
47
    /// True if this function may be inlined.
48
    unsigned MayInline : 1;
49
50
    /// The number of times the function has been inlined.
51
    unsigned TimesInlined : 32;
52
53
    FunctionSummary()
54
        : TotalBasicBlocks(0), InlineChecked(0), MayInline(0),
55
13.2k
          TimesInlined(0) {}
56
  };
57
58
  using MapTy = llvm::DenseMap<const Decl *, FunctionSummary>;
59
  MapTy Map;
60
61
public:
62
193k
  MapTy::iterator findOrInsertSummary(const Decl *D) {
63
193k
    MapTy::iterator I = Map.find(D);
64
193k
    if (I != Map.end())
65
179k
      return I;
66
13.2k
67
13.2k
    using KVPair = std::pair<const Decl *, FunctionSummary>;
68
13.2k
69
13.2k
    I = Map.insert(KVPair(D, FunctionSummary())).first;
70
13.2k
    assert(I != Map.end());
71
13.2k
    return I;
72
13.2k
  }
73
74
3.57k
  void markMayInline(const Decl *D) {
75
3.57k
    MapTy::iterator I = findOrInsertSummary(D);
76
3.57k
    I->second.InlineChecked = 1;
77
3.57k
    I->second.MayInline = 1;
78
3.57k
  }
79
80
287
  void markShouldNotInline(const Decl *D) {
81
287
    MapTy::iterator I = findOrInsertSummary(D);
82
287
    I->second.InlineChecked = 1;
83
287
    I->second.MayInline = 0;
84
287
  }
85
86
36
  void markReachedMaxBlockCount(const Decl *D) {
87
36
    markShouldNotInline(D);
88
36
  }
89
90
20.3k
  Optional<bool> mayInline(const Decl *D) {
91
20.3k
    MapTy::const_iterator I = Map.find(D);
92
20.3k
    if (I != Map.end() && 
I->second.InlineChecked16.6k
)
93
16.5k
      return I->second.MayInline;
94
3.81k
    return None;
95
3.81k
  }
96
97
169k
  void markVisitedBasicBlock(unsigned ID, const Decl* D, unsigned TotalIDs) {
98
169k
    MapTy::iterator I = findOrInsertSummary(D);
99
169k
    llvm::SmallBitVector &Blocks = I->second.VisitedBasicBlocks;
100
169k
    assert(ID < TotalIDs);
101
169k
    if (TotalIDs > Blocks.size()) {
102
13.0k
      Blocks.resize(TotalIDs);
103
13.0k
      I->second.TotalBasicBlocks = TotalIDs;
104
13.0k
    }
105
169k
    Blocks.set(ID);
106
169k
  }
107
108
0
  unsigned getNumVisitedBasicBlocks(const Decl* D) {
109
0
    MapTy::const_iterator I = Map.find(D);
110
0
    if (I != Map.end())
111
0
      return I->second.VisitedBasicBlocks.count();
112
0
    return 0;
113
0
  }
114
115
18.8k
  unsigned getNumTimesInlined(const Decl* D) {
116
18.8k
    MapTy::const_iterator I = Map.find(D);
117
18.8k
    if (I != Map.end())
118
18.8k
      return I->second.TimesInlined;
119
0
    return 0;
120
0
  }
121
122
19.2k
  void bumpNumTimesInlined(const Decl* D) {
123
19.2k
    MapTy::iterator I = findOrInsertSummary(D);
124
19.2k
    I->second.TimesInlined++;
125
19.2k
  }
126
127
  /// Get the percentage of the reachable blocks.
128
0
  unsigned getPercentBlocksReachable(const Decl *D) {
129
0
    MapTy::const_iterator I = Map.find(D);
130
0
      if (I != Map.end())
131
0
        return ((I->second.VisitedBasicBlocks.count() * 100) /
132
0
                 I->second.TotalBasicBlocks);
133
0
    return 0;
134
0
  }
135
136
  unsigned getTotalNumBasicBlocks();
137
  unsigned getTotalNumVisitedBasicBlocks();
138
};
139
140
} // namespace ento
141
} // namespace clang
142
143
#endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_FUNCTIONSUMMARY_H