@@ -278,26 +278,30 @@ bool CallStackTrie::buildMIBNodes(CallStackTrieNode *Node, LLVMContext &Ctx,
278278 return true ;
279279}
280280
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+
281295// Build and attach the minimal necessary MIB metadata. If the alloc has a
282296// single allocation type, add a function attribute instead. Returns true if
283297// memprof metadata attached, false if not (attribute added).
284298bool CallStackTrie::buildAndAttachMIBMetadata (CallBase *CI) {
285- auto &Ctx = CI->getContext ();
286299 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" );
299302 return false ;
300303 }
304+ auto &Ctx = CI->getContext ();
301305 std::vector<uint64_t > MIBCallStack;
302306 MIBCallStack.push_back (AllocStackId);
303307 std::vector<Metadata *> MIBNodes;
@@ -314,8 +318,9 @@ bool CallStackTrie::buildAndAttachMIBMetadata(CallBase *CI) {
314318 // If there exists corner case that CallStackTrie has one chain to leaf
315319 // and all node in the chain have multi alloc type, conservatively give
316320 // 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" );
319324 return false ;
320325}
321326
0 commit comments