1 //===- PseudoProbe.h - Pseudo Probe IR Helpers ------------------*- 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 // Pseudo probe IR intrinsic and dwarf discriminator manipulation routines. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_IR_PSEUDOPROBE_H 14 #define LLVM_IR_PSEUDOPROBE_H 15 16 #include <cassert> 17 #include <cstdint> 18 19 namespace llvm { 20 21 enum class PseudoProbeType { Block = 0, IndirectCall, DirectCall }; 22 23 struct PseudoProbeDwarfDiscriminator { 24 // The following APIs encodes/decodes per-probe information to/from a 25 // 32-bit integer which is organized as: 26 // [2:0] - 0x7, this is reserved for regular discriminator, 27 // see DWARF discriminator encoding rule 28 // [18:3] - probe id 29 // [25:19] - reserved 30 // [28:26] - probe type, see PseudoProbeType 31 // [31:29] - reserved for probe attributes packProbeDataPseudoProbeDwarfDiscriminator32 static uint32_t packProbeData(uint32_t Index, uint32_t Type) { 33 assert(Index <= 0xFFFF && "Probe index too big to encode, exceeding 2^16"); 34 assert(Type <= 0x7 && "Probe type too big to encode, exceeding 7"); 35 return (Index << 3) | (Type << 26) | 0x7; 36 } 37 extractProbeIndexPseudoProbeDwarfDiscriminator38 static uint32_t extractProbeIndex(uint32_t Value) { 39 return (Value >> 3) & 0xFFFF; 40 } 41 extractProbeTypePseudoProbeDwarfDiscriminator42 static uint32_t extractProbeType(uint32_t Value) { 43 return (Value >> 26) & 0x7; 44 } 45 extractProbeAttributesPseudoProbeDwarfDiscriminator46 static uint32_t extractProbeAttributes(uint32_t Value) { 47 return (Value >> 29) & 0x7; 48 } 49 }; 50 } // end namespace llvm 51 52 #endif // LLVM_IR_PSEUDOPROBE_H 53