clang  10.0.0git
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(llvm::SpecialCaseList::createOrDie(
21  AlwaysInstrumentPaths, SM.getFileManager().getVirtualFileSystem())),
22  NeverInstrument(llvm::SpecialCaseList::createOrDie(
23  NeverInstrumentPaths, SM.getFileManager().getVirtualFileSystem())),
24  AttrList(llvm::SpecialCaseList::createOrDie(
25  AttrListPaths, SM.getFileManager().getVirtualFileSystem())),
26  SM(SM) {}
27 
29 XRayFunctionFilter::shouldImbueFunction(StringRef FunctionName) const {
30  // First apply the always instrument list, than if it isn't an "always" see
31  // whether it's treated as a "never" instrument function.
32  // TODO: Remove these as they're deprecated; use the AttrList exclusively.
33  if (AlwaysInstrument->inSection("xray_always_instrument", "fun", FunctionName,
34  "arg1") ||
35  AttrList->inSection("always", "fun", FunctionName, "arg1"))
37  if (AlwaysInstrument->inSection("xray_always_instrument", "fun",
38  FunctionName) ||
39  AttrList->inSection("always", "fun", FunctionName))
41 
42  if (NeverInstrument->inSection("xray_never_instrument", "fun",
43  FunctionName) ||
44  AttrList->inSection("never", "fun", FunctionName))
45  return ImbueAttribute::NEVER;
46 
47  return ImbueAttribute::NONE;
48 }
49 
52  StringRef Category) const {
53  if (AlwaysInstrument->inSection("xray_always_instrument", "src", Filename,
54  Category) ||
55  AttrList->inSection("always", "src", Filename, Category))
57  if (NeverInstrument->inSection("xray_never_instrument", "src", Filename,
58  Category) ||
59  AttrList->inSection("never", "src", Filename, Category))
60  return ImbueAttribute::NEVER;
61  return ImbueAttribute::NONE;
62 }
63 
66  StringRef Category) const {
67  if (!Loc.isValid())
68  return ImbueAttribute::NONE;
69  return this->shouldImbueFunctionsInFile(SM.getFilename(SM.getFileLoc(Loc)),
70  Category);
71 }
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
Definition: Dominators.h:30
ImbueAttribute shouldImbueFunctionsInFile(StringRef Filename, StringRef Category=StringRef()) const
Definition: XRayLists.cpp:51
int Category
Definition: Format.cpp:1828
StringRef Filename
Definition: Format.cpp:1825
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:1685
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:29
ImbueAttribute shouldImbueLocation(SourceLocation Loc, StringRef Category=StringRef()) const
Definition: XRayLists.cpp:65
This class handles loading and caching of source files into memory.