Coverage Report

Created: 2018-12-09 11:54

/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.7k
          TimesInlined(0) {}
56
  };
57
58
  using MapTy = llvm::DenseMap<const Decl *, FunctionSummary>;
59
  MapTy Map;
60
61
public:
62
203k
  MapTy::iterator findOrInsertSummary(const Decl *D) {
63
203k
    MapTy::iterator I = Map.find(D);
64
203k
    if (I != Map.end())
65
190k
      return I;
66
13.7k
67
13.7k
    using KVPair = std::pair<const Decl *, FunctionSummary>;
68
13.7k
69
13.7k
    I = Map.insert(KVPair(D, FunctionSummary())).first;
70
13.7k
    assert(I != Map.end());
71
13.7k
    return I;
72
13.7k
  }
73
74
3.72k
  void markMayInline(const Decl *D) {
75
3.72k
    MapTy::iterator I = findOrInsertSummary(D);
76
3.72k
    I->second.InlineChecked = 1;
77
3.72k
    I->second.MayInline = 1;
78
3.72k
  }
79
80
291
  void markShouldNotInline(const Decl *D) {
81
291
    MapTy::iterator I = findOrInsertSummary(D);
82
291
    I->second.InlineChecked = 1;
83
291
    I->second.MayInline = 0;
84
291
  }
85
86
38
  void markReachedMaxBlockCount(const Decl *D) {
87
38
    markShouldNotInline(D);
88
38
  }
89
90
23.7k
  Optional<bool> mayInline(const Decl *D) {
91
23.7k
    MapTy::const_iterator I = Map.find(D);
92
23.7k
    if (I != Map.end() && 
I->second.InlineChecked19.9k
)
93
19.8k
      return I->second.MayInline;
94
3.95k
    return None;
95
3.95k
  }
96
97
177k
  void markVisitedBasicBlock(unsigned ID, const Decl* D, unsigned TotalIDs) {
98
177k
    MapTy::iterator I = findOrInsertSummary(D);
99
177k
    llvm::SmallBitVector &Blocks = I->second.VisitedBasicBlocks;
100
177k
    assert(ID < TotalIDs);
101
177k
    if (TotalIDs > Blocks.size()) {
102
13.4k
      Blocks.resize(TotalIDs);
103
13.4k
      I->second.TotalBasicBlocks = TotalIDs;
104
13.4k
    }
105
177k
    Blocks.set(ID);
106
177k
  }
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
22.2k
  unsigned getNumTimesInlined(const Decl* D) {
116
22.2k
    MapTy::const_iterator I = Map.find(D);
117
22.2k
    if (I != Map.end())
118
22.2k
      return I->second.TimesInlined;
119
0
    return 0;
120
0
  }
121
122
22.6k
  void bumpNumTimesInlined(const Decl* D) {
123
22.6k
    MapTy::iterator I = findOrInsertSummary(D);
124
22.6k
    I->second.TimesInlined++;
125
22.6k
  }
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