1 | //===--- XRayInstr.h --------------------------------------------*- C++ -*-===// |
---|---|
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 | /// \file |
10 | /// Defines the clang::XRayInstrKind enum. |
11 | // |
12 | //===----------------------------------------------------------------------===// |
13 | |
14 | #ifndef LLVM_CLANG_BASIC_XRAYINSTR_H |
15 | #define LLVM_CLANG_BASIC_XRAYINSTR_H |
16 | |
17 | #include "clang/Basic/LLVM.h" |
18 | #include "llvm/ADT/StringRef.h" |
19 | #include "llvm/Support/MathExtras.h" |
20 | #include <cassert> |
21 | #include <cstdint> |
22 | |
23 | namespace clang { |
24 | |
25 | using XRayInstrMask = uint32_t; |
26 | |
27 | namespace XRayInstrKind { |
28 | |
29 | // TODO: Auto-generate these as we add more instrumentation kinds. |
30 | enum XRayInstrOrdinal : XRayInstrMask { |
31 | XRIO_Function, |
32 | XRIO_Custom, |
33 | XRIO_Typed, |
34 | XRIO_Count |
35 | }; |
36 | |
37 | constexpr XRayInstrMask None = 0; |
38 | constexpr XRayInstrMask Function = 1U << XRIO_Function; |
39 | constexpr XRayInstrMask Custom = 1U << XRIO_Custom; |
40 | constexpr XRayInstrMask Typed = 1U << XRIO_Typed; |
41 | constexpr XRayInstrMask All = Function | Custom | Typed; |
42 | |
43 | } // namespace XRayInstrKind |
44 | |
45 | struct XRayInstrSet { |
46 | bool has(XRayInstrMask K) const { |
47 | assert(llvm::isPowerOf2_32(K)); |
48 | return Mask & K; |
49 | } |
50 | |
51 | bool hasOneOf(XRayInstrMask K) const { return Mask & K; } |
52 | |
53 | void set(XRayInstrMask K, bool Value) { |
54 | assert(llvm::isPowerOf2_32(K)); |
55 | Mask = Value ? (Mask | K) : (Mask & ~K); |
56 | } |
57 | |
58 | void clear(XRayInstrMask K = XRayInstrKind::All) { Mask &= ~K; } |
59 | |
60 | bool empty() const { return Mask == 0; } |
61 | |
62 | bool full() const { return Mask == XRayInstrKind::All; } |
63 | |
64 | XRayInstrMask Mask = 0; |
65 | }; |
66 | |
67 | XRayInstrMask parseXRayInstrValue(StringRef Value); |
68 | |
69 | } // namespace clang |
70 | |
71 | #endif // LLVM_CLANG_BASIC_XRAYINSTR_H |
72 |