Path: blob/main/contrib/llvm-project/llvm/lib/CodeGen/AsmPrinter/PseudoProbePrinter.cpp
35271 views
//===- llvm/CodeGen/PseudoProbePrinter.cpp - Pseudo Probe Emission -------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file contains support for writing pseudo probe info into asm files.9//10//===----------------------------------------------------------------------===//1112#include "PseudoProbePrinter.h"13#include "llvm/CodeGen/AsmPrinter.h"14#include "llvm/IR/DebugInfoMetadata.h"15#include "llvm/IR/Function.h"16#include "llvm/IR/PseudoProbe.h"17#include "llvm/MC/MCPseudoProbe.h"18#include "llvm/MC/MCStreamer.h"1920using namespace llvm;2122void PseudoProbeHandler::emitPseudoProbe(uint64_t Guid, uint64_t Index,23uint64_t Type, uint64_t Attr,24const DILocation *DebugLoc) {25// Gather all the inlined-at nodes.26// When it's done ReversedInlineStack looks like ([66, B], [88, A])27// which means, Function A inlines function B at calliste with a probe id 88,28// and B inlines C at probe 66 where C is represented by Guid.29SmallVector<InlineSite, 8> ReversedInlineStack;30auto *InlinedAt = DebugLoc ? DebugLoc->getInlinedAt() : nullptr;31while (InlinedAt) {32auto Name = InlinedAt->getSubprogramLinkageName();33// Use caching to avoid redundant md5 computation for build speed.34uint64_t &CallerGuid = NameGuidMap[Name];35if (!CallerGuid)36CallerGuid = Function::getGUID(Name);37uint64_t CallerProbeId = PseudoProbeDwarfDiscriminator::extractProbeIndex(38InlinedAt->getDiscriminator());39ReversedInlineStack.emplace_back(CallerGuid, CallerProbeId);40InlinedAt = InlinedAt->getInlinedAt();41}42uint64_t Discriminator = 0;43// For now only block probes have FS discriminators. See44// MIRFSDiscriminator.cpp for more details.45if (EnableFSDiscriminator && DebugLoc &&46(Type == (uint64_t)PseudoProbeType::Block))47Discriminator = DebugLoc->getDiscriminator();48assert((EnableFSDiscriminator || Discriminator == 0) &&49"Discriminator should not be set in non-FSAFDO mode");50SmallVector<InlineSite, 8> InlineStack(llvm::reverse(ReversedInlineStack));51Asm->OutStreamer->emitPseudoProbe(Guid, Index, Type, Attr, Discriminator,52InlineStack, Asm->CurrentFnSym);53}545556