1 //===- llvm/CodeGen/PseudoProbePrinter.cpp - Pseudo Probe Emission -------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file contains support for writing pseudo probe info into asm files.
11 //===----------------------------------------------------------------------===//
13 #include "PseudoProbePrinter.h"
14 #include "llvm/CodeGen/AsmPrinter.h"
15 #include "llvm/IR/DebugInfoMetadata.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"
23 void PseudoProbeHandler::emitPseudoProbe(uint64_t Guid
, uint64_t Index
,
24 uint64_t Type
, uint64_t Attr
,
25 const DILocation
*DebugLoc
) {
26 // Gather all the inlined-at nodes.
27 // When it's done ReversedInlineStack looks like ([66, B], [88, A])
28 // which means, Function A inlines function B at calliste with a probe id 88,
29 // and B inlines C at probe 66 where C is represented by Guid.
30 SmallVector
<InlineSite
, 8> ReversedInlineStack
;
31 auto *InlinedAt
= DebugLoc
? DebugLoc
->getInlinedAt() : nullptr;
33 const DISubprogram
*SP
= InlinedAt
->getScope()->getSubprogram();
34 // Use linkage name for C++ if possible.
35 auto Name
= SP
->getLinkageName();
38 uint64_t CallerGuid
= Function::getGUID(Name
);
39 uint64_t CallerProbeId
= PseudoProbeDwarfDiscriminator::extractProbeIndex(
40 InlinedAt
->getDiscriminator());
41 ReversedInlineStack
.emplace_back(CallerGuid
, CallerProbeId
);
42 InlinedAt
= InlinedAt
->getInlinedAt();
45 SmallVector
<InlineSite
, 8> InlineStack(ReversedInlineStack
.rbegin(),
46 ReversedInlineStack
.rend());
47 Asm
->OutStreamer
->emitPseudoProbe(Guid
, Index
, Type
, Attr
, InlineStack
);