LLVM  13.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  Dangling = 0x2, // The probe is dangling.
33 };
34 
35 // The saturated distrution factor representing 100% for block probes.
36 constexpr static uint64_t PseudoProbeFullDistributionFactor =
38 
40 public:
41  // The following APIs encodes/decodes per-probe information to/from a
42  // 32-bit integer which is organized as:
43  // [2:0] - 0x7, this is reserved for regular discriminator,
44  // see DWARF discriminator encoding rule
45  // [18:3] - probe id
46  // [25:19] - probe distribution factor
47  // [28:26] - probe type, see PseudoProbeType
48  // [31:29] - reserved for probe attributes
50  uint32_t Factor) {
51  assert(Index <= 0xFFFF && "Probe index too big to encode, exceeding 2^16");
52  assert(Type <= 0x7 && "Probe type too big to encode, exceeding 7");
53  assert(Flags <= 0x7);
54  assert(Factor <= 100 &&
55  "Probe distribution factor too big to encode, exceeding 100");
56  return (Index << 3) | (Factor << 19) | (Type << 26) | 0x7;
57  }
58 
60  return (Value >> 3) & 0xFFFF;
61  }
62 
64  return (Value >> 26) & 0x7;
65  }
66 
68  return (Value >> 29) & 0x7;
69  }
70 
72  return (Value >> 19) & 0x7F;
73  }
74 
75  // The saturated distrution factor representing 100% for callsites.
76  constexpr static uint8_t FullDistributionFactor = 100;
77 };
78 
79 struct PseudoProbe {
83  float Factor;
84 
85  bool isDangling() const {
87  }
88 };
89 
90 Optional<PseudoProbe> extractProbe(const Instruction &Inst);
91 
92 void setProbeDistributionFactor(Instruction &Inst, float Factor);
93 
94 bool moveAndDanglePseudoProbes(BasicBlock *From, Instruction *To);
95 
97 } // end namespace llvm
98 
99 #endif // LLVM_IR_PSEUDOPROBE_H
llvm::PseudoProbeFullDistributionFactor
constexpr static uint64_t PseudoProbeFullDistributionFactor
Definition: PseudoProbe.h:36
llvm::PseudoProbeDwarfDiscriminator::extractProbeAttributes
static uint32_t extractProbeAttributes(uint32_t Value)
Definition: PseudoProbe.h:67
llvm
Definition: AllocatorList.h:23
llvm::moveAndDanglePseudoProbes
bool moveAndDanglePseudoProbes(BasicBlock *From, Instruction *To)
A block emptied (i.e., with all instructions moved out of it) won't be sampled at run time.
Definition: PseudoProbe.cpp:120
llvm::PseudoProbeDwarfDiscriminator::FullDistributionFactor
constexpr static uint8_t FullDistributionFactor
Definition: PseudoProbe.h:76
Optional.h
llvm::PseudoProbeDwarfDiscriminator::extractProbeType
static uint32_t extractProbeType(uint32_t Value)
Definition: PseudoProbe.h:63
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:46
llvm::PseudoProbeAttributes
PseudoProbeAttributes
Definition: PseudoProbe.h:30
llvm::PseudoProbe::Factor
float Factor
Definition: PseudoProbe.h:83
llvm::PseudoProbeDwarfDiscriminator::extractProbeFactor
static uint32_t extractProbeFactor(uint32_t Value)
Definition: PseudoProbe.h:71
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:49
llvm::PseudoProbe::Id
uint32_t Id
Definition: PseudoProbe.h:80
llvm::PseudoProbeType::IndirectCall
@ IndirectCall
llvm::PseudoProbeAttributes::Dangling
@ Dangling
llvm::PseudoProbeDescMetadataName
constexpr const char * PseudoProbeDescMetadataName
Definition: PseudoProbe.h:26
llvm::setProbeDistributionFactor
void setProbeDistributionFactor(Instruction &Inst, float Factor)
Definition: PseudoProbe.cpp:65
llvm::removeRedundantPseudoProbes
bool removeRedundantPseudoProbes(BasicBlock *Block)
Same dangling probes in one blocks are redundant since they all have the same semantic that is to rel...
Definition: PseudoProbe.cpp:139
llvm::PseudoProbe::Type
uint32_t Type
Definition: PseudoProbe.h:81
Index
uint32_t Index
Definition: ELFObjHandler.cpp:84
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::ISD::BasicBlock
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:64
llvm::PseudoProbeDwarfDiscriminator::extractProbeIndex
static uint32_t extractProbeIndex(uint32_t Value)
Definition: PseudoProbe.h:59
llvm::PseudoProbe::isDangling
bool isDangling() const
Definition: PseudoProbe.h:85
uint32_t
llvm::extractProbe
Optional< PseudoProbe > extractProbe(const Instruction &Inst)
Definition: PseudoProbe.cpp:48
llvm::PseudoProbeType::Block
@ Block
llvm::PseudoProbeDwarfDiscriminator
Definition: PseudoProbe.h:39
llvm::PseudoProbeAttributes::Reserved
@ Reserved
llvm::max
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:340
llvm::PseudoProbe
Definition: PseudoProbe.h:79
llvm::PseudoProbe::Attr
uint32_t Attr
Definition: PseudoProbe.h:82
From
BlockVerifier::State From
Definition: BlockVerifier.cpp:55
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::PseudoProbeType::DirectCall
@ DirectCall