llvm-project
77 строк · 3.3 Кб
1//===-- XRayLists.cpp - XRay automatic-attribution ------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// User-provided filters for always/never XRay instrumenting certain functions.
10//
11//===----------------------------------------------------------------------===//
12
13#include "clang/Basic/XRayLists.h"14#include "clang/Basic/FileManager.h"15#include "clang/Basic/SourceManager.h"16#include "llvm/Support/SpecialCaseList.h"17
18using namespace clang;19
20XRayFunctionFilter::XRayFunctionFilter(21ArrayRef<std::string> AlwaysInstrumentPaths,22ArrayRef<std::string> NeverInstrumentPaths,23ArrayRef<std::string> AttrListPaths, SourceManager &SM)24: AlwaysInstrument(llvm::SpecialCaseList::createOrDie(25AlwaysInstrumentPaths, SM.getFileManager().getVirtualFileSystem())),26NeverInstrument(llvm::SpecialCaseList::createOrDie(27NeverInstrumentPaths, SM.getFileManager().getVirtualFileSystem())),28AttrList(llvm::SpecialCaseList::createOrDie(29AttrListPaths, SM.getFileManager().getVirtualFileSystem())),30SM(SM) {}31
32XRayFunctionFilter::~XRayFunctionFilter() = default;33
34XRayFunctionFilter::ImbueAttribute35XRayFunctionFilter::shouldImbueFunction(StringRef FunctionName) const {36// First apply the always instrument list, than if it isn't an "always" see37// whether it's treated as a "never" instrument function.38// TODO: Remove these as they're deprecated; use the AttrList exclusively.39if (AlwaysInstrument->inSection("xray_always_instrument", "fun", FunctionName,40"arg1") ||41AttrList->inSection("always", "fun", FunctionName, "arg1"))42return ImbueAttribute::ALWAYS_ARG1;43if (AlwaysInstrument->inSection("xray_always_instrument", "fun",44FunctionName) ||45AttrList->inSection("always", "fun", FunctionName))46return ImbueAttribute::ALWAYS;47
48if (NeverInstrument->inSection("xray_never_instrument", "fun",49FunctionName) ||50AttrList->inSection("never", "fun", FunctionName))51return ImbueAttribute::NEVER;52
53return ImbueAttribute::NONE;54}
55
56XRayFunctionFilter::ImbueAttribute57XRayFunctionFilter::shouldImbueFunctionsInFile(StringRef Filename,58StringRef Category) const {59if (AlwaysInstrument->inSection("xray_always_instrument", "src", Filename,60Category) ||61AttrList->inSection("always", "src", Filename, Category))62return ImbueAttribute::ALWAYS;63if (NeverInstrument->inSection("xray_never_instrument", "src", Filename,64Category) ||65AttrList->inSection("never", "src", Filename, Category))66return ImbueAttribute::NEVER;67return ImbueAttribute::NONE;68}
69
70XRayFunctionFilter::ImbueAttribute71XRayFunctionFilter::shouldImbueLocation(SourceLocation Loc,72StringRef Category) const {73if (!Loc.isValid())74return ImbueAttribute::NONE;75return this->shouldImbueFunctionsInFile(SM.getFilename(SM.getFileLoc(Loc)),76Category);77}
78