@@ -970,6 +970,7 @@ static void
970970readMemprof (Module &M, Function &F, IndexedInstrProfReader *MemProfReader,
971971 const TargetLibraryInfo &TLI,
972972 std::map<uint64_t , AllocMatchInfo> &FullStackIdToAllocMatchInfo,
973+ std::set<std::vector<uint64_t >> &MatchedCallSites,
973974 DenseMap<uint64_t , LocToLocMap> &UndriftMaps) {
974975 auto &Ctx = M.getContext ();
975976 // Previously we used getIRPGOFuncName() here. If F is local linkage,
@@ -1210,6 +1211,13 @@ readMemprof(Module &M, Function &F, IndexedInstrProfReader *MemProfReader,
12101211 addCallsiteMetadata (I, InlinedCallStack, Ctx);
12111212 // Only need to find one with a matching call stack and add a single
12121213 // callsite metadata.
1214+
1215+ // Accumulate call site matching information upon request.
1216+ if (ClPrintMemProfMatchInfo) {
1217+ std::vector<uint64_t > CallStack;
1218+ append_range (CallStack, InlinedCallStack);
1219+ MatchedCallSites.insert (std::move (CallStack));
1220+ }
12131221 break ;
12141222 }
12151223 }
@@ -1266,13 +1274,17 @@ PreservedAnalyses MemProfUsePass::run(Module &M, ModuleAnalysisManager &AM) {
12661274 // it to an allocation in the IR.
12671275 std::map<uint64_t , AllocMatchInfo> FullStackIdToAllocMatchInfo;
12681276
1277+ // Set of the matched call sites, each expressed as a sequence of an inline
1278+ // call stack.
1279+ std::set<std::vector<uint64_t >> MatchedCallSites;
1280+
12691281 for (auto &F : M) {
12701282 if (F.isDeclaration ())
12711283 continue ;
12721284
12731285 const TargetLibraryInfo &TLI = FAM.getResult <TargetLibraryAnalysis>(F);
12741286 readMemprof (M, F, MemProfReader.get (), TLI, FullStackIdToAllocMatchInfo,
1275- UndriftMaps);
1287+ MatchedCallSites, UndriftMaps);
12761288 }
12771289
12781290 if (ClPrintMemProfMatchInfo) {
@@ -1281,6 +1293,13 @@ PreservedAnalyses MemProfUsePass::run(Module &M, ModuleAnalysisManager &AM) {
12811293 << " context with id " << Id << " has total profiled size "
12821294 << Info.TotalSize << (Info.Matched ? " is" : " not" )
12831295 << " matched\n " ;
1296+
1297+ for (const auto &CallStack : MatchedCallSites) {
1298+ errs () << " MemProf callsite match for inline call stack" ;
1299+ for (uint64_t StackId : CallStack)
1300+ errs () << " " << StackId;
1301+ errs () << " \n " ;
1302+ }
12841303 }
12851304
12861305 return PreservedAnalyses::none ();
0 commit comments