================ @@ -414,6 +417,58 @@ void removeInstrumentation(Function &F) { I.eraseFromParent(); } +void annotateIndirectCall( + Module &M, CallBase &CB, + const DenseMap<uint32_t, FlatIndirectTargets> &FlatProf, + const InstrProfCallsite &Ins) { + auto Idx = Ins.getIndex()->getZExtValue(); + auto FIt = FlatProf.find(Idx); + if (FIt == FlatProf.end()) + return; + const auto &Targets = FIt->second; + SmallVector<InstrProfValueData, 2> Data; + uint64_t Sum = 0; + for (auto &[Guid, Count] : Targets) { + Data.push_back({/*.Value=*/Guid, /*.Count=*/Count}); + Sum += Count; + } + struct InstrProfValueDataGTComparer { + bool operator()(const InstrProfValueData &A, const InstrProfValueData &B) { + return A.Count > B.Count; + } + }; + llvm::sort(Data, InstrProfValueDataGTComparer()); + llvm::annotateValueSite(M, CB, Data, Sum, + InstrProfValueKind::IPVK_IndirectCallTarget, + Data.size()); + LLVM_DEBUG(dbgs() << "[ctxprof] flat indirect call prof: " << CB + << CB.getMetadata(LLVMContext::MD_prof) << "\n"); +} + +// We normally return a "Changed" bool, but the calling pass' run assumes +// something will change - some profile will be added - so this won't add much +// by returning false when applicable. +void annotateIndCalls(Module &M, const CtxProfAnalysis::Result &CtxProf) { ---------------- snehasish wrote:
nit: s/Ind/Indirect/ to be consistent with the other method? https://github.com/llvm/llvm-project/pull/134766 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits