[llvm] [MemProf] Attach value profile metadata to the IR using CalleeGuids. (PR #141164)
Snehasish Kumar via llvm-commits
llvm-commits at lists.llvm.org
Fri May 30 12:02:25 PDT 2025
================
@@ -1209,6 +1209,41 @@ readMemprof(Module &M, Function &F, IndexedInstrProfReader *MemProfReader,
InlinedCallStack)) {
NumOfMemProfMatchedCallSites++;
addCallsiteMetadata(I, InlinedCallStack, Ctx);
+
+ // Check if this is an indirect call and we have GUID information
+ // from CallSiteInfo to attach value profile metadata
+ if (!CalledFunction) {
+ // This is an indirect call, look for CallSites with matching stacks
+ // that have CalleeGuids information
+ for (auto &CS : MemProfRec->CallSites) {
+ if (!CS.CalleeGuids.empty() && stackFrameIncludesInlinedCallStack(
+ CS.Frames, InlinedCallStack)) {
+ // Create value profile data from the CalleeGuids
+ SmallVector<InstrProfValueData, 4> VDs;
+ uint64_t TotalCount = 0;
+
+ for (GlobalValue::GUID CalleeGUID : CS.CalleeGuids) {
+ // For MemProf, we don't have actual call counts, so we assign
+ // a weight of 1 to each potential target. This provides the
+ // information needed for indirect call promotion without
+ // specific count data.
+ InstrProfValueData VD;
+ VD.Value = CalleeGUID;
+ VD.Count = 1; // Weight for ICP decision making
+ VDs.push_back(VD);
+ TotalCount += VD.Count;
+ }
+
+ if (!VDs.empty()) {
+ // Attach value profile metadata for indirect call targets
+ annotateValueSite(M, I, VDs, TotalCount,
----------------
snehasish wrote:
For now I've changed the code to only attach if there is none. My guess was that we would see instr profile info applied after memprofuse? This is conservative for now. We can handle more sophisticated merging in the future if we need to.
https://github.com/llvm/llvm-project/pull/141164
More information about the llvm-commits
mailing list