[InstCombine] Signed saturation tests. NFC
[llvm-complete.git] / tools / llvm-cov / CoverageFilters.cpp
blobca241e386e87e309e91bbc3280a62a1ab27ec487
1 //===- CoverageFilters.cpp - Function coverage mapping filters ------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // These classes provide filtering for function coverage mapping records.
11 //===----------------------------------------------------------------------===//
13 #include "CoverageFilters.h"
14 #include "CoverageSummaryInfo.h"
15 #include "llvm/Support/Regex.h"
17 using namespace llvm;
19 bool NameCoverageFilter::matches(
20 const coverage::CoverageMapping &,
21 const coverage::FunctionRecord &Function) const {
22 StringRef FuncName = Function.Name;
23 return FuncName.find(Name) != StringRef::npos;
26 bool NameRegexCoverageFilter::matches(
27 const coverage::CoverageMapping &,
28 const coverage::FunctionRecord &Function) const {
29 return llvm::Regex(Regex).match(Function.Name);
32 bool NameRegexCoverageFilter::matchesFilename(StringRef Filename) const {
33 return llvm::Regex(Regex).match(Filename);
36 bool NameWhitelistCoverageFilter::matches(
37 const coverage::CoverageMapping &,
38 const coverage::FunctionRecord &Function) const {
39 return Whitelist.inSection("llvmcov", "whitelist_fun", Function.Name);
42 bool RegionCoverageFilter::matches(
43 const coverage::CoverageMapping &CM,
44 const coverage::FunctionRecord &Function) const {
45 return PassesThreshold(FunctionCoverageSummary::get(CM, Function)
46 .RegionCoverage.getPercentCovered());
49 bool LineCoverageFilter::matches(
50 const coverage::CoverageMapping &CM,
51 const coverage::FunctionRecord &Function) const {
52 return PassesThreshold(FunctionCoverageSummary::get(CM, Function)
53 .LineCoverage.getPercentCovered());
56 void CoverageFilters::push_back(std::unique_ptr<CoverageFilter> Filter) {
57 Filters.push_back(std::move(Filter));
60 bool CoverageFilters::matches(const coverage::CoverageMapping &CM,
61 const coverage::FunctionRecord &Function) const {
62 for (const auto &Filter : Filters) {
63 if (Filter->matches(CM, Function))
64 return true;
66 return false;
69 bool CoverageFilters::matchesFilename(StringRef Filename) const {
70 for (const auto &Filter : Filters) {
71 if (Filter->matchesFilename(Filename))
72 return true;
74 return false;
77 bool CoverageFiltersMatchAll::matches(
78 const coverage::CoverageMapping &CM,
79 const coverage::FunctionRecord &Function) const {
80 for (const auto &Filter : Filters) {
81 if (!Filter->matches(CM, Function))
82 return false;
84 return true;