Skip to content

Commit 113b2d7

Browse files
[MemProf] Add remarks for matched allocs and calls (#170379)
The new remarks are somewhat equivalent to the -memprof-print-match-info messages, however, are not deduplicated across the module so will be generally more verbose.
1 parent 8d57635 commit 113b2d7

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

llvm/lib/Transforms/Instrumentation/MemProfUse.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,15 @@ handleAllocSite(Instruction &I, CallBase *CI,
454454
InlinedCallStack.size())] = {
455455
AllocInfo->Info.getTotalSize(), AllocType};
456456
}
457+
ORE.emit(
458+
OptimizationRemark(DEBUG_TYPE, "MemProfUse", CI)
459+
<< ore::NV("AllocationCall", CI) << " in function "
460+
<< ore::NV("Caller", CI->getFunction())
461+
<< " matched alloc context with alloc type "
462+
<< ore::NV("Attribute", getAllocTypeAttributeString(AllocType))
463+
<< " total size " << ore::NV("Size", AllocInfo->Info.getTotalSize())
464+
<< " full context id " << ore::NV("Context", FullStackId)
465+
<< " frame count " << ore::NV("Frames", InlinedCallStack.size()));
457466
}
458467
}
459468
// If the threshold for the percent of cold bytes is less than 100%,
@@ -516,7 +525,8 @@ static void handleCallSite(
516525
Instruction &I, const Function *CalledFunction,
517526
ArrayRef<uint64_t> InlinedCallStack,
518527
const std::unordered_set<CallSiteEntry, CallSiteEntryHash> &CallSiteEntries,
519-
Module &M, std::set<std::vector<uint64_t>> &MatchedCallSites) {
528+
Module &M, std::set<std::vector<uint64_t>> &MatchedCallSites,
529+
OptimizationRemarkEmitter &ORE) {
520530
auto &Ctx = M.getContext();
521531
for (const auto &CallSiteEntry : CallSiteEntries) {
522532
// If we found and thus matched all frames on the call, create and
@@ -539,6 +549,11 @@ static void handleCallSite(
539549
append_range(CallStack, InlinedCallStack);
540550
MatchedCallSites.insert(std::move(CallStack));
541551
}
552+
ORE.emit(OptimizationRemark(DEBUG_TYPE, "MemProfUse", &I)
553+
<< ore::NV("CallSite", &I) << " in function "
554+
<< ore::NV("Caller", I.getFunction())
555+
<< " matched callsite with frame count "
556+
<< ore::NV("Frames", InlinedCallStack.size()));
542557
break;
543558
}
544559
}
@@ -719,7 +734,7 @@ static void readMemprof(Module &M, Function &F,
719734
// instruction's leaf location in the callsites map and not the
720735
// allocation map.
721736
handleCallSite(I, CalledFunction, InlinedCallStack,
722-
CallSitesIter->second, M, MatchedCallSites);
737+
CallSitesIter->second, M, MatchedCallSites, ORE);
723738
}
724739
}
725740
}

llvm/test/Transforms/PGOProfile/memprof-dump-matched-alloc-site.ll

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
; REQUIRES: x86_64-linux
2727
; RUN: split-file %s %t
2828
; RUN: llvm-profdata merge %t/memprof-dump-matched-alloc-site.yaml -o %t/memprof-dump-matched-alloc-site.memprofdata
29-
; RUN: opt < %t/memprof-dump-matched-alloc-site.ll -passes='memprof-use<profile-filename=%t/memprof-dump-matched-alloc-site.memprofdata>' -memprof-print-match-info -S 2>&1 | FileCheck %s
29+
; RUN: opt < %t/memprof-dump-matched-alloc-site.ll -passes='memprof-use<profile-filename=%t/memprof-dump-matched-alloc-site.memprofdata>' -memprof-print-match-info -S -pass-remarks=memprof 2>&1 | FileCheck %s
3030

3131
;--- memprof-dump-matched-alloc-site.yaml
3232
---
@@ -77,6 +77,13 @@ HeapProfileRecords:
7777
# Kept empty here because this section is irrelevant for this test.
7878
...
7979
;--- memprof-dump-matched-alloc-site.ll
80+
81+
;; From -pass-remarks=memprof
82+
; CHECK: remark: memprof-dump-matched-alloc-site.cc:1:21: call in function _Z2f1v matched alloc context with alloc type notcold total size 3 full context id 5736731103568718490 frame count 1
83+
; CHECK: remark: memprof-dump-matched-alloc-site.cc:1:21: call in function _Z2f2v matched alloc context with alloc type notcold total size 3 full context id 5736731103568718490 frame count 2
84+
; CHECK: remark: memprof-dump-matched-alloc-site.cc:1:21: call in function _Z2f3v matched alloc context with alloc type notcold total size 3 full context id 5736731103568718490 frame count 3
85+
86+
;; From -memprof-print-match-info
8087
; CHECK: MemProf notcold context with id 5736731103568718490 has total profiled size 3 is matched with 1 frames
8188
; CHECK: MemProf notcold context with id 5736731103568718490 has total profiled size 3 is matched with 2 frames
8289
; CHECK: MemProf notcold context with id 5736731103568718490 has total profiled size 3 is matched with 3 frames

llvm/test/Transforms/PGOProfile/memprof-dump-matched-call-sites.ll

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
; REQUIRES: x86_64-linux
3535
; RUN: split-file %s %t
3636
; RUN: llvm-profdata merge %t/memprof-dump-matched-call-site.yaml -o %t/memprof-dump-matched-call-site.memprofdata
37-
; RUN: opt < %t/memprof-dump-matched-call-site.ll -passes='memprof-use<profile-filename=%t/memprof-dump-matched-call-site.memprofdata>' -memprof-print-match-info -S 2>&1 | FileCheck %s
37+
; RUN: opt < %t/memprof-dump-matched-call-site.ll -passes='memprof-use<profile-filename=%t/memprof-dump-matched-call-site.memprofdata>' -memprof-print-match-info -S -pass-remarks=memprof 2>&1 | FileCheck %s
3838

3939
;--- memprof-dump-matched-call-site.yaml
4040
---
@@ -71,6 +71,12 @@ HeapProfileRecords:
7171
CallSites: []
7272
...
7373
;--- memprof-dump-matched-call-site.ll
74+
75+
;; From -pass-remarks=memprof
76+
; CHECK: remark: match.cc:18:3: call in function main matched callsite with frame count 1
77+
; CHECK: remark: match.cc:13:28: call in function _ZL2f1v matched callsite with frame count 2
78+
79+
;; From -memprof-print-match-info
7480
; CHECK: MemProf notcold context with id 3894143216621363392 has total profiled size 4 is matched with 1 frames
7581
; CHECK: MemProf callsite match for inline call stack 4745611964195289084 10616861955219347331
7682
; CHECK: MemProf callsite match for inline call stack 5401059281181789382

0 commit comments

Comments
 (0)