diff --git a/llvm/include/llvm/MC/MCPseudoProbe.h b/llvm/include/llvm/MC/MCPseudoProbe.h --- a/llvm/include/llvm/MC/MCPseudoProbe.h +++ b/llvm/include/llvm/MC/MCPseudoProbe.h @@ -385,7 +385,7 @@ void getInlineContextForProbe(const MCDecodedPseudoProbe *Probe, SmallVectorImpl &InlineContextStack, - bool IncludeLeaf) const; + bool UseMD5, bool IncludeLeaf) const; const AddressProbesMap &getAddress2ProbesMap() const { return Address2ProbesMap; diff --git a/llvm/lib/MC/MCPseudoProbe.cpp b/llvm/lib/MC/MCPseudoProbe.cpp --- a/llvm/lib/MC/MCPseudoProbe.cpp +++ b/llvm/lib/MC/MCPseudoProbe.cpp @@ -555,15 +555,24 @@ void MCPseudoProbeDecoder::getInlineContextForProbe( const MCDecodedPseudoProbe *Probe, - SmallVectorImpl &InlineContextStack, bool IncludeLeaf) const { - Probe->getInlineContext(InlineContextStack, GUID2FuncDescMap, true); + SmallVectorImpl &InlineContextStack, bool UseMD5, + bool IncludeLeaf) const { + Probe->getInlineContext(InlineContextStack, GUID2FuncDescMap, !UseMD5); if (!IncludeLeaf) return; + // Note that the context from probe doesn't include leaf frame, // hence we need to retrieve and prepend leaf if requested. - const auto *FuncDesc = getFuncDescForGUID(Probe->getGuid()); - InlineContextStack.emplace_back(FuncDesc->FuncName + ":" + - Twine(Probe->getIndex()).str()); + std::string LeafFrame; + if (UseMD5) { + LeafFrame = Twine(Probe->getGuid()).str(); + } else { + const auto *FuncDesc = getFuncDescForGUID(Probe->getGuid()); + LeafFrame = FuncDesc->FuncName; + } + LeafFrame += ":" + Twine(Probe->getIndex()).str(); + + InlineContextStack.emplace_back(LeafFrame); } const MCPseudoProbeFuncDesc *MCPseudoProbeDecoder::getInlinerDescForProbe( diff --git a/llvm/tools/llvm-profgen/PerfReader.cpp b/llvm/tools/llvm-profgen/PerfReader.cpp --- a/llvm/tools/llvm-profgen/PerfReader.cpp +++ b/llvm/tools/llvm-profgen/PerfReader.cpp @@ -25,6 +25,7 @@ extern cl::opt ShowDisassemblyOnly; extern cl::opt ShowSourceLocations; +extern cl::opt UseMD5; namespace llvm { namespace sampleprof { @@ -425,7 +426,7 @@ } else if (const auto *CtxKey = dyn_cast(K)) { SmallVector ContextStack; for (const auto *Probe : CtxKey->Probes) { - Binary->getInlineContextForProbe(Probe, ContextStack, true); + Binary->getInlineContextForProbe(Probe, ContextStack, UseMD5, true); } for (const auto &Context : ContextStack) { if (ContextStr.size()) 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 @@ -452,7 +452,7 @@ const SmallVectorImpl &Probes, ProfiledBinary *Binary) { for (const auto *P : Probes) { - Binary->getInlineContextForProbe(P, ContextStrStack, true); + Binary->getInlineContextForProbe(P, ContextStrStack, UseMD5, true); } } @@ -646,7 +646,8 @@ // Explicitly copy the context for appending the leaf context SmallVector ContextStrStackCopy(ContextStrStack.begin(), ContextStrStack.end()); - Binary->getInlineContextForProbe(LeafProbe, ContextStrStackCopy, true); + Binary->getInlineContextForProbe(LeafProbe, ContextStrStackCopy, UseMD5, + true); const auto *FuncDesc = Binary->getFuncDescForGUID(LeafProbe->getGuid()); bool WasLeafInlined = LeafProbe->getInlineTreeNode()->hasInlineSite(); return getFunctionProfileForLeafProbe(ContextStrStackCopy, FuncDesc, 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 @@ -272,9 +272,9 @@ void getInlineContextForProbe(const MCDecodedPseudoProbe *Probe, SmallVectorImpl &InlineContextStack, - bool IncludeLeaf = false) const { + bool UseMD5, bool IncludeLeaf = false) const { return ProbeDecoder.getInlineContextForProbe(Probe, InlineContextStack, - IncludeLeaf); + UseMD5, IncludeLeaf); } const AddressProbesMap &getAddress2ProbesMap() const { return ProbeDecoder.getAddress2ProbesMap();