aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/InlineCost.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Analysis/InlineCost.cpp')
-rw-r--r--llvm/lib/Analysis/InlineCost.cpp27
1 files changed, 21 insertions, 6 deletions
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp
index ebb1f20..0992a4f 100644
--- a/llvm/lib/Analysis/InlineCost.cpp
+++ b/llvm/lib/Analysis/InlineCost.cpp
@@ -161,12 +161,21 @@ static cl::opt<bool> DisableGEPConstOperand(
cl::desc("Disables evaluation of GetElementPtr with constant operands"));
namespace llvm {
+Optional<int> getStringFnAttrAsInt(const Attribute &Attr) {
+ if (Attr.isValid()) {
+ int AttrValue = 0;
+ if (!Attr.getValueAsString().getAsInteger(10, AttrValue))
+ return AttrValue;
+ }
+ return None;
+}
+
Optional<int> getStringFnAttrAsInt(CallBase &CB, StringRef AttrKind) {
- Attribute Attr = CB.getFnAttr(AttrKind);
- int AttrValue;
- if (Attr.getValueAsString().getAsInteger(10, AttrValue))
- return None;
- return AttrValue;
+ return getStringFnAttrAsInt(CB.getFnAttr(AttrKind));
+}
+
+Optional<int> getStringFnAttrAsInt(Function *F, StringRef AttrKind) {
+ return getStringFnAttrAsInt(F->getFnAttribute(AttrKind));
}
namespace InlineConstants {
@@ -2713,7 +2722,13 @@ InlineResult CallAnalyzer::analyze() {
// If the callee's stack size exceeds the user-specified threshold,
// do not let it be inlined.
- if (AllocatedSize > StackSizeThreshold)
+ // The command line option overrides a limit set in the function attributes.
+ size_t FinalStackSizeThreshold = StackSizeThreshold;
+ if (!StackSizeThreshold.getNumOccurrences())
+ if (Optional<int> AttrMaxStackSize = getStringFnAttrAsInt(
+ Caller, InlineConstants::MaxInlineStackSizeAttributeName))
+ FinalStackSizeThreshold = *AttrMaxStackSize;
+ if (AllocatedSize > FinalStackSizeThreshold)
return InlineResult::failure("stacksize");
return finalizeAnalysis();