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 /// \brief Matches specific functions that pass the requirement of this filter.
26 class CoverageFilter {
28 virtual ~CoverageFilter() {}
30 /// \brief 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 {
37 /// \brief Matches functions that contain a specific string in their name.
38 class NameCoverageFilter : public CoverageFilter {
42 NameCoverageFilter(StringRef Name) : Name(Name) {}
44 bool matches(const coverage::CoverageMapping &CM,
45 const coverage::FunctionRecord &Function) const override;
48 /// \brief Matches functions whose name matches a certain regular expression.
49 class NameRegexCoverageFilter : public CoverageFilter {
53 NameRegexCoverageFilter(StringRef Regex) : Regex(Regex) {}
55 bool matches(const coverage::CoverageMapping &CM,
56 const coverage::FunctionRecord &Function) const override;
59 /// \brief Matches functions whose name appears in a SpecialCaseList in the
60 /// whitelist_fun section.
61 class NameWhitelistCoverageFilter : public CoverageFilter {
62 const SpecialCaseList &Whitelist;
65 NameWhitelistCoverageFilter(const SpecialCaseList &Whitelist)
66 : Whitelist(Whitelist) {}
68 bool matches(const coverage::CoverageMapping &CM,
69 const coverage::FunctionRecord &Function) const override;
72 /// \brief Matches numbers that pass a certain threshold.
73 template <typename T> class StatisticThresholdFilter {
75 enum Operation { LessThan, GreaterThan };
81 StatisticThresholdFilter(Operation Op, T Threshold)
82 : Op(Op), Threshold(Threshold) {}
84 /// \brief Return true if the given number is less than
85 /// or greater than the certain threshold.
86 bool PassesThreshold(T Value) const {
89 return Value < Threshold;
91 return Value > Threshold;
97 /// \brief Matches functions whose region coverage percentage
98 /// is above/below a certain percentage.
99 class RegionCoverageFilter : public CoverageFilter,
100 public StatisticThresholdFilter<double> {
102 RegionCoverageFilter(Operation Op, double Threshold)
103 : StatisticThresholdFilter(Op, Threshold) {}
105 bool matches(const coverage::CoverageMapping &CM,
106 const coverage::FunctionRecord &Function) const override;
109 /// \brief Matches functions whose line coverage percentage
110 /// is above/below a certain percentage.
111 class LineCoverageFilter : public CoverageFilter,
112 public StatisticThresholdFilter<double> {
114 LineCoverageFilter(Operation Op, double Threshold)
115 : StatisticThresholdFilter(Op, Threshold) {}
117 bool matches(const coverage::CoverageMapping &CM,
118 const coverage::FunctionRecord &Function) const override;
121 /// \brief A collection of filters.
122 /// Matches functions that match any filters contained
123 /// in an instance of this class.
124 class CoverageFilters : public CoverageFilter {
126 std::vector<std::unique_ptr<CoverageFilter>> Filters;
129 /// \brief Append a filter to this collection.
130 void push_back(std::unique_ptr<CoverageFilter> Filter);
132 bool empty() const { return Filters.empty(); }
134 bool matches(const coverage::CoverageMapping &CM,
135 const coverage::FunctionRecord &Function) const override;
138 /// \brief A collection of filters.
139 /// Matches functions that match all of the filters contained
140 /// in an instance of this class.
141 class CoverageFiltersMatchAll : public CoverageFilters {
143 bool matches(const coverage::CoverageMapping &CM,
144 const coverage::FunctionRecord &Function) const override;
149 #endif // LLVM_COV_COVERAGEFILTERS_H