Index: include/llvm/Analysis/InlineCost.h =================================================================== --- include/llvm/Analysis/InlineCost.h +++ include/llvm/Analysis/InlineCost.h @@ -212,11 +212,13 @@ /// /// Also note that calling this function *dynamically* computes the cost of /// inlining the callsite. It is an expensive, heavyweight call. -InlineCost getInlineCost( - CallSite CS, const InlineParams &Params, TargetTransformInfo &CalleeTTI, - std::function &GetAssumptionCache, - Optional> GetBFI, - ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE = nullptr); +InlineCost +getInlineCost(CallSite CS, const InlineParams &Params, + TargetTransformInfo &CalleeTTI, + std::function &GetAssumptionCache, + Optional> GetBFI, + ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE = nullptr, + bool RemarksEnabled = false); /// Get an InlineCost with the callee explicitly specified. /// This allows you to calculate the cost of inlining a function via a @@ -228,7 +230,8 @@ TargetTransformInfo &CalleeTTI, std::function &GetAssumptionCache, Optional> GetBFI, - ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE); + ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE, + bool RemarksEnabled); /// Minimal filter to detect invalid constructs for inlining. bool isInlineViable(Function &Callee); Index: lib/Analysis/InlineCost.cpp =================================================================== --- lib/Analysis/InlineCost.cpp +++ lib/Analysis/InlineCost.cpp @@ -1989,9 +1989,10 @@ CallSite CS, const InlineParams &Params, TargetTransformInfo &CalleeTTI, std::function &GetAssumptionCache, Optional> GetBFI, - ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE) { + ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE, + bool RemarksEnabled) { return getInlineCost(CS, CS.getCalledFunction(), Params, CalleeTTI, - GetAssumptionCache, GetBFI, PSI, ORE); + GetAssumptionCache, GetBFI, PSI, ORE, RemarksEnabled); } InlineCost llvm::getInlineCost( @@ -1999,12 +2000,19 @@ TargetTransformInfo &CalleeTTI, std::function &GetAssumptionCache, Optional> GetBFI, - ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE) { + ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE, + bool RemarksEnabled) { // Cannot inline indirect calls. if (!Callee) return llvm::InlineCost::getNever("indirect call"); + // TODO: Eventually optimization remarks emitted in InlineCost.cpp is better + // to be moved outside -- return the related information to the caller and + // let the passes decide whether to emit the remarks. + if (!RemarksEnabled) + ORE = nullptr; + // 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/Target/AMDGPU/AMDGPUInline.cpp =================================================================== --- lib/Target/AMDGPU/AMDGPUInline.cpp +++ lib/Target/AMDGPU/AMDGPUInline.cpp @@ -206,5 +206,5 @@ }; return llvm::getInlineCost(CS, Callee, LocalParams, TTI, GetAssumptionCache, - None, PSI, RemarksEnabled ? &ORE : nullptr); + None, PSI, &ORE, RemarksEnabled); } Index: lib/Transforms/IPO/InlineSimple.cpp =================================================================== --- lib/Transforms/IPO/InlineSimple.cpp +++ lib/Transforms/IPO/InlineSimple.cpp @@ -69,8 +69,7 @@ return ACT->getAssumptionCache(F); }; return llvm::getInlineCost(CS, Params, TTI, GetAssumptionCache, - /*GetBFI=*/None, PSI, - RemarksEnabled ? &ORE : nullptr); + /*GetBFI=*/None, PSI, &ORE, RemarksEnabled); } bool runOnSCC(CallGraphSCC &SCC) override; 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, &ORE, RemarksEnabled); }; // 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, &ORE, RemarksEnabled); if (IC.isAlways()) { ORE.emit([&]() {