From f39256e3a5dd1f3d7311703003608340ffdb42bc Mon Sep 17 00:00:00 2001 From: Hongtao Yu Date: Wed, 25 Aug 2021 11:57:48 -0700 Subject: [PATCH] [CSSPGO] Avoid repeatedly computing md5 hash code for pseudo probe inline contexts. Md5 hashing is expansive. Using a hash map to look up already computed GUID for dwarf names. Saw a 2% build time improvement on an internal large application. Reviewed By: wenlei Differential Revision: https://reviews.llvm.org/D108722 --- llvm/lib/CodeGen/AsmPrinter/PseudoProbePrinter.cpp | 7 ++++++- llvm/lib/CodeGen/AsmPrinter/PseudoProbePrinter.h | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/llvm/lib/CodeGen/AsmPrinter/PseudoProbePrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/PseudoProbePrinter.cpp index 35a830f..9e6f1a5 100644 --- a/llvm/lib/CodeGen/AsmPrinter/PseudoProbePrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/PseudoProbePrinter.cpp @@ -20,6 +20,8 @@ using namespace llvm; +PseudoProbeHandler::~PseudoProbeHandler() = default; + void PseudoProbeHandler::emitPseudoProbe(uint64_t Guid, uint64_t Index, uint64_t Type, uint64_t Attr, const DILocation *DebugLoc) { @@ -35,7 +37,10 @@ void PseudoProbeHandler::emitPseudoProbe(uint64_t Guid, uint64_t Index, auto Name = SP->getLinkageName(); if (Name.empty()) Name = SP->getName(); - uint64_t CallerGuid = Function::getGUID(Name); + // Use caching to avoid redundant md5 computation for build speed. + uint64_t &CallerGuid = NameGuidMap[Name]; + if (!CallerGuid) + CallerGuid = Function::getGUID(Name); uint64_t CallerProbeId = PseudoProbeDwarfDiscriminator::extractProbeIndex( InlinedAt->getDiscriminator()); ReversedInlineStack.emplace_back(CallerGuid, CallerProbeId); diff --git a/llvm/lib/CodeGen/AsmPrinter/PseudoProbePrinter.h b/llvm/lib/CodeGen/AsmPrinter/PseudoProbePrinter.h index f2026a1..7d5e512 100644 --- a/llvm/lib/CodeGen/AsmPrinter/PseudoProbePrinter.h +++ b/llvm/lib/CodeGen/AsmPrinter/PseudoProbePrinter.h @@ -26,9 +26,12 @@ class DILocation; class PseudoProbeHandler : public AsmPrinterHandler { // Target of pseudo probe emission. AsmPrinter *Asm; + // Name to GUID map, used as caching/memoization for speed. + DenseMap NameGuidMap; public: PseudoProbeHandler(AsmPrinter *A) : Asm(A){}; + ~PseudoProbeHandler() override; void emitPseudoProbe(uint64_t Guid, uint64_t Index, uint64_t Type, uint64_t Attr, const DILocation *DebugLoc); -- 2.7.4