summaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/MemoryProfileInfo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Analysis/MemoryProfileInfo.cpp')
-rw-r--r--llvm/lib/Analysis/MemoryProfileInfo.cpp48
1 files changed, 39 insertions, 9 deletions
diff --git a/llvm/lib/Analysis/MemoryProfileInfo.cpp b/llvm/lib/Analysis/MemoryProfileInfo.cpp
index 347377522101..c08024a38ffc 100644
--- a/llvm/lib/Analysis/MemoryProfileInfo.cpp
+++ b/llvm/lib/Analysis/MemoryProfileInfo.cpp
@@ -46,6 +46,25 @@ cl::opt<unsigned> MinCallsiteColdBytePercent(
cl::desc("Min percent of cold bytes at a callsite to discard non-cold "
"contexts"));
+// Enable saving context size information for largest cold contexts, which can
+// be used to flag contexts for more aggressive cloning and reporting.
+cl::opt<unsigned> MinPercentMaxColdSize(
+ "memprof-min-percent-max-cold-size", cl::init(100), cl::Hidden,
+ cl::desc("Min percent of max cold bytes for critical cold context"));
+
+bool llvm::memprof::metadataIncludesAllContextSizeInfo() {
+ return MemProfReportHintedSizes || MinClonedColdBytePercent < 100;
+}
+
+bool llvm::memprof::metadataMayIncludeContextSizeInfo() {
+ return metadataIncludesAllContextSizeInfo() || MinPercentMaxColdSize < 100;
+}
+
+bool llvm::memprof::recordContextSizeInfoForAnalysis() {
+ return metadataMayIncludeContextSizeInfo() ||
+ MinCallsiteColdBytePercent < 100;
+}
+
MDNode *llvm::memprof::buildCallstackMetadata(ArrayRef<uint64_t> CallStack,
LLVMContext &Ctx) {
SmallVector<Metadata *, 8> StackVals;
@@ -168,7 +187,8 @@ void CallStackTrie::addCallStack(MDNode *MIB) {
static MDNode *createMIBNode(LLVMContext &Ctx, ArrayRef<uint64_t> MIBCallStack,
AllocationType AllocType,
ArrayRef<ContextTotalSize> ContextSizeInfo,
- uint64_t &TotalBytes, uint64_t &ColdBytes) {
+ const uint64_t MaxColdSize, uint64_t &TotalBytes,
+ uint64_t &ColdBytes) {
SmallVector<Metadata *> MIBPayload(
{buildCallstackMetadata(MIBCallStack, Ctx)});
MIBPayload.push_back(
@@ -184,12 +204,21 @@ static MDNode *createMIBNode(LLVMContext &Ctx, ArrayRef<uint64_t> MIBCallStack,
for (const auto &[FullStackId, TotalSize] : ContextSizeInfo) {
TotalBytes += TotalSize;
- if (AllocType == AllocationType::Cold)
+ bool LargeColdContext = false;
+ if (AllocType == AllocationType::Cold) {
ColdBytes += TotalSize;
+ // If we have the max cold context size from summary information and have
+ // requested identification of contexts above a percentage of the max, see
+ // if this context qualifies.
+ if (MaxColdSize > 0 && MinPercentMaxColdSize < 100 &&
+ TotalSize * 100 >= MaxColdSize * MinPercentMaxColdSize)
+ LargeColdContext = true;
+ }
// Only add the context size info as metadata if we need it in the thin
- // link (currently if reporting of hinted sizes is enabled or we have
- // specified a threshold for marking allocations cold after cloning).
- if (MemProfReportHintedSizes || MinClonedColdBytePercent < 100) {
+ // link (currently if reporting of hinted sizes is enabled, we have
+ // specified a threshold for marking allocations cold after cloning, or we
+ // have identified this as a large cold context of interest above).
+ if (metadataIncludesAllContextSizeInfo() || LargeColdContext) {
auto *FullStackIdMD = ValueAsMetadata::get(
ConstantInt::get(Type::getInt64Ty(Ctx), FullStackId));
auto *TotalSizeMD = ValueAsMetadata::get(
@@ -357,9 +386,9 @@ bool CallStackTrie::buildMIBNodes(CallStackTrieNode *Node, LLVMContext &Ctx,
if (hasSingleAllocType(Node->AllocTypes)) {
std::vector<ContextTotalSize> ContextSizeInfo;
collectContextSizeInfo(Node, ContextSizeInfo);
- MIBNodes.push_back(createMIBNode(Ctx, MIBCallStack,
- (AllocationType)Node->AllocTypes,
- ContextSizeInfo, TotalBytes, ColdBytes));
+ MIBNodes.push_back(
+ createMIBNode(Ctx, MIBCallStack, (AllocationType)Node->AllocTypes,
+ ContextSizeInfo, MaxColdSize, TotalBytes, ColdBytes));
return true;
}
@@ -413,7 +442,8 @@ bool CallStackTrie::buildMIBNodes(CallStackTrieNode *Node, LLVMContext &Ctx,
std::vector<ContextTotalSize> ContextSizeInfo;
collectContextSizeInfo(Node, ContextSizeInfo);
MIBNodes.push_back(createMIBNode(Ctx, MIBCallStack, AllocationType::NotCold,
- ContextSizeInfo, TotalBytes, ColdBytes));
+ ContextSizeInfo, MaxColdSize, TotalBytes,
+ ColdBytes));
return true;
}