[llvm] [ctx_prof] Simple ICP criteria during module inliner (PR #109881)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 25 12:47:06 PDT 2024
================
@@ -623,34 +623,37 @@ CallBase *llvm::promoteCallWithIfThenElse(CallBase &CB, Function &Callee,
// All the ctx-es belonging to a function must have the same size counters.
Ctx.resizeCounters(NewCountersSize);
- // Maybe in this context, the indirect callsite wasn't observed at all
+ // Maybe in this context, the indirect callsite wasn't observed at all. That
+ // would make both direct and indirect BBs cold - which is what we already
+ // have from resising the counters.
if (!Ctx.hasCallsite(CSIndex))
return;
auto &CSData = Ctx.callsite(CSIndex);
- auto It = CSData.find(CalleeGUID);
- // Maybe we did notice the indirect callsite, but to other targets.
- if (It == CSData.end())
- return;
-
- assert(CalleeGUID == It->second.guid());
-
- uint32_t DirectCount = It->second.getEntrycount();
- uint32_t TotalCount = 0;
+ uint64_t TotalCount = 0;
for (const auto &[_, V] : CSData)
TotalCount += V.getEntrycount();
+ uint64_t DirectCount = 0;
+ // If we called the direct target, update the DirectCount. If we didn't, we
+ // still want to update the indirect BB (to which the TotalCount goes, in
+ // that case).
+ if (auto It = CSData.find(CalleeGUID); It != CSData.end()) {
+ assert(CalleeGUID == It->second.guid());
+ DirectCount = It->second.getEntrycount();
+ // This direct target needs to be moved to this caller under the
+ // newly-allocated callsite index.
+ assert(Ctx.callsites().count(NewCSID) == 0);
+ Ctx.ingestContext(NewCSID, std::move(It->second));
+ CSData.erase(CalleeGUID);
----------------
kazutakahirata wrote:
Ah, I see. Thank you for the explanation!
https://github.com/llvm/llvm-project/pull/109881
More information about the llvm-commits
mailing list