LLVM  14.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/Module.h"
17 #include "llvm/IR/PseudoProbe.h"
18 #include "llvm/MC/MCPseudoProbe.h"
19 #include "llvm/MC/MCStreamer.h"
20 
21 using namespace llvm;
22 
24 
26  uint64_t Type, uint64_t Attr,
27  const DILocation *DebugLoc) {
28  // Gather all the inlined-at nodes.
29  // When it's done ReversedInlineStack looks like ([66, B], [88, A])
30  // which means, Function A inlines function B at calliste with a probe id 88,
31  // and B inlines C at probe 66 where C is represented by Guid.
32  SmallVector<InlineSite, 8> ReversedInlineStack;
33  auto *InlinedAt = DebugLoc ? DebugLoc->getInlinedAt() : nullptr;
34  while (InlinedAt) {
35  const DISubprogram *SP = InlinedAt->getScope()->getSubprogram();
36  // Use linkage name for C++ if possible.
37  auto Name = SP->getLinkageName();
38  if (Name.empty())
39  Name = SP->getName();
40  // Use caching to avoid redundant md5 computation for build speed.
41  uint64_t &CallerGuid = NameGuidMap[Name];
42  if (!CallerGuid)
43  CallerGuid = Function::getGUID(Name);
45  InlinedAt->getDiscriminator());
46  ReversedInlineStack.emplace_back(CallerGuid, CallerProbeId);
47  InlinedAt = InlinedAt->getInlinedAt();
48  }
49 
50  SmallVector<InlineSite, 8> InlineStack(ReversedInlineStack.rbegin(),
51  ReversedInlineStack.rend());
52  Asm->OutStreamer->emitPseudoProbe(Guid, Index, Type, Attr, InlineStack);
53 }
AsmPrinter.h
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
PseudoProbePrinter.h
DebugInfoMetadata.h
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
llvm::DIScope::getName
StringRef getName() const
Definition: DebugInfoMetadata.cpp:261
llvm::DILocation
Debug location.
Definition: DebugInfoMetadata.h:1580
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
Module.h
MCPseudoProbe.h
llvm::AsmPrinter::OutStreamer
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:97
llvm::PseudoProbeHandler::~PseudoProbeHandler
~PseudoProbeHandler() override
Index
uint32_t Index
Definition: ELFObjHandler.cpp:84
uint64_t
llvm::PseudoProbeDwarfDiscriminator::extractProbeIndex
static uint32_t extractProbeIndex(uint32_t Value)
Definition: PseudoProbe.h:54
llvm::DIScope::getScope
DIScope * getScope() const
Definition: DebugInfoMetadata.cpp:237
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::GlobalValue::getGUID
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
Definition: GlobalValue.h:517
PseudoProbe.h
llvm::PseudoProbeHandler::emitPseudoProbe
void emitPseudoProbe(uint64_t Guid, uint64_t Index, uint64_t Type, uint64_t Attr, const DILocation *DebugLoc)
Definition: PseudoProbePrinter.cpp:25
MCStreamer.h
llvm::DISubprogram
Subprogram description.
Definition: DebugInfoMetadata.h:1820
llvm::DebugLoc
A debug info location.
Definition: DebugLoc.h:33
llvm::SmallVectorImpl::emplace_back
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:908