From 27c37327da67020f938aabf0f6405f57d688441e Mon Sep 17 00:00:00 2001 From: Mark Santaniello Date: Thu, 25 May 2023 08:11:40 -0700 Subject: [PATCH] Avoid pointless canonicalize when using Dwarf names CPU profile indicated memcmp was hot due to the two rfind calls in getCanonicalFnName. If UseSymbolTable is false, we can avoid the cost entirely. For CSSPGO profiles I've measured ~5% speedup with this change. Profile similarity before/after matches 100%. Reviewed By: wenlei Differential Revision: https://reviews.llvm.org/D151441 --- llvm/tools/llvm-profgen/ProfiledBinary.cpp | 11 ++++++----- llvm/tools/llvm-profgen/ProfiledBinary.h | 10 ++++++---- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.cpp b/llvm/tools/llvm-profgen/ProfiledBinary.cpp index 781c61d..ebd4557 100644 --- a/llvm/tools/llvm-profgen/ProfiledBinary.cpp +++ b/llvm/tools/llvm-profgen/ProfiledBinary.cpp @@ -163,12 +163,13 @@ void BinarySizeContextTracker::trackInlineesOptimizedAway( } ProfiledBinary::ProfiledBinary(const StringRef ExeBinPath, - const StringRef DebugBinPath) - : Path(ExeBinPath), DebugBinaryPath(DebugBinPath), ProEpilogTracker(this), + const StringRef DebugBinPath) + : Path(ExeBinPath), DebugBinaryPath(DebugBinPath), + SymbolizerOpts(getSymbolizerOpts()), ProEpilogTracker(this), + Symbolizer(std::make_unique(SymbolizerOpts)), TrackFuncContextSize(EnableCSPreInliner && UseContextCostForPreInliner) { // Point to executable binary if debug info binary is not specified. SymbolizerPath = DebugBinPath.empty() ? ExeBinPath : DebugBinPath; - setupSymbolizer(); if (InferMissingFrames) MissingContextInferrer = std::make_unique(this); load(); @@ -840,7 +841,7 @@ void ProfiledBinary::populateSymbolListFromDWARF( SymbolList.add(I.second.getFuncName()); } -void ProfiledBinary::setupSymbolizer() { +symbolize::LLVMSymbolizer::Options ProfiledBinary::getSymbolizerOpts() const { symbolize::LLVMSymbolizer::Options SymbolizerOpts; SymbolizerOpts.PrintFunctions = DILineInfoSpecifier::FunctionNameKind::LinkageName; @@ -849,7 +850,7 @@ void ProfiledBinary::setupSymbolizer() { SymbolizerOpts.UseSymbolTable = false; SymbolizerOpts.RelativeAddresses = false; SymbolizerOpts.DWPName = DWPPath; - Symbolizer = std::make_unique(SymbolizerOpts); + return SymbolizerOpts; } SampleContextFrameVector ProfiledBinary::symbolize(const InstructionPointer &IP, diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.h b/llvm/tools/llvm-profgen/ProfiledBinary.h index c410b98..a6d78c6 100644 --- a/llvm/tools/llvm-profgen/ProfiledBinary.h +++ b/llvm/tools/llvm-profgen/ProfiledBinary.h @@ -190,10 +190,12 @@ class ProfiledBinary { std::string Path; // Path of the debug info binary. std::string DebugBinaryPath; - // Path of symbolizer path which should be pointed to binary with debug info. - StringRef SymbolizerPath; // The target triple. Triple TheTriple; + // Path of symbolizer path which should be pointed to binary with debug info. + StringRef SymbolizerPath; + // Options used to configure the symbolizer + symbolize::LLVMSymbolizer::Options SymbolizerOpts; // The runtime base address that the first executable segment is loaded at. uint64_t BaseAddress = 0; // The runtime base address that the first loadabe segment is loaded at. @@ -304,7 +306,7 @@ class ProfiledBinary { // Set up disassembler and related components. void setUpDisassembler(const ELFObjectFileBase *Obj); - void setupSymbolizer(); + symbolize::LLVMSymbolizer::Options getSymbolizerOpts() const; // Load debug info of subprograms from DWARF section. void loadSymbolsFromDWARF(ObjectFile &Obj); @@ -495,7 +497,7 @@ public: SampleContextFrameVector getFrameLocationStack(uint64_t Address, bool UseProbeDiscriminator = false) { InstructionPointer IP(this, Address); - return symbolize(IP, true, UseProbeDiscriminator); + return symbolize(IP, SymbolizerOpts.UseSymbolTable, UseProbeDiscriminator); } const SampleContextFrameVector & -- 2.7.4