117706Sjulian//===--- XRayInstr.h --------------------------------------------*- C++ -*-===//
217706Sjulian//
317706Sjulian// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
417706Sjulian// See https://llvm.org/LICENSE.txt for license information.
517706Sjulian// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
617706Sjulian//
717706Sjulian//===----------------------------------------------------------------------===//
817706Sjulian//
917706Sjulian/// \file
1017706Sjulian/// Defines the clang::XRayInstrKind enum.
1117706Sjulian//
1217706Sjulian//===----------------------------------------------------------------------===//
1317706Sjulian
1417706Sjulian#ifndef LLVM_CLANG_BASIC_XRAYINSTR_H
1517706Sjulian#define LLVM_CLANG_BASIC_XRAYINSTR_H
1617706Sjulian
1717706Sjulian#include "clang/Basic/LLVM.h"
1817706Sjulian#include "llvm/ADT/StringRef.h"
1917706Sjulian#include "llvm/Support/MathExtras.h"
2017706Sjulian#include <cassert>
2117706Sjulian#include <cstdint>
2217706Sjulian
2349439Sdeischennamespace clang {
2417706Sjulian
2517706Sjulianusing XRayInstrMask = uint32_t;
2617706Sjulian
2717706Sjuliannamespace XRayInstrKind {
2817706Sjulian
2917706Sjulian// TODO: Auto-generate these as we add more instrumentation kinds.
3017706Sjulianenum XRayInstrOrdinal : XRayInstrMask {
3117706Sjulian  XRIO_FunctionEntry,
3250476Speter  XRIO_FunctionExit,
3317706Sjulian  XRIO_Custom,
3417706Sjulian  XRIO_Typed,
3517706Sjulian  XRIO_Count
3617706Sjulian};
3717706Sjulian
3871581Sdeischenconstexpr XRayInstrMask None = 0;
3971581Sdeischenconstexpr XRayInstrMask FunctionEntry = 1U << XRIO_FunctionEntry;
4035509Sjbconstexpr XRayInstrMask FunctionExit = 1U << XRIO_FunctionExit;
4117706Sjulianconstexpr XRayInstrMask Custom = 1U << XRIO_Custom;
4271581Sdeischenconstexpr XRayInstrMask Typed = 1U << XRIO_Typed;
4317706Sjulianconstexpr XRayInstrMask All = FunctionEntry | FunctionExit | Custom | Typed;
4461681Sjasone
4561681Sjasone} // namespace XRayInstrKind
4635509Sjb
4735509Sjbstruct XRayInstrSet {
4835509Sjb  bool has(XRayInstrMask K) const {
4958094Sdeischen    assert(llvm::isPowerOf2_32(K));
5061681Sjasone    return Mask & K;
5161681Sjasone  }
5258094Sdeischen
5358094Sdeischen  bool hasOneOf(XRayInstrMask K) const { return Mask & K; }
5458094Sdeischen
5544963Sjb  void set(XRayInstrMask K, bool Value) {
5648046Sjb    Mask = Value ? (Mask | K) : (Mask & ~K);
5748046Sjb  }
5844963Sjb
5948046Sjb  void clear(XRayInstrMask K = XRayInstrKind::All) { Mask &= ~K; }
6044963Sjb
6161681Sjasone  bool empty() const { return Mask == 0; }
6261681Sjasone
6361681Sjasone  bool full() const { return Mask == XRayInstrKind::All; }
6461681Sjasone
6561681Sjasone  XRayInstrMask Mask = 0;
6661681Sjasone};
6761681Sjasone
6861681Sjasone/// Parses a command line argument into a mask.
6961681SjasoneXRayInstrMask parseXRayInstrValue(StringRef Value);
7061681Sjasone
7161681Sjasone/// Serializes a set into a list of command line arguments.
7261681Sjasonevoid serializeXRayInstrValue(XRayInstrSet Set,
7361681Sjasone                             SmallVectorImpl<StringRef> &Values);
7461681Sjasone
7561681Sjasone} // namespace clang
7661681Sjasone
7761681Sjasone#endif // LLVM_CLANG_BASIC_XRAYINSTR_H
7861681Sjasone