LLVM  14.0.0git
PseudoProbe.h
Go to the documentation of this file.
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 "llvm/ADT/Optional.h"
17 #include <cassert>
18 #include <cstdint>
19 #include <limits>
20 
21 namespace llvm {
22 
23 class Instruction;
24 class BasicBlock;
25 
26 constexpr const char *PseudoProbeDescMetadataName = "llvm.pseudo_probe_desc";
27 
29 
31  Reserved = 0x1, // Reserved for future use.
32 };
33 
34 // The saturated distrution factor representing 100% for block probes.
37 
39 public:
40  // The following APIs encodes/decodes per-probe information to/from a
41  // 32-bit integer which is organized as:
42  // [2:0] - 0x7, this is reserved for regular discriminator,
43  // see DWARF discriminator encoding rule
44  // [18:3] - probe id
45  // [25:19] - probe distribution factor
46  // [28:26] - probe type, see PseudoProbeType
47  // [31:29] - reserved for probe attributes
49  uint32_t Factor) {
50  assert(Index <= 0xFFFF && "Probe index too big to encode, exceeding 2^16");
51  assert(Type <= 0x7 && "Probe type too big to encode, exceeding 7");
52  assert(Flags <= 0x7);
53  assert(Factor <= 100 &&
54  "Probe distribution factor too big to encode, exceeding 100");
55  return (Index << 3) | (Factor << 19) | (Type << 26) | 0x7;
56  }
57 
59  return (Value >> 3) & 0xFFFF;
60  }
61 
63  return (Value >> 26) & 0x7;
64  }
65 
67  return (Value >> 29) & 0x7;
68  }
69 
71  return (Value >> 19) & 0x7F;
72  }
73 
74  // The saturated distrution factor representing 100% for callsites.
75  constexpr static uint8_t FullDistributionFactor = 100;
76 };
77 
78 struct PseudoProbe {
82  // Distribution factor that estimates the portion of the real execution count.
83  // A saturated distribution factor stands for 1.0 or 100%. A pesudo probe has
84  // a factor with the value ranged from 0.0 to 1.0.
85  float Factor;
86 };
87 
89 
90 void setProbeDistributionFactor(Instruction &Inst, float Factor);
91 } // end namespace llvm
92 
93 #endif // LLVM_IR_PSEUDOPROBE_H
llvm::PseudoProbeFullDistributionFactor
constexpr static uint64_t PseudoProbeFullDistributionFactor
Definition: PseudoProbe.h:35
llvm::PseudoProbeDwarfDiscriminator::extractProbeAttributes
static uint32_t extractProbeAttributes(uint32_t Value)
Definition: PseudoProbe.h:66
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::PseudoProbeDwarfDiscriminator::FullDistributionFactor
constexpr static uint8_t FullDistributionFactor
Definition: PseudoProbe.h:75
Optional.h
llvm::PseudoProbeDwarfDiscriminator::extractProbeType
static uint32_t extractProbeType(uint32_t Value)
Definition: PseudoProbe.h:62
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::PseudoProbeAttributes
PseudoProbeAttributes
Definition: PseudoProbe.h:30
llvm::Optional
Definition: APInt.h:33
llvm::PseudoProbe::Factor
float Factor
Definition: PseudoProbe.h:85
llvm::PseudoProbeDwarfDiscriminator::extractProbeFactor
static uint32_t extractProbeFactor(uint32_t Value)
Definition: PseudoProbe.h:70
llvm::PseudoProbeType
PseudoProbeType
Definition: PseudoProbe.h:28
llvm::PseudoProbeDwarfDiscriminator::packProbeData
static uint32_t packProbeData(uint32_t Index, uint32_t Type, uint32_t Flags, uint32_t Factor)
Definition: PseudoProbe.h:48
llvm::PseudoProbe::Id
uint32_t Id
Definition: PseudoProbe.h:79
llvm::PseudoProbeType::IndirectCall
@ IndirectCall
llvm::PseudoProbeDescMetadataName
constexpr const char * PseudoProbeDescMetadataName
Definition: PseudoProbe.h:26
llvm::Instruction
Definition: Instruction.h:45
llvm::setProbeDistributionFactor
void setProbeDistributionFactor(Instruction &Inst, float Factor)
Definition: PseudoProbe.cpp:65
llvm::PseudoProbe::Type
uint32_t Type
Definition: PseudoProbe.h:80
Index
uint32_t Index
Definition: ELFObjHandler.cpp:84
uint64_t
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::ISD::BasicBlock
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:71
llvm::PseudoProbeDwarfDiscriminator::extractProbeIndex
static uint32_t extractProbeIndex(uint32_t Value)
Definition: PseudoProbe.h:58
uint32_t
llvm::extractProbe
Optional< PseudoProbe > extractProbe(const Instruction &Inst)
Definition: PseudoProbe.cpp:48
llvm::PseudoProbeType::Block
@ Block
llvm::PseudoProbeDwarfDiscriminator
Definition: PseudoProbe.h:38
llvm::PseudoProbeAttributes::Reserved
@ Reserved
llvm::max
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:340
llvm::PseudoProbe
Definition: PseudoProbe.h:78
llvm::PseudoProbe::Attr
uint32_t Attr
Definition: PseudoProbe.h:81
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::PseudoProbeType::DirectCall
@ DirectCall