1 //===--- XRayFunctionFilter.cpp - XRay automatic-attribution --------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // User-provided filters for always/never XRay instrumenting certain functions.
12 //===----------------------------------------------------------------------===//
13 #include "clang/Basic/XRayLists.h"
15 using namespace clang;
17 XRayFunctionFilter::XRayFunctionFilter(
18 ArrayRef<std::string> AlwaysInstrumentPaths,
19 ArrayRef<std::string> NeverInstrumentPaths,
20 ArrayRef<std::string> AttrListPaths, SourceManager &SM)
22 llvm::SpecialCaseList::createOrDie(AlwaysInstrumentPaths)),
23 NeverInstrument(llvm::SpecialCaseList::createOrDie(NeverInstrumentPaths)),
24 AttrList(llvm::SpecialCaseList::createOrDie(AttrListPaths)), SM(SM) {}
26 XRayFunctionFilter::ImbueAttribute
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,
33 AttrList->inSection("always", "fun", FunctionName, "arg1"))
34 return ImbueAttribute::ALWAYS_ARG1;
35 if (AlwaysInstrument->inSection("xray_always_instrument", "fun",
37 AttrList->inSection("always", "fun", FunctionName))
38 return ImbueAttribute::ALWAYS;
40 if (NeverInstrument->inSection("xray_never_instrument", "fun",
42 AttrList->inSection("never", "fun", FunctionName))
43 return ImbueAttribute::NEVER;
45 return ImbueAttribute::NONE;
48 XRayFunctionFilter::ImbueAttribute
49 XRayFunctionFilter::shouldImbueFunctionsInFile(StringRef Filename,
50 StringRef Category) const {
51 if (AlwaysInstrument->inSection("xray_always_instrument", "src", Filename,
53 AttrList->inSection("always", "src", Filename, Category))
54 return ImbueAttribute::ALWAYS;
55 if (NeverInstrument->inSection("xray_never_instrument", "src", Filename,
57 AttrList->inSection("never", "src", Filename, Category))
58 return ImbueAttribute::NEVER;
59 return ImbueAttribute::NONE;
62 XRayFunctionFilter::ImbueAttribute
63 XRayFunctionFilter::shouldImbueLocation(SourceLocation Loc,
64 StringRef Category) const {
66 return ImbueAttribute::NONE;
67 return this->shouldImbueFunctionsInFile(SM.getFilename(SM.getFileLoc(Loc)),