@@ -173,6 +173,10 @@ static cl::opt<std::string>
173
173
174
174
extern cl::opt<bool > MemProfReportHintedSizes;
175
175
176
+ static cl::opt<unsigned > MinMatchedColdBytePercent (
177
+ " memprof-matching-cold-threshold" , cl::init(100 ), cl::Hidden,
178
+ cl::desc(" Min percent of cold bytes matched to hint allocation cold" ));
179
+
176
180
// Instrumentation statistics
177
181
STATISTIC (NumInstrumentedReads, " Number of instrumented reads" );
178
182
STATISTIC (NumInstrumentedWrites, " Number of instrumented writes" );
@@ -1074,6 +1078,8 @@ readMemprof(Module &M, Function &F, IndexedInstrProfReader *MemProfReader,
1074
1078
// contexts. Add them to a Trie specialized for trimming the contexts to
1075
1079
// the minimal needed to disambiguate contexts with unique behavior.
1076
1080
CallStackTrie AllocTrie;
1081
+ uint64_t TotalSize = 0 ;
1082
+ uint64_t TotalColdSize = 0 ;
1077
1083
for (auto *AllocInfo : AllocInfoIter->second ) {
1078
1084
// Check the full inlined call stack against this one.
1079
1085
// If we found and thus matched all frames on the call, include
@@ -1085,6 +1091,9 @@ readMemprof(Module &M, Function &F, IndexedInstrProfReader *MemProfReader,
1085
1091
if (ClPrintMemProfMatchInfo || MemProfReportHintedSizes)
1086
1092
FullStackId = computeFullStackId (AllocInfo->CallStack );
1087
1093
auto AllocType = addCallStack (AllocTrie, AllocInfo, FullStackId);
1094
+ TotalSize += AllocInfo->Info .getTotalSize ();
1095
+ if (AllocType == AllocationType::Cold)
1096
+ TotalColdSize += AllocInfo->Info .getTotalSize ();
1088
1097
// Record information about the allocation if match info printing
1089
1098
// was requested.
1090
1099
if (ClPrintMemProfMatchInfo) {
@@ -1094,6 +1103,16 @@ readMemprof(Module &M, Function &F, IndexedInstrProfReader *MemProfReader,
1094
1103
}
1095
1104
}
1096
1105
}
1106
+ // If the threshold for the percent of cold bytes is less than 100%,
1107
+ // and not all bytes are cold, see if we should still hint this
1108
+ // allocation as cold without context sensitivity.
1109
+ if (TotalColdSize < TotalSize && MinMatchedColdBytePercent < 100 &&
1110
+ TotalColdSize * 100 >= MinMatchedColdBytePercent * TotalSize) {
1111
+ AllocTrie.addSingleAllocTypeAttribute (CI, AllocationType::Cold,
1112
+ " dominant" );
1113
+ continue ;
1114
+ }
1115
+
1097
1116
// We might not have matched any to the full inlined call stack.
1098
1117
// But if we did, create and attach metadata, or a function attribute if
1099
1118
// all contexts have identical profiled behavior.
0 commit comments