aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/InlineCost.cpp
diff options
context:
space:
mode:
authorWolfgang Pieb <wolfgang_pieb@playstation.sony.com>2022-06-22 13:02:01 -0700
committerWolfgang Pieb <wolfgang_pieb@playstation.sony.com>2022-06-23 10:57:46 -0700
commitc50e6f590cd42aa739cc469341721ff443c35c36 (patch)
tree78124a271394ca0e9c0a3d5ffc7c2699f68108ef /llvm/lib/Analysis/InlineCost.cpp
parentb163ac33bdfcd4fca8ae6087081f8de9d72005c5 (diff)
downloadllvm-c50e6f590cd42aa739cc469341721ff443c35c36.zip
llvm-c50e6f590cd42aa739cc469341721ff443c35c36.tar.gz
llvm-c50e6f590cd42aa739cc469341721ff443c35c36.tar.bz2
[Inline] Introduce a backend option to suppress inlining of functions with large stack sizes.
The hidden option max-inline-stacksize=<N> prevents the inlining of functions with a stack size larger than N. Reviewed By: mtrofin, aeubanks Differential Review: https://reviews.llvm.org/D127988
Diffstat (limited to 'llvm/lib/Analysis/InlineCost.cpp')
-rw-r--r--llvm/lib/Analysis/InlineCost.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp
index 0b2c72e..b83f5cf 100644
--- a/llvm/lib/Analysis/InlineCost.cpp
+++ b/llvm/lib/Analysis/InlineCost.cpp
@@ -42,6 +42,7 @@
#include "llvm/Support/Debug.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/raw_ostream.h"
+#include <limits>
using namespace llvm;
@@ -124,6 +125,13 @@ static cl::opt<int> CallPenalty(
"inline-call-penalty", cl::Hidden, cl::init(25),
cl::desc("Call penalty that is applied per callsite when inlining"));
+static cl::opt<size_t>
+ StackSizeThreshold("inline-max-stacksize", cl::Hidden,
+ cl::init(std::numeric_limits<size_t>::max()),
+ cl::ZeroOrMore,
+ cl::desc("Do not inline functions with a stack size "
+ "that exceeds the specified limit"));
+
static cl::opt<bool> OptComputeFullInlineCost(
"inline-cost-full", cl::Hidden,
cl::desc("Compute the full inline cost of a call site even when the cost "
@@ -2707,6 +2715,11 @@ InlineResult CallAnalyzer::analyze() {
if (!OnlyOneCallAndLocalLinkage && ContainsNoDuplicateCall)
return InlineResult::failure("noduplicate");
+ // If the callee's stack size exceeds the user-specified threshold,
+ // do not let it be inlined.
+ if (AllocatedSize > StackSizeThreshold)
+ return InlineResult::failure("stacksize");
+
return finalizeAnalysis();
}