LLVM 22.0.0git
PseudoProbePrinter.cpp
Go to the documentation of this file.
1//===- llvm/CodeGen/PseudoProbePrinter.cpp - Pseudo Probe Emission -------===//
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// This file contains support for writing pseudo probe info into asm files.
10//
11//===----------------------------------------------------------------------===//
12
13#include "PseudoProbePrinter.h"
16#include "llvm/IR/Function.h"
17#include "llvm/IR/PseudoProbe.h"
19#include "llvm/MC/MCStreamer.h"
20
21#ifndef NDEBUG
22#include "llvm/IR/Module.h"
24#endif
25
26using namespace llvm;
27
30 const DILocation *DebugLoc) {
31 // Gather all the inlined-at nodes.
32 // When it's done ReversedInlineStack looks like ([66, B], [88, A])
33 // which means, Function A inlines function B at calliste with a probe id 88,
34 // and B inlines C at probe 66 where C is represented by Guid.
35 SmallVector<InlineSite, 8> ReversedInlineStack;
36 auto *InlinedAt = DebugLoc ? DebugLoc->getInlinedAt() : nullptr;
37 while (InlinedAt) {
38 auto Name = InlinedAt->getSubprogramLinkageName();
39 // Use caching to avoid redundant md5 computation for build speed.
40 uint64_t &CallerGuid = NameGuidMap[Name];
41 if (!CallerGuid)
43#ifndef NDEBUG
44 verifyGuidExistenceInDesc(CallerGuid, Name);
45#endif
47 InlinedAt->getDiscriminator());
48 ReversedInlineStack.emplace_back(CallerGuid, CallerProbeId);
49 InlinedAt = InlinedAt->getInlinedAt();
50 }
51 uint64_t Discriminator = 0;
52 // For now only block probes have FS discriminators. See
53 // MIRFSDiscriminator.cpp for more details.
56 Discriminator = DebugLoc->getDiscriminator();
57 assert((EnableFSDiscriminator || Discriminator == 0) &&
58 "Discriminator should not be set in non-FSAFDO mode");
59 SmallVector<InlineSite, 8> InlineStack(llvm::reverse(ReversedInlineStack));
60 Asm->OutStreamer->emitPseudoProbe(Guid, Index, Type, Attr, Discriminator,
61 InlineStack, Asm->CurrentFnSym);
62#ifndef NDEBUG
63 verifyGuidExistenceInDesc(
64 Guid, DebugLoc ? DebugLoc->getSubprogramLinkageName() : "");
65#endif
66}
67
68#ifndef NDEBUG
69void PseudoProbeHandler::verifyGuidExistenceInDesc(uint64_t Guid,
70 StringRef FuncName) {
73 assert(Desc && "pseudo probe does not exist");
74
75 // Keep DescGuidSet up to date.
76 for (size_t I = DescGuidSet.size(), E = Desc->getNumOperands(); I != E; ++I) {
77 const auto *MD = cast<MDNode>(Desc->getOperand(I));
78 auto *ID = mdconst::extract<ConstantInt>(MD->getOperand(0));
79 DescGuidSet.insert(ID->getZExtValue());
80 }
81
82 if (!DescGuidSet.contains(Guid))
83 WithColor::warning() << "Guid:" << Guid << " Name:" << FuncName
84 << " does not exist in pseudo probe desc\n";
85}
86#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
std::string Name
Module.h This file contains the declarations for the Module class.
#define I(x, y, z)
Definition: MD5.cpp:58
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:108
MCSymbol * CurrentFnSym
The symbol for the current function.
Definition: AsmPrinter.h:127
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:105
Debug location.
A debug info location.
Definition: DebugLoc.h:124
static LLVM_ABI GUID getGUIDAssumingExternalLinkage(StringRef GlobalName)
Return a 64-bit global unique ID constructed from the name of a global symbol.
Definition: Globals.cpp:77
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:663
Function & getFunction()
Return the LLVM function that this machine code represents.
NamedMDNode * getNamedMetadata(StringRef Name) const
Return the first NamedMDNode in the module with the specified name.
Definition: Module.cpp:295
A tuple of MDNodes.
Definition: Metadata.h:1753
void emitPseudoProbe(uint64_t Guid, uint64_t Index, uint64_t Type, uint64_t Attr, const DILocation *DebugLoc)
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:938
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
static LLVM_ABI raw_ostream & warning()
Convenience method for printing "warning: " to stderr.
Definition: WithColor.cpp:85
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:194
size_type size() const
Definition: DenseSet.h:87
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
Definition: DenseSet.h:169
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
LLVM_ABI cl::opt< bool > EnableFSDiscriminator
auto reverse(ContainerTy &&C)
Definition: STLExtras.h:428
constexpr const char * PseudoProbeDescMetadataName
Definition: PseudoProbe.h:26
Description of the encoding of one expression Op.
static uint32_t extractProbeIndex(uint32_t Value)
Definition: PseudoProbe.h:75