clang  14.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 
13 #include "clang/Basic/XRayLists.h"
16 #include "llvm/Support/SpecialCaseList.h"
17 
18 using namespace clang;
19 
21  ArrayRef<std::string> AlwaysInstrumentPaths,
22  ArrayRef<std::string> NeverInstrumentPaths,
23  ArrayRef<std::string> AttrListPaths, SourceManager &SM)
24  : AlwaysInstrument(llvm::SpecialCaseList::createOrDie(
25  AlwaysInstrumentPaths, SM.getFileManager().getVirtualFileSystem())),
26  NeverInstrument(llvm::SpecialCaseList::createOrDie(
27  NeverInstrumentPaths, SM.getFileManager().getVirtualFileSystem())),
28  AttrList(llvm::SpecialCaseList::createOrDie(
29  AttrListPaths, SM.getFileManager().getVirtualFileSystem())),
30  SM(SM) {}
31 
33 
35 XRayFunctionFilter::shouldImbueFunction(StringRef FunctionName) const {
36  // First apply the always instrument list, than if it isn't an "always" see
37  // whether it's treated as a "never" instrument function.
38  // TODO: Remove these as they're deprecated; use the AttrList exclusively.
39  if (AlwaysInstrument->inSection("xray_always_instrument", "fun", FunctionName,
40  "arg1") ||
41  AttrList->inSection("always", "fun", FunctionName, "arg1"))
43  if (AlwaysInstrument->inSection("xray_always_instrument", "fun",
44  FunctionName) ||
45  AttrList->inSection("always", "fun", FunctionName))
47 
48  if (NeverInstrument->inSection("xray_never_instrument", "fun",
49  FunctionName) ||
50  AttrList->inSection("never", "fun", FunctionName))
51  return ImbueAttribute::NEVER;
52 
53  return ImbueAttribute::NONE;
54 }
55 
58  StringRef Category) const {
59  if (AlwaysInstrument->inSection("xray_always_instrument", "src", Filename,
60  Category) ||
61  AttrList->inSection("always", "src", Filename, Category))
63  if (NeverInstrument->inSection("xray_never_instrument", "src", Filename,
64  Category) ||
65  AttrList->inSection("never", "src", Filename, Category))
66  return ImbueAttribute::NEVER;
67  return ImbueAttribute::NONE;
68 }
69 
72  StringRef Category) const {
73  if (!Loc.isValid())
74  return ImbueAttribute::NONE;
75  return this->shouldImbueFunctionsInFile(SM.getFilename(SM.getFileLoc(Loc)),
76  Category);
77 }
clang::SourceManager::getFilename
StringRef getFilename(SourceLocation SpellingLoc) const
Return the filename of the file containing a SourceLocation.
Definition: SourceManager.cpp:1018
llvm
Definition: Dominators.h:30
clang::XRayFunctionFilter::shouldImbueLocation
ImbueAttribute shouldImbueLocation(SourceLocation Loc, StringRef Category=StringRef()) const
Definition: XRayLists.cpp:71
clang::XRayFunctionFilter::ImbueAttribute::ALWAYS_ARG1
@ ALWAYS_ARG1
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:88
Filename
StringRef Filename
Definition: Format.cpp:2333
clang::XRayFunctionFilter::XRayFunctionFilter
XRayFunctionFilter(ArrayRef< std::string > AlwaysInstrumentPaths, ArrayRef< std::string > NeverInstrumentPaths, ArrayRef< std::string > AttrListPaths, SourceManager &SM)
Definition: XRayLists.cpp:20
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
SourceManager.h
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:626
Category
int Category
Definition: Format.cpp:2336
clang::XRayFunctionFilter::ImbueAttribute::NONE
@ NONE
clang::XRayFunctionFilter::ImbueAttribute::NEVER
@ NEVER
llvm::ArrayRef< std::string >
clang
Definition: CalledOnceCheck.h:17
XRayLists.h
clang::XRayFunctionFilter::shouldImbueFunction
ImbueAttribute shouldImbueFunction(StringRef FunctionName) const
Definition: XRayLists.cpp:35
clang::XRayFunctionFilter::~XRayFunctionFilter
~XRayFunctionFilter()
clang::SourceLocation::isValid
bool isValid() const
Return true if this is a valid SourceLocation object.
Definition: SourceLocation.h:112
clang::XRayFunctionFilter::shouldImbueFunctionsInFile
ImbueAttribute shouldImbueFunctionsInFile(StringRef Filename, StringRef Category=StringRef()) const
Definition: XRayLists.cpp:57
FileManager.h
SM
#define SM(sm)
Definition: Cuda.cpp:78
clang::XRayFunctionFilter::ImbueAttribute
ImbueAttribute
Definition: XRayLists.h:41
clang::XRayFunctionFilter::ImbueAttribute::ALWAYS
@ ALWAYS