blob: ad331899d2e224a302145432e5ae0030d8d28c31 [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,
Dean Michael Berris20dc6ef2018-04-09 04:02:09 +000019 ArrayRef<std::string> NeverInstrumentPaths,
20 ArrayRef<std::string> AttrListPaths, SourceManager &SM)
Dean Michael Berris835832d2017-03-30 00:29:36 +000021 : AlwaysInstrument(
22 llvm::SpecialCaseList::createOrDie(AlwaysInstrumentPaths)),
23 NeverInstrument(llvm::SpecialCaseList::createOrDie(NeverInstrumentPaths)),
Dean Michael Berris20dc6ef2018-04-09 04:02:09 +000024 AttrList(llvm::SpecialCaseList::createOrDie(AttrListPaths)), SM(SM) {}
Dean Michael Berris835832d2017-03-30 00:29:36 +000025
26XRayFunctionFilter::ImbueAttribute
27XRayFunctionFilter::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.
Dean Michael Berris20dc6ef2018-04-09 04:02:09 +000030 // TODO: Remove these as they're deprecated; use the AttrList exclusively.
Vlad Tsyrklevich2eccdab2017-09-25 22:11:12 +000031 if (AlwaysInstrument->inSection("xray_always_instrument", "fun", FunctionName,
Dean Michael Berris20dc6ef2018-04-09 04:02:09 +000032 "arg1") ||
33 AttrList->inSection("always", "fun", FunctionName, "arg1"))
Dean Michael Berris170429e2017-05-24 05:46:36 +000034 return ImbueAttribute::ALWAYS_ARG1;
Vlad Tsyrklevich2eccdab2017-09-25 22:11:12 +000035 if (AlwaysInstrument->inSection("xray_always_instrument", "fun",
Dean Michael Berris20dc6ef2018-04-09 04:02:09 +000036 FunctionName) ||
37 AttrList->inSection("always", "fun", FunctionName))
Dean Michael Berris835832d2017-03-30 00:29:36 +000038 return ImbueAttribute::ALWAYS;
Dean Michael Berris20dc6ef2018-04-09 04:02:09 +000039
40 if (NeverInstrument->inSection("xray_never_instrument", "fun",
41 FunctionName) ||
42 AttrList->inSection("never", "fun", FunctionName))
Dean Michael Berris835832d2017-03-30 00:29:36 +000043 return ImbueAttribute::NEVER;
Dean Michael Berris20dc6ef2018-04-09 04:02:09 +000044
Dean Michael Berris835832d2017-03-30 00:29:36 +000045 return ImbueAttribute::NONE;
46}
47
48XRayFunctionFilter::ImbueAttribute
49XRayFunctionFilter::shouldImbueFunctionsInFile(StringRef Filename,
50 StringRef Category) const {
Vlad Tsyrklevich2eccdab2017-09-25 22:11:12 +000051 if (AlwaysInstrument->inSection("xray_always_instrument", "src", Filename,
Dean Michael Berris20dc6ef2018-04-09 04:02:09 +000052 Category) ||
53 AttrList->inSection("always", "src", Filename, Category))
Dean Michael Berris835832d2017-03-30 00:29:36 +000054 return ImbueAttribute::ALWAYS;
Vlad Tsyrklevich2eccdab2017-09-25 22:11:12 +000055 if (NeverInstrument->inSection("xray_never_instrument", "src", Filename,
Dean Michael Berris20dc6ef2018-04-09 04:02:09 +000056 Category) ||
57 AttrList->inSection("never", "src", Filename, Category))
Dean Michael Berris835832d2017-03-30 00:29:36 +000058 return ImbueAttribute::NEVER;
59 return ImbueAttribute::NONE;
60}
61
62XRayFunctionFilter::ImbueAttribute
63XRayFunctionFilter::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}