clang  9.0.0svn
XRayLists.cpp
Go to the documentation of this file.
1 //===-- XRayLists.cpp - XRay automatic-attribution ------------------------===//
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 for always/never XRay instrumenting certain functions.
10 //
11 //===----------------------------------------------------------------------===//
12 #include "clang/Basic/XRayLists.h"
13 
14 using namespace clang;
15 
17  ArrayRef<std::string> AlwaysInstrumentPaths,
18  ArrayRef<std::string> NeverInstrumentPaths,
19  ArrayRef<std::string> AttrListPaths, SourceManager &SM)
20  : AlwaysInstrument(
21  llvm::SpecialCaseList::createOrDie(AlwaysInstrumentPaths)),
22  NeverInstrument(llvm::SpecialCaseList::createOrDie(NeverInstrumentPaths)),
23  AttrList(llvm::SpecialCaseList::createOrDie(AttrListPaths)), 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  // TODO: Remove these as they're deprecated; use the AttrList exclusively.
30  if (AlwaysInstrument->inSection("xray_always_instrument", "fun", FunctionName,
31  "arg1") ||
32  AttrList->inSection("always", "fun", FunctionName, "arg1"))
34  if (AlwaysInstrument->inSection("xray_always_instrument", "fun",
35  FunctionName) ||
36  AttrList->inSection("always", "fun", FunctionName))
38 
39  if (NeverInstrument->inSection("xray_never_instrument", "fun",
40  FunctionName) ||
41  AttrList->inSection("never", "fun", FunctionName))
42  return ImbueAttribute::NEVER;
43 
44  return ImbueAttribute::NONE;
45 }
46 
49  StringRef Category) const {
50  if (AlwaysInstrument->inSection("xray_always_instrument", "src", Filename,
51  Category) ||
52  AttrList->inSection("always", "src", Filename, Category))
54  if (NeverInstrument->inSection("xray_never_instrument", "src", Filename,
55  Category) ||
56  AttrList->inSection("never", "src", Filename, Category))
57  return ImbueAttribute::NEVER;
58  return ImbueAttribute::NONE;
59 }
60 
63  StringRef Category) const {
64  if (!Loc.isValid())
65  return ImbueAttribute::NONE;
66  return this->shouldImbueFunctionsInFile(SM.getFilename(SM.getFileLoc(Loc)),
67  Category);
68 }
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:29
ImbueAttribute shouldImbueFunctionsInFile(StringRef Filename, StringRef Category=StringRef()) const
Definition: XRayLists.cpp:48
int Category
Definition: Format.cpp:1710
StringRef Filename
Definition: Format.cpp:1707
XRayFunctionFilter(ArrayRef< std::string > AlwaysInstrumentPaths, ArrayRef< std::string > NeverInstrumentPaths, ArrayRef< std::string > AttrListPaths, SourceManager &SM)
Definition: XRayLists.cpp:16
const SourceManager & SM
Definition: Format.cpp:1568
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:26
ImbueAttribute shouldImbueLocation(SourceLocation Loc, StringRef Category=StringRef()) const
Definition: XRayLists.cpp:62
This class handles loading and caching of source files into memory.