clang  14.0.0git
ProfileList.cpp
Go to the documentation of this file.
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 
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,
30 
31  static std::unique_ptr<ProfileSpecialCaseList>
32  createOrDie(const std::vector<std::string> &Paths,
33  llvm::vfs::FileSystem &VFS);
34 
35  bool isEmpty() const { return Sections.empty(); }
36 
37  bool hasPrefix(StringRef Prefix) const {
38  for (auto &SectionIter : Sections)
39  if (SectionIter.Entries.count(Prefix) > 0)
40  return true;
41  return false;
42  }
43 };
44 
45 std::unique_ptr<ProfileSpecialCaseList>
46 ProfileSpecialCaseList::create(const std::vector<std::string> &Paths,
47  llvm::vfs::FileSystem &VFS,
48  std::string &Error) {
49  auto PSCL = std::make_unique<ProfileSpecialCaseList>();
50  if (PSCL->createInternal(Paths, VFS, Error))
51  return PSCL;
52  return nullptr;
53 }
54 
55 std::unique_ptr<ProfileSpecialCaseList>
56 ProfileSpecialCaseList::createOrDie(const std::vector<std::string> &Paths,
57  llvm::vfs::FileSystem &VFS) {
59  if (auto PSCL = create(Paths, VFS, Error))
60  return PSCL;
61  llvm::report_fatal_error(llvm::Twine(Error));
62 }
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  Default(SCL->hasPrefix("fun") || SCL->hasPrefix("src")), SM(SM) {}
71 
72 ProfileList::~ProfileList() = default;
73 
75  switch (Kind) {
77  return "";
79  return "clang";
81  return "llvm";
83  return "csllvm";
84  }
85  llvm_unreachable("Unhandled CodeGenOptions::ProfileInstrKind enum");
86 }
87 
89 ProfileList::isFunctionExcluded(StringRef FunctionName,
91  StringRef Section = getSectionName(Kind);
92  if (SCL->inSection(Section, "!fun", FunctionName))
93  return true;
94  if (SCL->inSection(Section, "fun", FunctionName))
95  return false;
96  return None;
97 }
98 
102  return isFileExcluded(SM.getFilename(SM.getFileLoc(Loc)), Kind);
103 }
104 
106 ProfileList::isFileExcluded(StringRef FileName,
108  StringRef Section = getSectionName(Kind);
109  if (SCL->inSection(Section, "!src", FileName))
110  return true;
111  if (SCL->inSection(Section, "src", FileName))
112  return false;
113  return None;
114 }
clang::SourceManager::getFilename
StringRef getFilename(SourceLocation SpellingLoc) const
Return the filename of the file containing a SourceLocation.
Definition: SourceManager.cpp:1018
Error
llvm::Error Error
Definition: ByteCodeEmitter.cpp:20
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:88
clang::ProfileList::isLocationExcluded
llvm::Optional< bool > isLocationExcluded(SourceLocation Loc, CodeGenOptions::ProfileInstrKind Kind) const
Definition: ProfileList.cpp:100
ProfileList.h
clang::SourceManager::getFileLoc
SourceLocation getFileLoc(SourceLocation Loc) const
Given Loc, if it is a macro location return the expansion location or the spelling location,...
Definition: SourceManager.h:1168
llvm::Optional< bool >
SourceManager.h
clang::CodeGenOptions::ProfileInstrKind
ProfileInstrKind
Definition: CodeGenOptions.h:85
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:626
clang::StructuralEquivalenceKind::Default
@ Default
clang::CodeGenOptions::ProfileNone
@ ProfileNone
Definition: CodeGenOptions.h:86
clang::ProfileSpecialCaseList
Definition: ProfileList.cpp:25
clang::ProfileList::isFileExcluded
llvm::Optional< bool > isFileExcluded(StringRef FileName, CodeGenOptions::ProfileInstrKind Kind) const
Definition: ProfileList.cpp:106
clang::CodeGenOptions::ProfileClangInstr
@ ProfileClangInstr
Definition: CodeGenOptions.h:87
clang::ProfileList::isFunctionExcluded
llvm::Optional< bool > isFunctionExcluded(StringRef FunctionName, CodeGenOptions::ProfileInstrKind Kind) const
Definition: ProfileList.cpp:89
clang::ProfileSpecialCaseList::createOrDie
static std::unique_ptr< ProfileSpecialCaseList > createOrDie(const std::vector< std::string > &Paths, llvm::vfs::FileSystem &VFS)
Definition: ProfileList.cpp:56
clang::ProfileSpecialCaseList::isEmpty
bool isEmpty() const
Definition: ProfileList.cpp:35
clang::ProfileList::~ProfileList
~ProfileList()
clang::ProfileSpecialCaseList::hasPrefix
bool hasPrefix(StringRef Prefix) const
Definition: ProfileList.cpp:37
llvm::ArrayRef< std::string >
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang
Definition: CalledOnceCheck.h:17
clang::CodeGenOptions::ProfileIRInstr
@ ProfileIRInstr
Definition: CodeGenOptions.h:89
getSectionName
static StringRef getSectionName(CodeGenOptions::ProfileInstrKind Kind)
Definition: ProfileList.cpp:74
FileManager.h
clang::ProfileSpecialCaseList::create
static std::unique_ptr< ProfileSpecialCaseList > create(const std::vector< std::string > &Paths, llvm::vfs::FileSystem &VFS, std::string &Error)
Definition: ProfileList.cpp:46
SM
#define SM(sm)
Definition: Cuda.cpp:78
clang::CodeGenOptions::ProfileCSIRInstr
@ ProfileCSIRInstr
Definition: CodeGenOptions.h:90