clang  7.0.0svn
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,
20  ArrayRef<std::string> AttrListPaths, SourceManager &SM)
21  : AlwaysInstrument(
22  llvm::SpecialCaseList::createOrDie(AlwaysInstrumentPaths)),
23  NeverInstrument(llvm::SpecialCaseList::createOrDie(NeverInstrumentPaths)),
24  AttrList(llvm::SpecialCaseList::createOrDie(AttrListPaths)), SM(SM) {}
25 
27 XRayFunctionFilter::shouldImbueFunction(StringRef FunctionName) const {
28  // First apply the always instrument list, than if it isn't an "always" see
29  // whether it's treated as a "never" instrument function.
30  // TODO: Remove these as they're deprecated; use the AttrList exclusively.
31  if (AlwaysInstrument->inSection("xray_always_instrument", "fun", FunctionName,
32  "arg1") ||
33  AttrList->inSection("always", "fun", FunctionName, "arg1"))
35  if (AlwaysInstrument->inSection("xray_always_instrument", "fun",
36  FunctionName) ||
37  AttrList->inSection("always", "fun", FunctionName))
39 
40  if (NeverInstrument->inSection("xray_never_instrument", "fun",
41  FunctionName) ||
42  AttrList->inSection("never", "fun", FunctionName))
43  return ImbueAttribute::NEVER;
44 
45  return ImbueAttribute::NONE;
46 }
47 
50  StringRef Category) const {
51  if (AlwaysInstrument->inSection("xray_always_instrument", "src", Filename,
52  Category) ||
53  AttrList->inSection("always", "src", Filename, Category))
55  if (NeverInstrument->inSection("xray_never_instrument", "src", Filename,
56  Category) ||
57  AttrList->inSection("never", "src", Filename, Category))
58  return ImbueAttribute::NEVER;
59  return ImbueAttribute::NONE;
60 }
61 
64  StringRef Category) const {
65  if (!Loc.isValid())
66  return ImbueAttribute::NONE;
67  return this->shouldImbueFunctionsInFile(SM.getFilename(SM.getFileLoc(Loc)),
68  Category);
69 }
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:30
ImbueAttribute shouldImbueFunctionsInFile(StringRef Filename, StringRef Category=StringRef()) const
Definition: XRayLists.cpp:49
int Category
Definition: Format.cpp:1575
StringRef Filename
Definition: Format.cpp:1572
XRayFunctionFilter(ArrayRef< std::string > AlwaysInstrumentPaths, ArrayRef< std::string > NeverInstrumentPaths, ArrayRef< std::string > AttrListPaths, SourceManager &SM)
Definition: XRayLists.cpp:17
const SourceManager & SM
Definition: Format.cpp:1442
StringRef getFilename(SourceLocation SpellingLoc) const
Return the filename of the file containing a SourceLocation.
Encodes a location in the source.
SourceLocation getFileLoc(SourceLocation Loc) const
Given Loc, if it is a macro location return the expansion location or the spelling location...
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
ImbueAttribute shouldImbueFunction(StringRef FunctionName) const
Definition: XRayLists.cpp:27
ImbueAttribute shouldImbueLocation(SourceLocation Loc, StringRef Category=StringRef()) const
Definition: XRayLists.cpp:63
This class handles loading and caching of source files into memory.