From fd402bb2dff58dd41a478ca4ca899e6bbfa87cd7 Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Fri, 19 Dec 2025 08:24:59 -0800 Subject: [MemProf] Fix callee guid for non-leaf frame (#172502) When matching callsite profile info, we synthesize VP metadata for matched indirect calls from the CalleeGuids recorded with the CallSite profile info. However, those are the callee guids of the leaf-most frame in the callsite. In cases where we match to a portion of the frames, not including the leaf, the callee guid should instead be synthesized from the next leaf-most frame in the list. This addresses the case where indirect call promotion was applied in the profiled binary during SamplePGO matching in a ThinLTO backend, where we didn't have VP metadata. --- llvm/lib/Transforms/Instrumentation/MemProfUse.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'llvm/lib/Transforms/Instrumentation/MemProfUse.cpp') diff --git a/llvm/lib/Transforms/Instrumentation/MemProfUse.cpp b/llvm/lib/Transforms/Instrumentation/MemProfUse.cpp index 5cde52637248..1a55021c5d3f 100644 --- a/llvm/lib/Transforms/Instrumentation/MemProfUse.cpp +++ b/llvm/lib/Transforms/Instrumentation/MemProfUse.cpp @@ -702,8 +702,14 @@ readMemprof(Module &M, Function &F, IndexedInstrProfReader *MemProfReader, for (auto &StackFrame : CS.Frames) { uint64_t StackId = computeStackId(StackFrame); ArrayRef FrameSlice = ArrayRef(CS.Frames).drop_front(Idx++); - ArrayRef CalleeGuids(CS.CalleeGuids); - LocHashToCallSites[StackId].push_back({FrameSlice, CalleeGuids}); + // The callee guids for the slice containing all frames (due to the + // increment above Idx is now 1) comes from the CalleeGuids recorded in + // the CallSite. For the slices not containing the leaf-most frame, the + // callee guid is simply the function GUID of the prior frame. + LocHashToCallSites[StackId].push_back( + {FrameSlice, (Idx == 1 ? CS.CalleeGuids + : ArrayRef( + CS.Frames[Idx - 2].Function))}); ProfileHasColumns |= StackFrame.Column; // Once we find this function, we can stop recording. -- cgit v1.2.3