clang  5.0.0
XRayLists.cpp
Go to the documentation of this file.
1 //===--- XRayFunctionFilter.cpp - XRay automatic-attribution --------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // User-provided filters for always/never XRay instrumenting certain functions.
11 //
12 //===----------------------------------------------------------------------===//
13 #include "clang/Basic/XRayLists.h"
14 
15 using namespace clang;
16 
18  ArrayRef<std::string> AlwaysInstrumentPaths,
19  ArrayRef<std::string> NeverInstrumentPaths, SourceManager &SM)
20  : AlwaysInstrument(
21  llvm::SpecialCaseList::createOrDie(AlwaysInstrumentPaths)),
22  NeverInstrument(llvm::SpecialCaseList::createOrDie(NeverInstrumentPaths)),
23  SM(SM) {}
24 
26 XRayFunctionFilter::shouldImbueFunction(StringRef FunctionName) const {
27  // First apply the always instrument list, than if it isn't an "always" see
28  // whether it's treated as a "never" instrument function.
29  if (AlwaysInstrument->inSection("fun", FunctionName, "arg1"))
31  if (AlwaysInstrument->inSection("fun", FunctionName))
33  if (NeverInstrument->inSection("fun", FunctionName))
34  return ImbueAttribute::NEVER;
35  return ImbueAttribute::NONE;
36 }
37 
40  StringRef Category) const {
41  if (AlwaysInstrument->inSection("src", Filename, Category))
43  if (NeverInstrument->inSection("src", Filename, Category))
44  return ImbueAttribute::NEVER;
45  return ImbueAttribute::NONE;
46 }
47 
50  StringRef Category) const {
51  if (!Loc.isValid())
52  return ImbueAttribute::NONE;
53  return this->shouldImbueFunctionsInFile(SM.getFilename(SM.getFileLoc(Loc)),
54  Category);
55 }
int Category
Definition: Format.cpp:1304
ImbueAttribute shouldImbueFunctionsInFile(StringRef Filename, StringRef Category=StringRef()) const
Definition: XRayLists.cpp:39
SourceLocation getFileLoc(SourceLocation Loc) const
Given Loc, if it is a macro location return the expansion location or the spelling location...
ImbueAttribute shouldImbueLocation(SourceLocation Loc, StringRef Category=StringRef()) const
Definition: XRayLists.cpp:49
XRayFunctionFilter(ArrayRef< std::string > AlwaysInstrumentPaths, ArrayRef< std::string > NeverInstrumentPaths, SourceManager &SM)
Definition: XRayLists.cpp:17
StringRef getFilename(SourceLocation SpellingLoc) const
Return the filename of the file containing a SourceLocation.
StringRef Filename
Definition: Format.cpp:1301
const SourceManager & SM
Definition: Format.cpp:1293
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
ImbueAttribute shouldImbueFunction(StringRef FunctionName) const
Definition: XRayLists.cpp:26
This class handles loading and caching of source files into memory.