Index: include/llvm/Analysis/InlineCost.h =================================================================== --- include/llvm/Analysis/InlineCost.h +++ include/llvm/Analysis/InlineCost.h @@ -127,7 +127,7 @@ /// Threshold to use for callees with inline hint. Optional HintThreshold; - /// Threshold to use for cold callees. + /// Threshold to use for cold call sites and callees. Optional ColdThreshold; /// Threshold to use when the caller is optimized for size. @@ -142,9 +142,6 @@ /// Threshold to use when the callsite is considered hot relative to function /// entry. Optional LocallyHotCallSiteThreshold; - - /// Threshold to use when the callsite is considered cold. - Optional ColdCallSiteThreshold; }; /// Generate the parameters to tune the inline cost analysis based only on the Index: lib/Analysis/InlineCost.cpp =================================================================== --- lib/Analysis/InlineCost.cpp +++ lib/Analysis/InlineCost.cpp @@ -49,11 +49,6 @@ "inlinehint-threshold", cl::Hidden, cl::init(325), cl::desc("Threshold for inlining functions with inline hint")); -static cl::opt - ColdCallSiteThreshold("inline-cold-callsite-threshold", cl::Hidden, - cl::init(45), - cl::desc("Threshold for inlining cold callsites")); - // We introduce this threshold to help performance of instrumentation based // PGO before we actually hook up inliner with analysis passes such as BPI and // BFI. @@ -190,7 +185,8 @@ bool allowSizeGrowth(CallSite CS); /// Return true if \p CS is a cold callsite. - bool isColdCallSite(CallSite CS, BlockFrequencyInfo *CallerBFI); + bool isColdCallSite(CallSite CS, BlockFrequencyInfo *CallerBFI, + Function &Callee); /// Return a higher threshold if \p CS is a hot callsite. Optional getHotCallSiteThreshold(CallSite CS, @@ -656,7 +652,13 @@ return true; } -bool CallAnalyzer::isColdCallSite(CallSite CS, BlockFrequencyInfo *CallerBFI) { +bool CallAnalyzer::isColdCallSite(CallSite CS, BlockFrequencyInfo *CallerBFI, + Function &Callee) { + // Simplest test is for the cold attribute on the function itself. These + // should *always* be considered cold. + if (Callee.hasFnAttribute(Attribute::Cold)) + return true; + // If global profile summary is available, then callsite's coldness is // determined based on that. if (PSI && PSI->hasProfileSummary()) @@ -792,14 +794,14 @@ // behavior to prevent inlining of hot callsites during ThinLTO // compile phase. Threshold = HotCallSiteThreshold.getValue(); - } else if (isColdCallSite(CS, CallerBFI)) { + } else if (isColdCallSite(CS, CallerBFI, Callee)) { DEBUG(dbgs() << "Cold callsite.\n"); // Do not apply bonuses for a cold callsite including the // LastCallToStatic bonus. While this bonus might result in code size // reduction, it can cause the size of a non-cold caller to increase // preventing it from being inlined. DisallowAllBonuses(); - Threshold = MinIfValid(Threshold, Params.ColdCallSiteThreshold); + Threshold = MinIfValid(Threshold, Params.ColdThreshold); } else if (PSI) { // Use callee's global profile information only if we have no way of // determining this via callsite information. @@ -1786,9 +1788,6 @@ if (LocallyHotCallSiteThreshold.getNumOccurrences() > 0) Params.LocallyHotCallSiteThreshold = LocallyHotCallSiteThreshold; - // Set the ColdCallSiteThreshold knob from the -inline-cold-callsite-threshold. - Params.ColdCallSiteThreshold = ColdCallSiteThreshold; - // Set the OptMinSizeThreshold and OptSizeThreshold params only if the // -inlinehint-threshold commandline option is not explicitly given. If that // option is present, then its value applies even for callees with size and Index: test/Transforms/Inline/bfi-update.ll =================================================================== --- test/Transforms/Inline/bfi-update.ll +++ test/Transforms/Inline/bfi-update.ll @@ -1,4 +1,4 @@ -; RUN: opt < %s -passes='require,cgscc(inline)' -S -inline-threshold=50 -inline-cold-callsite-threshold=0 -hot-callsite-threshold=50 | FileCheck %s +; RUN: opt < %s -passes='require,cgscc(inline)' -S -inline-threshold=50 -inlinecold-threshold=0 -hot-callsite-threshold=50 | FileCheck %s ; This tests incremental updates to caller's BFI as a callee gets inlined. ; In bottom-up inlining, first c->e inlining is considered and fails because ; e's size exceeds the threshold of 50. Then a->c inlining is considered and it Index: test/Transforms/Inline/inline-cold-callsite-pgo.ll =================================================================== --- test/Transforms/Inline/inline-cold-callsite-pgo.ll +++ test/Transforms/Inline/inline-cold-callsite-pgo.ll @@ -1,4 +1,4 @@ -; RUN: opt < %s -passes='require,cgscc(inline)' -inline-threshold=100 -inline-cold-callsite-threshold=0 -S | FileCheck %s +; RUN: opt < %s -passes='require,cgscc(inline)' -inline-threshold=100 -inlinecold-threshold=0 -S | FileCheck %s ; This tests that a cold callsite gets the inline-cold-callsite-threshold ; and does not get inlined. Another callsite to an identical callee that Index: test/Transforms/Inline/inline-cold-callsite.ll =================================================================== --- test/Transforms/Inline/inline-cold-callsite.ll +++ test/Transforms/Inline/inline-cold-callsite.ll @@ -1,5 +1,4 @@ - -; RUN: opt < %s -passes='require,cgscc(inline)' -inline-threshold=100 -inline-cold-callsite-threshold=0 -S | FileCheck %s +; RUN: opt < %s -passes='cgscc(inline)' -inline-threshold=100 -inlinecold-threshold=0 -S | FileCheck %s ; This tests that a cold callsite gets the inline-cold-callsite-threshold ; and does not get inlined. Another callsite to an identical callee that Index: test/Transforms/Inline/pr26698.ll =================================================================== --- test/Transforms/Inline/pr26698.ll +++ test/Transforms/Inline/pr26698.ll @@ -1,5 +1,5 @@ -; RUN: opt -S -inline -inline-threshold=100 -inline-cold-callsite-threshold=100 < %s | FileCheck %s -; RUN: opt -S -passes='cgscc(inline)' -inline-threshold=100 -inline-cold-callsite-threshold=100 < %s | FileCheck %s +; RUN: opt -S -inline -inline-threshold=100 -inlinecold-threshold=100 < %s | FileCheck %s +; RUN: opt -S -passes='cgscc(inline)' -inline-threshold=100 -inlinecold-threshold=100 < %s | FileCheck %s target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32" target triple = "i686-pc-windows-msvc18.0.0"