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, SourceManager &SM)
21 llvm::SpecialCaseList::createOrDie(AlwaysInstrumentPaths)),
22 NeverInstrument(llvm::SpecialCaseList::createOrDie(NeverInstrumentPaths)),
25 XRayFunctionFilter::ImbueAttribute
26 XRayFunctionFilter::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, "arg1"))
30 return ImbueAttribute::ALWAYS_ARG1;
31 if (AlwaysInstrument->inSection("fun", FunctionName))
32 return ImbueAttribute::ALWAYS;
33 if (NeverInstrument->inSection("fun", FunctionName))
34 return ImbueAttribute::NEVER;
35 return ImbueAttribute::NONE;
38 XRayFunctionFilter::ImbueAttribute
39 XRayFunctionFilter::shouldImbueFunctionsInFile(StringRef Filename,
40 StringRef Category) const {
41 if (AlwaysInstrument->inSection("src", Filename, Category))
42 return ImbueAttribute::ALWAYS;
43 if (NeverInstrument->inSection("src", Filename, Category))
44 return ImbueAttribute::NEVER;
45 return ImbueAttribute::NONE;
48 XRayFunctionFilter::ImbueAttribute
49 XRayFunctionFilter::shouldImbueLocation(SourceLocation Loc,
50 StringRef Category) const {
52 return ImbueAttribute::NONE;
53 return this->shouldImbueFunctionsInFile(SM.getFilename(SM.getFileLoc(Loc)),