diff options
author | Wolfgang Pieb <wolfgang_pieb@playstation.sony.com> | 2022-07-15 13:19:21 -0700 |
---|---|---|
committer | Wolfgang Pieb <wolfgang_pieb@playstation.sony.com> | 2022-08-12 11:07:18 -0700 |
commit | 7ddfb4dfeb1c52fa0714f1a0784899d7ccd23900 (patch) | |
tree | 3b43fa9b273a313409a5004826a703a07ed8acbe /llvm/lib/Analysis/InlineCost.cpp | |
parent | 2f025e0e78fd57923aceb49c7d4aeb3e5e2d34bf (diff) | |
download | llvm-7ddfb4dfeb1c52fa0714f1a0784899d7ccd23900.zip llvm-7ddfb4dfeb1c52fa0714f1a0784899d7ccd23900.tar.gz llvm-7ddfb4dfeb1c52fa0714f1a0784899d7ccd23900.tar.bz2 |
[Inlining] Introduce the function attribute "inline-max-stacksize"
The value of the attribute is a size in bytes. It has the effect of
suppressing inlining of functions whose stacksizes exceed the given value.
Reviewed By: mtrofin
Differential Revision: https://reviews.llvm.org/D129904
Diffstat (limited to 'llvm/lib/Analysis/InlineCost.cpp')
-rw-r--r-- | llvm/lib/Analysis/InlineCost.cpp | 27 |
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(); |