XRayLists.cpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #include "clang/Basic/XRayLists.h"
  13. using namespace clang;
  14. XRayFunctionFilter::XRayFunctionFilter(
  15. ArrayRef<std::string> AlwaysInstrumentPaths,
  16. ArrayRef<std::string> NeverInstrumentPaths,
  17. ArrayRef<std::string> AttrListPaths, SourceManager &SM)
  18. : AlwaysInstrument(
  19. llvm::SpecialCaseList::createOrDie(AlwaysInstrumentPaths)),
  20. NeverInstrument(llvm::SpecialCaseList::createOrDie(NeverInstrumentPaths)),
  21. AttrList(llvm::SpecialCaseList::createOrDie(AttrListPaths)), SM(SM) {}
  22. XRayFunctionFilter::ImbueAttribute
  23. XRayFunctionFilter::shouldImbueFunction(StringRef FunctionName) const {
  24. // First apply the always instrument list, than if it isn't an "always" see
  25. // whether it's treated as a "never" instrument function.
  26. // TODO: Remove these as they're deprecated; use the AttrList exclusively.
  27. if (AlwaysInstrument->inSection("xray_always_instrument", "fun", FunctionName,
  28. "arg1") ||
  29. AttrList->inSection("always", "fun", FunctionName, "arg1"))
  30. return ImbueAttribute::ALWAYS_ARG1;
  31. if (AlwaysInstrument->inSection("xray_always_instrument", "fun",
  32. FunctionName) ||
  33. AttrList->inSection("always", "fun", FunctionName))
  34. return ImbueAttribute::ALWAYS;
  35. if (NeverInstrument->inSection("xray_never_instrument", "fun",
  36. FunctionName) ||
  37. AttrList->inSection("never", "fun", FunctionName))
  38. return ImbueAttribute::NEVER;
  39. return ImbueAttribute::NONE;
  40. }
  41. XRayFunctionFilter::ImbueAttribute
  42. XRayFunctionFilter::shouldImbueFunctionsInFile(StringRef Filename,
  43. StringRef Category) const {
  44. if (AlwaysInstrument->inSection("xray_always_instrument", "src", Filename,
  45. Category) ||
  46. AttrList->inSection("always", "src", Filename, Category))
  47. return ImbueAttribute::ALWAYS;
  48. if (NeverInstrument->inSection("xray_never_instrument", "src", Filename,
  49. Category) ||
  50. AttrList->inSection("never", "src", Filename, Category))
  51. return ImbueAttribute::NEVER;
  52. return ImbueAttribute::NONE;
  53. }
  54. XRayFunctionFilter::ImbueAttribute
  55. XRayFunctionFilter::shouldImbueLocation(SourceLocation Loc,
  56. StringRef Category) const {
  57. if (!Loc.isValid())
  58. return ImbueAttribute::NONE;
  59. return this->shouldImbueFunctionsInFile(SM.getFilename(SM.getFileLoc(Loc)),
  60. Category);
  61. }