Index: lib/Analysis/InlineCost.cpp =================================================================== --- lib/Analysis/InlineCost.cpp +++ lib/Analysis/InlineCost.cpp @@ -2005,6 +2005,12 @@ if (!Callee) return llvm::InlineCost::getNever("indirect call"); + OptimizationRemarkEmitter NewORE(Callee); + if (!ORE && + Callee->getContext().getDiagHandlerPtr()->isMissedOptRemarkEnabled( + DEBUG_TYPE)) + ORE = &NewORE; + // Never inline calls with byval arguments that does not have the alloca // address space. Since byval arguments can be replaced with a copy to an // alloca, the inlined code would need to be adjusted to handle that the Index: lib/Transforms/IPO/Inliner.cpp =================================================================== --- lib/Transforms/IPO/Inliner.cpp +++ lib/Transforms/IPO/Inliner.cpp @@ -1005,8 +1005,11 @@ auto GetInlineCost = [&](CallSite CS) { Function &Callee = *CS.getCalledFunction(); auto &CalleeTTI = FAM.getResult(Callee); + bool RemarksEnabled = + Callee.getContext().getDiagHandlerPtr()->isMissedOptRemarkEnabled( + DEBUG_TYPE); return getInlineCost(CS, Params, CalleeTTI, GetAssumptionCache, {GetBFI}, - PSI, &ORE); + PSI, RemarksEnabled ? &ORE : nullptr); }; // Now process as many calls as we have within this caller in the sequnece. Index: lib/Transforms/IPO/PartialInlining.cpp =================================================================== --- lib/Transforms/IPO/PartialInlining.cpp +++ lib/Transforms/IPO/PartialInlining.cpp @@ -762,8 +762,12 @@ Function *Caller = CS.getCaller(); auto &CalleeTTI = (*GetTTI)(*Callee); - InlineCost IC = getInlineCost(CS, getInlineParams(), CalleeTTI, - *GetAssumptionCache, GetBFI, PSI, &ORE); + bool RemarksEnabled = + Callee->getContext().getDiagHandlerPtr()->isMissedOptRemarkEnabled( + DEBUG_TYPE); + InlineCost IC = + getInlineCost(CS, getInlineParams(), CalleeTTI, *GetAssumptionCache, + GetBFI, PSI, RemarksEnabled ? &ORE : nullptr); if (IC.isAlways()) { ORE.emit([&]() {