[PseudoProbe] Use callee name as callsite identfier for MCDecodedPseudoProbeInlineTree.

The callsite identifier used in pseudo probe encoding and decoding is consisted of a function name and the callsite probe id. For encoding, i.e., `MCPseudoProbeInlineTree`, the function name is callee function name. However for decoding, i.e., `MCDecodedPseudoProbeInlineTree`, the caller function name is used actually. This results in multiple callees that are inlined at the same callsite, likely via indirect call promotion, sharing the same decoded inline frame. While it is not a problem for profile generation, it confuses probe re-encoding in Bolt.

In Bolt, we decode pseudo probes first and build `MCDecodedPseudoProbeInlineTree`. The decoded tree is used for final re-encoding. Here comes the problem. Two inlinees from the same callsite share the same decoded inline frame. During re-encoding, the frame name (whatever inlinee comes first) will be used and encoded in the bolted binary. This will cause wrong inline contexts  in the profile generated on the bolted binary.

The fix is a no-op to pre-bolt profile generation. Some of the bolt tests are not yet upstreamed, thus I'm not adding a bolt test here.

Reviewed By: wenlei

Differential Revision: https://reviews.llvm.org/D126434
This commit is contained in:
Hongtao Yu 2022-05-25 16:30:07 -07:00
parent 6c6eddb617
commit ab34ab2b87
2 changed files with 5 additions and 6 deletions

View File

@ -85,7 +85,7 @@ struct MCPseudoProbeFuncDesc {
class MCDecodedPseudoProbe; class MCDecodedPseudoProbe;
// An inline frame has the form <Guid, ProbeID> // An inline frame has the form <CalleeGuid, ProbeID>
using InlineSite = std::tuple<uint64_t, uint32_t>; using InlineSite = std::tuple<uint64_t, uint32_t>;
using MCPseudoProbeInlineStack = SmallVector<InlineSite, 8>; using MCPseudoProbeInlineStack = SmallVector<InlineSite, 8>;
// GUID to PseudoProbeFuncDesc map // GUID to PseudoProbeFuncDesc map
@ -271,7 +271,7 @@ public:
MCDecodedPseudoProbeInlineTree(const InlineSite &Site) : ISite(Site){}; MCDecodedPseudoProbeInlineTree(const InlineSite &Site) : ISite(Site){};
// Return false if it's a dummy inline site // Return false if it's a dummy inline site
bool hasInlineSite() const { return std::get<0>(ISite) != 0; } bool hasInlineSite() const { return !isRoot() && !Parent->isRoot(); }
}; };
/// Instances of this class represent the pseudo probes inserted into a compile /// Instances of this class represent the pseudo probes inserted into a compile

View File

@ -230,8 +230,7 @@ void MCDecodedPseudoProbe::getInlineContext(
// It will add the string of each node's inline site during iteration. // It will add the string of each node's inline site during iteration.
// Note that it won't include the probe's belonging function(leaf location) // Note that it won't include the probe's belonging function(leaf location)
while (Cur->hasInlineSite()) { while (Cur->hasInlineSite()) {
StringRef FuncName = StringRef FuncName = getProbeFNameForGUID(GUID2FuncMAP, Cur->Parent->Guid);
getProbeFNameForGUID(GUID2FuncMAP, std::get<0>(Cur->ISite));
ContextStack.emplace_back( ContextStack.emplace_back(
MCPseduoProbeFrameLocation(FuncName, std::get<1>(Cur->ISite))); MCPseduoProbeFrameLocation(FuncName, std::get<1>(Cur->ISite)));
Cur = static_cast<MCDecodedPseudoProbeInlineTree *>(Cur->Parent); Cur = static_cast<MCDecodedPseudoProbeInlineTree *>(Cur->Parent);
@ -417,7 +416,7 @@ bool MCPseudoProbeDecoder::buildAddress2ProbeMap(
// If the incoming node is null, all its children nodes should be disgarded. // If the incoming node is null, all its children nodes should be disgarded.
if (Cur) { if (Cur) {
// Switch/add to a new tree node(inlinee) // Switch/add to a new tree node(inlinee)
Cur = Cur->getOrAddNode(std::make_tuple(Cur->Guid, Index)); Cur = Cur->getOrAddNode(std::make_tuple(Guid, Index));
Cur->Guid = Guid; Cur->Guid = Guid;
} }
@ -574,5 +573,5 @@ const MCPseudoProbeFuncDesc *MCPseudoProbeDecoder::getInlinerDescForProbe(
MCDecodedPseudoProbeInlineTree *InlinerNode = Probe->getInlineTreeNode(); MCDecodedPseudoProbeInlineTree *InlinerNode = Probe->getInlineTreeNode();
if (!InlinerNode->hasInlineSite()) if (!InlinerNode->hasInlineSite())
return nullptr; return nullptr;
return getFuncDescForGUID(std::get<0>(InlinerNode->ISite)); return getFuncDescForGUID(InlinerNode->Parent->Guid);
} }