@@ -278,26 +278,30 @@ bool CallStackTrie::buildMIBNodes(CallStackTrieNode *Node, LLVMContext &Ctx,
278
278
return true ;
279
279
}
280
280
281
+ void CallStackTrie::addSingleAllocTypeAttribute (CallBase *CI, AllocationType AT,
282
+ StringRef Descriptor) {
283
+ addAllocTypeAttribute (CI->getContext (), CI, AT);
284
+ if (MemProfReportHintedSizes) {
285
+ std::vector<ContextTotalSize> ContextSizeInfo;
286
+ collectContextSizeInfo (Alloc, ContextSizeInfo);
287
+ for (const auto &[FullStackId, TotalSize] : ContextSizeInfo) {
288
+ errs () << " MemProf hinting: Total size for full allocation context hash "
289
+ << FullStackId << " and " << Descriptor << " alloc type "
290
+ << getAllocTypeAttributeString (AT) << " : " << TotalSize << " \n " ;
291
+ }
292
+ }
293
+ }
294
+
281
295
// Build and attach the minimal necessary MIB metadata. If the alloc has a
282
296
// single allocation type, add a function attribute instead. Returns true if
283
297
// memprof metadata attached, false if not (attribute added).
284
298
bool CallStackTrie::buildAndAttachMIBMetadata (CallBase *CI) {
285
- auto &Ctx = CI->getContext ();
286
299
if (hasSingleAllocType (Alloc->AllocTypes )) {
287
- addAllocTypeAttribute (Ctx, CI, (AllocationType)Alloc->AllocTypes );
288
- if (MemProfReportHintedSizes) {
289
- std::vector<ContextTotalSize> ContextSizeInfo;
290
- collectContextSizeInfo (Alloc, ContextSizeInfo);
291
- for (const auto &[FullStackId, TotalSize] : ContextSizeInfo) {
292
- errs ()
293
- << " MemProf hinting: Total size for full allocation context hash "
294
- << FullStackId << " and single alloc type "
295
- << getAllocTypeAttributeString ((AllocationType)Alloc->AllocTypes )
296
- << " : " << TotalSize << " \n " ;
297
- }
298
- }
300
+ addSingleAllocTypeAttribute (CI, (AllocationType)Alloc->AllocTypes ,
301
+ " single" );
299
302
return false ;
300
303
}
304
+ auto &Ctx = CI->getContext ();
301
305
std::vector<uint64_t > MIBCallStack;
302
306
MIBCallStack.push_back (AllocStackId);
303
307
std::vector<Metadata *> MIBNodes;
@@ -314,8 +318,9 @@ bool CallStackTrie::buildAndAttachMIBMetadata(CallBase *CI) {
314
318
// If there exists corner case that CallStackTrie has one chain to leaf
315
319
// and all node in the chain have multi alloc type, conservatively give
316
320
// it non-cold allocation type.
317
- // FIXME: Avoid this case before memory profile created.
318
- addAllocTypeAttribute (Ctx, CI, AllocationType::NotCold);
321
+ // FIXME: Avoid this case before memory profile created. Alternatively, select
322
+ // hint based on fraction cold.
323
+ addSingleAllocTypeAttribute (CI, AllocationType::NotCold, " indistinguishable" );
319
324
return false ;
320
325
}
321
326
0 commit comments