Coverage Report

Created: 2021-09-21 08:58

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Basic/ProfileList.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- ProfileList.h - ProfileList filter ---------------------*- C++ -*-===//
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
// User-provided filters include/exclude profile instrumentation in certain
10
// functions or files.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#include "clang/Basic/ProfileList.h"
15
#include "clang/Basic/FileManager.h"
16
#include "clang/Basic/SourceManager.h"
17
#include "llvm/Support/SpecialCaseList.h"
18
19
#include "llvm/Support/raw_ostream.h"
20
21
using namespace clang;
22
23
namespace clang {
24
25
class ProfileSpecialCaseList : public llvm::SpecialCaseList {
26
public:
27
  static std::unique_ptr<ProfileSpecialCaseList>
28
  create(const std::vector<std::string> &Paths, llvm::vfs::FileSystem &VFS,
29
         std::string &Error);
30
31
  static std::unique_ptr<ProfileSpecialCaseList>
32
  createOrDie(const std::vector<std::string> &Paths,
33
              llvm::vfs::FileSystem &VFS);
34
35
103k
  bool isEmpty() const { return Sections.empty(); }
36
37
207k
  bool hasPrefix(StringRef Prefix) const {
38
207k
    for (auto &SectionIter : Sections)
39
7
      if (SectionIter.Entries.count(Prefix) > 0)
40
4
        return true;
41
207k
    return false;
42
207k
  }
43
};
44
45
std::unique_ptr<ProfileSpecialCaseList>
46
ProfileSpecialCaseList::create(const std::vector<std::string> &Paths,
47
                               llvm::vfs::FileSystem &VFS,
48
103k
                               std::string &Error) {
49
103k
  auto PSCL = std::make_unique<ProfileSpecialCaseList>();
50
103k
  if (PSCL->createInternal(Paths, VFS, Error))
51
103k
    return PSCL;
52
18.4E
  return nullptr;
53
103k
}
54
55
std::unique_ptr<ProfileSpecialCaseList>
56
ProfileSpecialCaseList::createOrDie(const std::vector<std::string> &Paths,
57
103k
                                    llvm::vfs::FileSystem &VFS) {
58
103k
  std::string Error;
59
103k
  if (auto PSCL = create(Paths, VFS, Error))
60
103k
    return PSCL;
61
18.4E
  llvm::report_fatal_error(Error);
62
18.4E
}
63
64
}
65
66
ProfileList::ProfileList(ArrayRef<std::string> Paths, SourceManager &SM)
67
    : SCL(ProfileSpecialCaseList::createOrDie(
68
          Paths, SM.getFileManager().getVirtualFileSystem())),
69
      Empty(SCL->isEmpty()),
70
103k
      Default(SCL->hasPrefix("fun") || SCL->hasPrefix("src")), SM(SM) {}
71
72
98.9k
ProfileList::~ProfileList() = default;
73
74
18
static StringRef getSectionName(CodeGenOptions::ProfileInstrKind Kind) {
75
18
  switch (Kind) {
76
0
  case CodeGenOptions::ProfileNone:
77
0
    return "";
78
14
  case CodeGenOptions::ProfileClangInstr:
79
14
    return "clang";
80
4
  case CodeGenOptions::ProfileIRInstr:
81
4
    return "llvm";
82
0
  case CodeGenOptions::ProfileCSIRInstr:
83
0
    return "csllvm";
84
18
  }
85
0
  llvm_unreachable("Unhandled CodeGenOptions::ProfileInstrKind enum");
86
0
}
87
88
llvm::Optional<bool>
89
ProfileList::isFunctionExcluded(StringRef FunctionName,
90
10
                                CodeGenOptions::ProfileInstrKind Kind) const {
91
10
  StringRef Section = getSectionName(Kind);
92
10
  if (SCL->inSection(Section, "!fun", FunctionName))
93
2
    return true;
94
8
  if (SCL->inSection(Section, "fun", FunctionName))
95
3
    return false;
96
5
  return None;
97
8
}
98
99
llvm::Optional<bool>
100
ProfileList::isLocationExcluded(SourceLocation Loc,
101
5
                                CodeGenOptions::ProfileInstrKind Kind) const {
102
5
  return isFileExcluded(SM.getFilename(SM.getFileLoc(Loc)), Kind);
103
5
}
104
105
llvm::Optional<bool>
106
ProfileList::isFileExcluded(StringRef FileName,
107
8
                            CodeGenOptions::ProfileInstrKind Kind) const {
108
8
  StringRef Section = getSectionName(Kind);
109
8
  if (SCL->inSection(Section, "!src", FileName))
110
0
    return true;
111
8
  if (SCL->inSection(Section, "src", FileName))
112
2
    return false;
113
6
  return None;
114
8
}