blob: dccf3baa75e2683fdfa31561a48845a83d5a2fad [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.
29 if (AlwaysInstrument->inSection("fun", FunctionName))
30 return ImbueAttribute::ALWAYS;
31 if (NeverInstrument->inSection("fun", FunctionName))
32 return ImbueAttribute::NEVER;
33 return ImbueAttribute::NONE;
34}
35
36XRayFunctionFilter::ImbueAttribute
37XRayFunctionFilter::shouldImbueFunctionsInFile(StringRef Filename,
38 StringRef Category) const {
39 if (AlwaysInstrument->inSection("src", Filename, Category))
40 return ImbueAttribute::ALWAYS;
41 if (NeverInstrument->inSection("src", Filename, Category))
42 return ImbueAttribute::NEVER;
43 return ImbueAttribute::NONE;
44}
45
46XRayFunctionFilter::ImbueAttribute
47XRayFunctionFilter::shouldImbueLocation(SourceLocation Loc,
48 StringRef Category) const {
49 if (!Loc.isValid())
50 return ImbueAttribute::NONE;
51 return this->shouldImbueFunctionsInFile(SM.getFilename(SM.getFileLoc(Loc)),
52 Category);
53}