Inliner uses a smaller inline threshold for callees with cold attribute.
[oota-llvm.git] / lib / Transforms / IPO / Inliner.cpp
index dc710d14157bdd0102e1d108e6702772861addfb..8647f39a90017b035bab538ee11b6c02f7f0de97 100644 (file)
@@ -50,6 +50,10 @@ static cl::opt<int>
 HintThreshold("inlinehint-threshold", cl::Hidden, cl::init(325),
               cl::desc("Threshold for inlining functions with inline hint"));
 
+static cl::opt<int>
+ColdThreshold("inlinecold-threshold", cl::Hidden, cl::init(75),
+              cl::desc("Threshold for inlining functions with cold attribute"));
+
 // Threshold to use when optsize is specified (and there is no -inline-limit).
 const int OptSizeThreshold = 75;
 
@@ -277,6 +281,13 @@ unsigned Inliner::getInlineThreshold(CallSite CS) const {
                                                Attribute::MinSize))
     thres = HintThreshold;
 
+  // Listen to the cold attribute when it would decrease the threshold.
+  bool ColdCallee = Callee && !Callee->isDeclaration() &&
+    Callee->getAttributes().hasAttribute(AttributeSet::FunctionIndex,
+                                         Attribute::Cold);
+  if (ColdCallee && ColdThreshold < thres)
+    thres = ColdThreshold;
+
   return thres;
 }