diff --git a/llvm/tools/llvm-profgen/ProfileGenerator.cpp b/llvm/tools/llvm-profgen/ProfileGenerator.cpp --- a/llvm/tools/llvm-profgen/ProfileGenerator.cpp +++ b/llvm/tools/llvm-profgen/ProfileGenerator.cpp @@ -667,7 +667,7 @@ continue; do { - const SampleContextFrameVector &FrameVec = + const SampleContextFrameVector FrameVec = Binary->getFrameLocationStack(IP.Address); if (!FrameVec.empty()) { // FIXME: As accumulating total count per instruction caused some @@ -709,7 +709,7 @@ continue; // Record called target sample and its count. const SampleContextFrameVector &FrameVec = - Binary->getFrameLocationStack(SourceAddress); + Binary->getCachedFrameLocationStack(SourceAddress); if (!FrameVec.empty()) { FunctionSamples &FunctionProfile = getLeafProfileAndAddTotalSamples(FrameVec, 0); diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.h b/llvm/tools/llvm-profgen/ProfiledBinary.h --- a/llvm/tools/llvm-profgen/ProfiledBinary.h +++ b/llvm/tools/llvm-profgen/ProfiledBinary.h @@ -477,18 +477,24 @@ // Load the symbols from debug table and populate into symbol list. void populateSymbolListFromDWARF(ProfileSymbolList &SymbolList); - const SampleContextFrameVector & + SampleContextFrameVector getFrameLocationStack(uint64_t Address, bool UseProbeDiscriminator = false) { + InstructionPointer IP(this, Address); + return symbolize(IP, true, UseProbeDiscriminator); + } + + const SampleContextFrameVector & + getCachedFrameLocationStack(uint64_t Address, + bool UseProbeDiscriminator = false) { auto I = AddressToLocStackMap.emplace(Address, SampleContextFrameVector()); if (I.second) { - InstructionPointer IP(this, Address); - I.first->second = symbolize(IP, true, UseProbeDiscriminator); + I.first->second = getFrameLocationStack(Address, UseProbeDiscriminator); } return I.first->second; } - Optional getInlineLeafFrameLoc(uint64_t Address) { - const auto &Stack = getFrameLocationStack(Address); + Optional getInlineLeafFrameLoc(uint64_t Offset) { + const auto &Stack = getCachedFrameLocationStack(Offset); if (Stack.empty()) return {}; return Stack.back(); diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.cpp b/llvm/tools/llvm-profgen/ProfiledBinary.cpp --- a/llvm/tools/llvm-profgen/ProfiledBinary.cpp +++ b/llvm/tools/llvm-profgen/ProfiledBinary.cpp @@ -233,8 +233,10 @@ } bool ProfiledBinary::inlineContextEqual(uint64_t Address1, uint64_t Address2) { - const SampleContextFrameVector &Context1 = getFrameLocationStack(Address1); - const SampleContextFrameVector &Context2 = getFrameLocationStack(Address2); + const SampleContextFrameVector &Context1 = + getCachedFrameLocationStack(Address1); + const SampleContextFrameVector &Context2 = + getCachedFrameLocationStack(Address2); if (Context1.size() != Context2.size()) return false; if (Context1.empty()) @@ -254,7 +256,7 @@ // Process from frame root to leaf for (auto Address : Stack) { const SampleContextFrameVector &ExpandedContext = - getFrameLocationStack(Address); + getCachedFrameLocationStack(Address); // An instruction without a valid debug line will be ignored by sample // processing if (ExpandedContext.empty()) @@ -806,10 +808,9 @@ return; do { - const SampleContextFrameVector &SymbolizedCallStack = + const SampleContextFrameVector SymbolizedCallStack = getFrameLocationStack(IP.Address, UsePseudoProbes); uint64_t Size = AddressToInstSizeMap[IP.Address]; - // Record instruction size for the corresponding context FuncSizeTracker.addInstructionForContext(SymbolizedCallStack, Size);