XRayInstr.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- XRayInstr.h --------------------------------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. /// \file
  15. /// Defines the clang::XRayInstrKind enum.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_CLANG_BASIC_XRAYINSTR_H
  19. #define LLVM_CLANG_BASIC_XRAYINSTR_H
  20. #include "clang/Basic/LLVM.h"
  21. #include "llvm/ADT/StringRef.h"
  22. #include "llvm/Support/MathExtras.h"
  23. #include <cassert>
  24. #include <cstdint>
  25. namespace clang {
  26. using XRayInstrMask = uint32_t;
  27. namespace XRayInstrKind {
  28. // TODO: Auto-generate these as we add more instrumentation kinds.
  29. enum XRayInstrOrdinal : XRayInstrMask {
  30. XRIO_FunctionEntry,
  31. XRIO_FunctionExit,
  32. XRIO_Custom,
  33. XRIO_Typed,
  34. XRIO_Count
  35. };
  36. constexpr XRayInstrMask None = 0;
  37. constexpr XRayInstrMask FunctionEntry = 1U << XRIO_FunctionEntry;
  38. constexpr XRayInstrMask FunctionExit = 1U << XRIO_FunctionExit;
  39. constexpr XRayInstrMask Custom = 1U << XRIO_Custom;
  40. constexpr XRayInstrMask Typed = 1U << XRIO_Typed;
  41. constexpr XRayInstrMask All = FunctionEntry | FunctionExit | Custom | Typed;
  42. } // namespace XRayInstrKind
  43. struct XRayInstrSet {
  44. bool has(XRayInstrMask K) const {
  45. assert(llvm::isPowerOf2_32(K));
  46. return Mask & K;
  47. }
  48. bool hasOneOf(XRayInstrMask K) const { return Mask & K; }
  49. void set(XRayInstrMask K, bool Value) {
  50. Mask = Value ? (Mask | K) : (Mask & ~K);
  51. }
  52. void clear(XRayInstrMask K = XRayInstrKind::All) { Mask &= ~K; }
  53. bool empty() const { return Mask == 0; }
  54. bool full() const { return Mask == XRayInstrKind::All; }
  55. XRayInstrMask Mask = 0;
  56. };
  57. /// Parses a command line argument into a mask.
  58. XRayInstrMask parseXRayInstrValue(StringRef Value);
  59. /// Serializes a set into a list of command line arguments.
  60. void serializeXRayInstrValue(XRayInstrSet Set,
  61. SmallVectorImpl<StringRef> &Values);
  62. } // namespace clang
  63. #endif // LLVM_CLANG_BASIC_XRAYINSTR_H
  64. #ifdef __GNUC__
  65. #pragma GCC diagnostic pop
  66. #endif