blob: 462777d53400f68577e11536c69de5ffad42e6ae [file] [log] [blame]
Dean Michael Berris835832d2017-03-30 00:29:36 +00001//===--- 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
15using namespace clang;
16
17XRayFunctionFilter::XRayFunctionFilter(
18 ArrayRef<std::string> AlwaysInstrumentPaths,
19 ArrayRef<std::string> NeverInstrumentPaths, SourceManager &SM)
20 : AlwaysInstrument(
21 llvm::SpecialCaseList::createOrDie(AlwaysInstrumentPaths)),
22 NeverInstrument(llvm::SpecialCaseList::createOrDie(NeverInstrumentPaths)),
23 SM(SM) {}
24
25XRayFunctionFilter::ImbueAttribute
26XRayFunctionFilter::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.
Vlad Tsyrklevich2eccdab2017-09-25 22:11:12 +000029 if (AlwaysInstrument->inSection("xray_always_instrument", "fun", FunctionName,
30 "arg1"))
Dean Michael Berris170429e2017-05-24 05:46:36 +000031 return ImbueAttribute::ALWAYS_ARG1;
Vlad Tsyrklevich2eccdab2017-09-25 22:11:12 +000032 if (AlwaysInstrument->inSection("xray_always_instrument", "fun",
33 FunctionName))
Dean Michael Berris835832d2017-03-30 00:29:36 +000034 return ImbueAttribute::ALWAYS;
Vlad Tsyrklevich2eccdab2017-09-25 22:11:12 +000035 if (NeverInstrument->inSection("xray_never_instrument", "fun", FunctionName))
Dean Michael Berris835832d2017-03-30 00:29:36 +000036 return ImbueAttribute::NEVER;
37 return ImbueAttribute::NONE;
38}
39
40XRayFunctionFilter::ImbueAttribute
41XRayFunctionFilter::shouldImbueFunctionsInFile(StringRef Filename,
42 StringRef Category) const {
Vlad Tsyrklevich2eccdab2017-09-25 22:11:12 +000043 if (AlwaysInstrument->inSection("xray_always_instrument", "src", Filename,
44 Category))
Dean Michael Berris835832d2017-03-30 00:29:36 +000045 return ImbueAttribute::ALWAYS;
Vlad Tsyrklevich2eccdab2017-09-25 22:11:12 +000046 if (NeverInstrument->inSection("xray_never_instrument", "src", Filename,
47 Category))
Dean Michael Berris835832d2017-03-30 00:29:36 +000048 return ImbueAttribute::NEVER;
49 return ImbueAttribute::NONE;
50}
51
52XRayFunctionFilter::ImbueAttribute
53XRayFunctionFilter::shouldImbueLocation(SourceLocation Loc,
54 StringRef Category) const {
55 if (!Loc.isValid())
56 return ImbueAttribute::NONE;
57 return this->shouldImbueFunctionsInFile(SM.getFilename(SM.getFileLoc(Loc)),
58 Category);
59}