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
XRayFunctionFilter(ArrayRef<std::string> AlwaysInstrumentPaths,ArrayRef<std::string> NeverInstrumentPaths,ArrayRef<std::string> AttrListPaths,SourceManager & SM)17 XRayFunctionFilter::XRayFunctionFilter(
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
26 XRayFunctionFilter::ImbueAttribute
shouldImbueFunction(StringRef FunctionName) const27 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"))
34 return ImbueAttribute::ALWAYS_ARG1;
35 if (AlwaysInstrument->inSection("xray_always_instrument", "fun",
36 FunctionName) ||
37 AttrList->inSection("always", "fun", FunctionName))
38 return ImbueAttribute::ALWAYS;
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
48 XRayFunctionFilter::ImbueAttribute
shouldImbueFunctionsInFile(StringRef Filename,StringRef Category) const49 XRayFunctionFilter::shouldImbueFunctionsInFile(StringRef Filename,
50 StringRef Category) const {
51 if (AlwaysInstrument->inSection("xray_always_instrument", "src", Filename,
52 Category) ||
53 AttrList->inSection("always", "src", Filename, Category))
54 return ImbueAttribute::ALWAYS;
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
62 XRayFunctionFilter::ImbueAttribute
shouldImbueLocation(SourceLocation Loc,StringRef Category) const63 XRayFunctionFilter::shouldImbueLocation(SourceLocation Loc,
64 StringRef Category) const {
65 if (!Loc.isValid())
66 return ImbueAttribute::NONE;
67 return this->shouldImbueFunctionsInFile(SM.getFilename(SM.getFileLoc(Loc)),
68 Category);
69 }
70