+
+unsigned Inliner::getInlineThreshold(CallSite CS) const {
+ int thres = InlineThreshold; // -inline-threshold or else selected by
+ // overall opt level
+
+ // If -inline-threshold is not given, listen to the optsize attribute when it
+ // would decrease the threshold.
+ Function *Caller = CS.getCaller();
+ bool OptSize = Caller && !Caller->isDeclaration() &&
+ Caller->getAttributes().hasAttribute(AttributeSet::FunctionIndex,
+ Attribute::OptimizeForSize);
+ if (!(InlineLimit.getNumOccurrences() > 0) && OptSize &&
+ OptSizeThreshold < thres)
+ thres = OptSizeThreshold;
+
+ // Listen to the inlinehint attribute when it would increase the threshold
+ // and the caller does not need to minimize its size.
+ Function *Callee = CS.getCalledFunction();
+ bool InlineHint = Callee && !Callee->isDeclaration() &&
+ Callee->getAttributes().hasAttribute(AttributeSet::FunctionIndex,
+ Attribute::InlineHint);
+ if (InlineHint && HintThreshold > thres
+ && !Caller->getAttributes().hasAttribute(AttributeSet::FunctionIndex,
+ Attribute::MinSize))
+ thres = HintThreshold;
+
+ return thres;
+}
+