Clang Project

clang_source_code/include/clang/Basic/XRayInstr.h
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
23namespace clang {
24
25using XRayInstrMask = uint32_t;
26
27namespace XRayInstrKind {
28
29// TODO: Auto-generate these as we add more instrumentation kinds.
30enum XRayInstrOrdinal : XRayInstrMask {
31  XRIO_Function,
32  XRIO_Custom,
33  XRIO_Typed,
34  XRIO_Count
35};
36
37constexpr XRayInstrMask None = 0;
38constexpr XRayInstrMask Function = 1U << XRIO_Function;
39constexpr XRayInstrMask Custom = 1U << XRIO_Custom;
40constexpr XRayInstrMask Typed = 1U << XRIO_Typed;
41constexpr XRayInstrMask All = Function | Custom | Typed;
42
43// namespace XRayInstrKind
44
45struct XRayInstrSet {
46  bool has(XRayInstrMask Kconst {
47    assert(llvm::isPowerOf2_32(K));
48    return Mask & K;
49  }
50
51  bool hasOneOf(XRayInstrMask Kconst { return Mask & K; }
52
53  void set(XRayInstrMask Kbool 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
67XRayInstrMask parseXRayInstrValue(StringRef Value);
68
69// namespace clang
70
71#endif // LLVM_CLANG_BASIC_XRAYINSTR_H
72
clang::XRayInstrSet::has
clang::XRayInstrSet::hasOneOf
clang::XRayInstrSet::set
clang::XRayInstrSet::clear
clang::XRayInstrSet::empty
clang::XRayInstrSet::full
clang::XRayInstrSet::Mask