aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Instrumentation
diff options
context:
space:
mode:
authorTeresa Johnson <tejohnson@google.com>2025-12-19 08:24:59 -0800
committerGitHub <noreply@github.com>2025-12-19 08:24:59 -0800
commitfd402bb2dff58dd41a478ca4ca899e6bbfa87cd7 (patch)
tree8232a1e40b61a9e82ecdb99c4c1be64e1fb1d93c /llvm/lib/Transforms/Instrumentation
parent99d63c64f8e8e63068ebfd2b1f792f6abfae7fed (diff)
downloadllvm-fd402bb2dff58dd41a478ca4ca899e6bbfa87cd7.tar.gz
llvm-fd402bb2dff58dd41a478ca4ca899e6bbfa87cd7.tar.bz2
llvm-fd402bb2dff58dd41a478ca4ca899e6bbfa87cd7.zip
[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.
Diffstat (limited to 'llvm/lib/Transforms/Instrumentation')
-rw-r--r--llvm/lib/Transforms/Instrumentation/MemProfUse.cpp10
1 files changed, 8 insertions, 2 deletions
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<Frame> FrameSlice = ArrayRef<Frame>(CS.Frames).drop_front(Idx++);
- ArrayRef<GlobalValue::GUID> 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<GlobalValue::GUID>(
+ CS.Frames[Idx - 2].Function))});
ProfileHasColumns |= StackFrame.Column;
// Once we find this function, we can stop recording.