diff --git a/llvm/include/llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h b/llvm/include/llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h --- a/llvm/include/llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h +++ b/llvm/include/llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h @@ -214,13 +214,22 @@ } #ifndef NDEBUG +template static inline std::string getName(const BT *BB) { + if (BB->hasName()) + return BB->getName().str(); + std::string Str; + raw_string_ostream OS(Str); + BB->printAsOperand(OS, false); + return Str; +} + /// Print the weight of edge \p E on stream \p OS. /// /// \param OS Stream to emit the output to. /// \param E Edge to print. template void SampleProfileLoaderBaseImpl::printEdgeWeight(raw_ostream &OS, Edge E) { - OS << "weight[" << E.first->getName() << "->" << E.second->getName() + OS << "weight[" << getName(E.first) << "->" << getName(E.second) << "]: " << EdgeWeights[E] << "\n"; } @@ -232,8 +241,8 @@ void SampleProfileLoaderBaseImpl::printBlockEquivalence( raw_ostream &OS, const BasicBlockT *BB) { const BasicBlockT *Equiv = EquivalenceClass[BB]; - OS << "equivalence[" << BB->getName() - << "]: " << ((Equiv) ? EquivalenceClass[BB]->getName() : "NONE") << "\n"; + OS << "equivalence[" << getName(BB) + << "]: " << ((Equiv) ? getName(EquivalenceClass[BB]) : "NONE") << "\n"; } /// Print the weight of block \p BB on stream \p OS. @@ -245,7 +254,7 @@ raw_ostream &OS, const BasicBlockT *BB) const { const auto &I = BlockWeights.find(BB); uint64_t W = (I == BlockWeights.end() ? 0 : I->second); - OS << "weight[" << BB->getName() << "]: " << W << "\n"; + OS << "weight[" << getName(BB) << "]: " << W << "\n"; } #endif diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp --- a/llvm/lib/Transforms/IPO/SampleProfile.cpp +++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp @@ -886,6 +886,8 @@ auto *DI = &pgo::promoteIndirectCall( CI, R->getValue(), Candidate.CallsiteCount, Sum, false, ORE); if (DI) { + LLVM_DEBUG(dbgs() << "Promoted indirect call " << CI << "\n" + << " to " << *DI << "\n"); Sum -= Candidate.CallsiteCount; // Do not prorate the indirect callsite distribution since the original // distribution will be used to scale down non-promoted profile target @@ -1173,15 +1175,24 @@ if (Cost.isNever()) { ORE->emit(OptimizationRemarkAnalysis(CSINLINE_DEBUG, "InlineFail", DLoc, BB) << "incompatible inlining"); + LLVM_DEBUG(dbgs() << "Failed to inline call " << CB + << "\n because of incompatible inlining\n"); return false; } - if (!Cost) + if (!Cost) { + LLVM_DEBUG(dbgs() << "Failed to inline call " << CB + << "\n with CallsiteCount " << Candidate.CallsiteCount + << " HotCountThreshold " << PSI->getHotCountThreshold() + << " Cost " << Cost.getCost() << " CostThreshold " + << Cost.getThreshold() << "\n"); return false; + } InlineFunctionInfo IFI(nullptr, GetAC); IFI.UpdateProfile = false; - if (InlineFunction(CB, IFI).isSuccess()) { + InlineResult IR = InlineFunction(CB, IFI); + if (IR.isSuccess()) { // The call to InlineFunction erases I, so we can't pass it here. emitInlinedInto(*ORE, DLoc, BB, *CalledFunction, *BB->getParent(), Cost, true, CSINLINE_DEBUG); @@ -1213,7 +1224,18 @@ NumDuplicatedInlinesite++; } + LLVM_DEBUG(dbgs() << "Inlined " << CalledFunction->getName() << "\n"); return true; + } else { + ORE->emit([&]() { + return OptimizationRemarkMissed(CSINLINE_DEBUG, "NotInlined", DLoc, BB) + << ore::NV("Callee", CalledFunction) + << " will not be inlined into " + << ore::NV("Caller", BB->getParent()) << ": " + << ore::NV("Reason", IR.getFailureReason()); + }); + LLVM_DEBUG(dbgs() << "Failed to inline call " << CB << "\n because of " + << IR.getFailureReason() << "\n"); } return false; } @@ -1243,6 +1265,7 @@ CallsiteCount, uint64_t(CalleeSamples->getEntrySamples() * Factor)); *NewCandidate = {CB, CalleeSamples, CallsiteCount, Factor}; + LLVM_DEBUG(dbgs() << "Inline Candidate: " << *CB << "\n"); return true; } @@ -1300,7 +1323,7 @@ bool SampleProfileLoader::inlineHotFunctionsWithPriority( Function &F, DenseSet &InlinedGUIDs) { - assert(ProfileIsCS && "Prioritiy based inliner only works with CSSPGO now"); + assert(ProfileIsCS && "Priority based inliner only works with CSSPGO now"); // ProfAccForSymsInList is used in callsiteIsHot. The assertion makes sure // Profile symbol list is ignored when profile-sample-accurate is on. @@ -1407,6 +1430,7 @@ } if (!CQueue.empty()) { + LLVM_DEBUG(dbgs() << "Inlining stopped, out of budget\n"); if (SizeLimit == (unsigned)ProfileInlineLimitMax) ++NumCSInlinedHitMaxLimit; else if (SizeLimit == (unsigned)ProfileInlineLimitMin)