1 //===- CoverageFilters.h - Function coverage mapping filters --------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // These classes provide filtering for function coverage mapping records.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_COV_COVERAGEFILTERS_H
15 #define LLVM_COV_COVERAGEFILTERS_H
17 #include "CoverageSummaryInfo.h"
18 #include "llvm/ProfileData/Coverage/CoverageMapping.h"
19 #include "llvm/Support/SpecialCaseList.h"
25 /// Matches specific functions that pass the requirement of this filter.
26 class CoverageFilter
{
28 virtual ~CoverageFilter() {}
30 /// Return true if the function passes the requirements of this filter.
31 virtual bool matches(const coverage::CoverageMapping
&CM
,
32 const coverage::FunctionRecord
&Function
) const {
36 /// Return true if the filename passes the requirements of this filter.
37 virtual bool matchesFilename(StringRef Filename
) const {
42 /// Matches functions that contain a specific string in their name.
43 class NameCoverageFilter
: public CoverageFilter
{
47 NameCoverageFilter(StringRef Name
) : Name(Name
) {}
49 bool matches(const coverage::CoverageMapping
&CM
,
50 const coverage::FunctionRecord
&Function
) const override
;
53 /// Matches functions whose name matches a certain regular expression.
54 class NameRegexCoverageFilter
: public CoverageFilter
{
58 NameRegexCoverageFilter(StringRef Regex
) : Regex(Regex
) {}
60 bool matches(const coverage::CoverageMapping
&CM
,
61 const coverage::FunctionRecord
&Function
) const override
;
63 bool matchesFilename(StringRef Filename
) const override
;
66 /// Matches functions whose name appears in a SpecialCaseList in the
67 /// whitelist_fun section.
68 class NameWhitelistCoverageFilter
: public CoverageFilter
{
69 const SpecialCaseList
&Whitelist
;
72 NameWhitelistCoverageFilter(const SpecialCaseList
&Whitelist
)
73 : Whitelist(Whitelist
) {}
75 bool matches(const coverage::CoverageMapping
&CM
,
76 const coverage::FunctionRecord
&Function
) const override
;
79 /// Matches numbers that pass a certain threshold.
80 template <typename T
> class StatisticThresholdFilter
{
82 enum Operation
{ LessThan
, GreaterThan
};
88 StatisticThresholdFilter(Operation Op
, T Threshold
)
89 : Op(Op
), Threshold(Threshold
) {}
91 /// Return true if the given number is less than
92 /// or greater than the certain threshold.
93 bool PassesThreshold(T Value
) const {
96 return Value
< Threshold
;
98 return Value
> Threshold
;
104 /// Matches functions whose region coverage percentage
105 /// is above/below a certain percentage.
106 class RegionCoverageFilter
: public CoverageFilter
,
107 public StatisticThresholdFilter
<double> {
109 RegionCoverageFilter(Operation Op
, double Threshold
)
110 : StatisticThresholdFilter(Op
, Threshold
) {}
112 bool matches(const coverage::CoverageMapping
&CM
,
113 const coverage::FunctionRecord
&Function
) const override
;
116 /// Matches functions whose line coverage percentage
117 /// is above/below a certain percentage.
118 class LineCoverageFilter
: public CoverageFilter
,
119 public StatisticThresholdFilter
<double> {
121 LineCoverageFilter(Operation Op
, double Threshold
)
122 : StatisticThresholdFilter(Op
, Threshold
) {}
124 bool matches(const coverage::CoverageMapping
&CM
,
125 const coverage::FunctionRecord
&Function
) const override
;
128 /// A collection of filters.
129 /// Matches functions that match any filters contained
130 /// in an instance of this class.
131 class CoverageFilters
: public CoverageFilter
{
133 std::vector
<std::unique_ptr
<CoverageFilter
>> Filters
;
136 /// Append a filter to this collection.
137 void push_back(std::unique_ptr
<CoverageFilter
> Filter
);
139 bool empty() const { return Filters
.empty(); }
141 bool matches(const coverage::CoverageMapping
&CM
,
142 const coverage::FunctionRecord
&Function
) const override
;
144 bool matchesFilename(StringRef Filename
) const override
;
147 /// A collection of filters.
148 /// Matches functions that match all of the filters contained
149 /// in an instance of this class.
150 class CoverageFiltersMatchAll
: public CoverageFilters
{
152 bool matches(const coverage::CoverageMapping
&CM
,
153 const coverage::FunctionRecord
&Function
) const override
;
158 #endif // LLVM_COV_COVERAGEFILTERS_H