aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
diff options
context:
space:
mode:
authorTeresa Johnson <tejohnson@google.com>2024-11-15 08:24:44 -0800
committerGitHub <noreply@github.com>2024-11-15 08:24:44 -0800
commit9513f2fdf2ad50f55726154a6b6a4aa463bc457f (patch)
tree738757d593af34a24cc6fddb5c3881386b6f9bd0 /llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
parentf6e1d64458130643377511baeec430de67ddddfb (diff)
downloadllvm-9513f2fdf2ad50f55726154a6b6a4aa463bc457f.zip
llvm-9513f2fdf2ad50f55726154a6b6a4aa463bc457f.tar.gz
llvm-9513f2fdf2ad50f55726154a6b6a4aa463bc457f.tar.bz2
[MemProf] Print full context hash when reporting hinted bytes (#114465)
Improve the information printed when -memprof-report-hinted-sizes is enabled. Now print the full context hash computed from the original profile, similar to what we do when reporting matching statistics. This will make it easier to correlate with the profile. Note that the full context hash must be computed at profile match time and saved in the metadata and summary, because we may trim the context during matching when it isn't needed for distinguishing hotness. Similarly, due to the context trimming, we may have more than one full context id and total size pair per MIB in the metadata and summary, which now get a list of these pairs. Remove the old aggregate size from the metadata and summary support. One other change from the prior support is that we no longer write the size information into the combined index for the LTO backends, which don't use this information, which reduces unnecessary bloat in distributed index files.
Diffstat (limited to 'llvm/lib/Analysis/ModuleSummaryAnalysis.cpp')
-rw-r--r--llvm/lib/Analysis/ModuleSummaryAnalysis.cpp31
1 files changed, 23 insertions, 8 deletions
diff --git a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
index 04670f2..611d4bf 100644
--- a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -522,6 +522,7 @@ static void computeFunctionSummary(
if (MemProfMD) {
std::vector<MIBInfo> MIBs;
std::vector<uint64_t> TotalSizes;
+ std::vector<std::vector<ContextTotalSize>> ContextSizeInfos;
for (auto &MDOp : MemProfMD->operands()) {
auto *MIBMD = cast<const MDNode>(MDOp);
MDNode *StackNode = getMIBStackNode(MIBMD);
@@ -539,18 +540,32 @@ static void computeFunctionSummary(
if (StackIdIndices.empty() || StackIdIndices.back() != StackIdIdx)
StackIdIndices.push_back(StackIdIdx);
}
+ // If we have context size information, collect it for inclusion in
+ // the summary.
+ assert(MIBMD->getNumOperands() > 2 || !MemProfReportHintedSizes);
+ if (MIBMD->getNumOperands() > 2) {
+ std::vector<ContextTotalSize> ContextSizes;
+ for (unsigned I = 2; I < MIBMD->getNumOperands(); I++) {
+ MDNode *ContextSizePair = dyn_cast<MDNode>(MIBMD->getOperand(I));
+ assert(ContextSizePair->getNumOperands() == 2);
+ uint64_t FullStackId = mdconst::dyn_extract<ConstantInt>(
+ ContextSizePair->getOperand(0))
+ ->getZExtValue();
+ uint64_t TS = mdconst::dyn_extract<ConstantInt>(
+ ContextSizePair->getOperand(1))
+ ->getZExtValue();
+ ContextSizes.push_back({FullStackId, TS});
+ }
+ ContextSizeInfos.push_back(std::move(ContextSizes));
+ }
MIBs.push_back(
MIBInfo(getMIBAllocType(MIBMD), std::move(StackIdIndices)));
- if (MemProfReportHintedSizes) {
- auto TotalSize = getMIBTotalSize(MIBMD);
- assert(TotalSize);
- TotalSizes.push_back(TotalSize);
- }
}
Allocs.push_back(AllocInfo(std::move(MIBs)));
- if (MemProfReportHintedSizes) {
- assert(Allocs.back().MIBs.size() == TotalSizes.size());
- Allocs.back().TotalSizes = std::move(TotalSizes);
+ assert(!ContextSizeInfos.empty() || !MemProfReportHintedSizes);
+ if (!ContextSizeInfos.empty()) {
+ assert(Allocs.back().MIBs.size() == ContextSizeInfos.size());
+ Allocs.back().ContextSizeInfos = std::move(ContextSizeInfos);
}
} else if (!InstCallsite.empty()) {
SmallVector<unsigned> StackIdIndices;