Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions llvm/lib/Transforms/Instrumentation/MemProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: remove braces around single line body

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

// 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,
IPVK_IndirectCallTarget, VDs.size());
}
break;
}
}
}

// Only need to find one with a matching call stack and add a single
// callsite metadata.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
; Make sure that we can ingest the MemProf profile in YAML with CalleeGuids
; and annotate an indirect call with value profile metadata.

; RUN: split-file %s %t
; RUN: llvm-profdata merge --memprof-version=4 %t/memprof_annotate_indirect_call_yaml.yaml -o %t/memprof_annotate_indirect_call_yaml.memprofdata
; RUN: opt < %t/memprof_annotate_indirect_call_yaml.ll -passes='memprof-use<profile-filename=%t/memprof_annotate_indirect_call_yaml.memprofdata>' -S 2>&1 | FileCheck %s

;--- memprof_annotate_indirect_call_yaml.yaml
---
HeapProfileRecords:
- GUID: _Z3barv
AllocSites: []
CallSites:
- Frames:
- { Function: _Z3barv, LineOffset: 3, Column: 5, IsInlineFrame: false }
CalleeGuids: [0x123456789abcdef0, 0x23456789abcdef01]
...
;--- memprof_annotate_indirect_call_yaml.ll
define dso_local void @_Z3barv() !dbg !4 {
entry:
%fp = alloca ptr, align 8
%0 = load ptr, ptr %fp, align 8
call void %0(), !dbg !5
; CHECK: call void %0(), {{.*}} !prof ![[PROF:[0-9]+]]
ret void
}

; CHECK: ![[PROF]] = !{!"VP", i32 0, i64 2, i64 1311768467463790320, i64 1, i64 2541551405711093505, i64 1}

!llvm.module.flags = !{!2, !3}

!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1)
!1 = !DIFile(filename: "t", directory: "/")
!2 = !{i32 7, !"Dwarf Version", i32 5}
!3 = !{i32 2, !"Debug Info Version", i32 3}
!4 = distinct !DISubprogram(name: "bar", linkageName: "_Z3barv", scope: !1, file: !1, line: 1, unit: !0)
!5 = !DILocation(line: 4, column: 5, scope: !4)