[Inlining] Add a clang option to limit inlining of functions
Add the clang option -finline-max-stacksize=<N> to suppress inlining of functions whose stack size exceeds the given value. Reviewed By: aeubanks Differential Revision: https://reviews.llvm.org/D131986
This commit is contained in:
@@ -945,6 +945,10 @@ Inline suitable functions
|
||||
|
||||
Inline functions which are (explicitly or implicitly) marked inline
|
||||
|
||||
.. option:: -finline-max-stacksize=<arg>
|
||||
|
||||
Suppress inlining of functions with a stacksize larger than <arg> bytes.
|
||||
|
||||
.. option:: -fno-legacy-pass-manager, -fexperimental-new-pass-manager
|
||||
|
||||
.. option:: -fno-sanitize-ignorelist, -fno-sanitize-blacklist
|
||||
|
||||
@@ -399,6 +399,9 @@ CODEGENOPT(CodeViewGHash, 1, 0)
|
||||
/// The kind of inlining to perform.
|
||||
ENUM_CODEGENOPT(Inlining, InliningMethod, 2, NormalInlining)
|
||||
|
||||
/// The maximum stack size a function can have to be considered for inlining.
|
||||
VALUE_CODEGENOPT(InlineMaxStackSize, 32, UINT_MAX)
|
||||
|
||||
// Vector functions library to use.
|
||||
ENUM_CODEGENOPT(VecLib, VectorLibrary, 3, NoLibrary)
|
||||
|
||||
|
||||
@@ -1985,6 +1985,11 @@ def finline_functions : Flag<["-"], "finline-functions">, Group<f_clang_Group>,
|
||||
def finline_hint_functions: Flag<["-"], "finline-hint-functions">, Group<f_clang_Group>, Flags<[CC1Option]>,
|
||||
HelpText<"Inline functions which are (explicitly or implicitly) marked inline">;
|
||||
def finline : Flag<["-"], "finline">, Group<clang_ignored_f_Group>;
|
||||
def finline_max_stacksize_EQ
|
||||
: Joined<["-"], "finline-max-stacksize=">,
|
||||
Group<f_Group>, Flags<[CoreOption, CC1Option]>,
|
||||
HelpText<"Suppress inlining of functions whose stack size exceeds the given value">,
|
||||
MarshallingInfoInt<CodeGenOpts<"InlineMaxStackSize">, "UINT_MAX">;
|
||||
defm jmc : BoolFOption<"jmc",
|
||||
CodeGenOpts<"JMCInstrument">, DefaultFalse,
|
||||
PosFlag<SetTrue, [CC1Option], "Enable just-my-code debugging">,
|
||||
|
||||
@@ -2372,6 +2372,9 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, llvm::Function *F,
|
||||
if (getLangOpts().OpenMP && FD->hasAttr<OMPDeclareSimdDeclAttr>())
|
||||
getOpenMPRuntime().emitDeclareSimdFunction(FD, F);
|
||||
|
||||
if (CodeGenOpts.InlineMaxStackSize != UINT_MAX)
|
||||
F->addFnAttr("inline-max-stacksize", llvm::utostr(CodeGenOpts.InlineMaxStackSize));
|
||||
|
||||
if (const auto *CB = FD->getAttr<CallbackAttr>()) {
|
||||
// Annotate the callback behavior as metadata:
|
||||
// - The callback callee (as argument number).
|
||||
|
||||
@@ -6592,6 +6592,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
|
||||
InlineArg->render(Args, CmdArgs);
|
||||
}
|
||||
|
||||
Args.AddLastArg(CmdArgs, options::OPT_finline_max_stacksize_EQ);
|
||||
|
||||
// FIXME: Find a better way to determine whether the language has modules
|
||||
// support by default, or just assume that all languages do.
|
||||
bool HaveModules =
|
||||
|
||||
8
clang/test/CodeGen/inline-stacksize.c
Normal file
8
clang/test/CodeGen/inline-stacksize.c
Normal file
@@ -0,0 +1,8 @@
|
||||
// RUN: %clang_cc1 -O2 -emit-llvm %s -o - | FileCheck %s --check-prefixes NOOPT
|
||||
// RUN: %clang_cc1 -O2 -finline-max-stacksize=64 -emit-llvm %s -o - | FileCheck %s --check-prefix OPT
|
||||
|
||||
void foo() {}
|
||||
|
||||
// NOOPT-NOT: inline-max-stacksize
|
||||
// OPT: define {{.*}}@foo{{.*}}#[[ATTR:[0-9]+]]
|
||||
// OPT: attributes #[[ATTR]] = {{.*}}"inline-max-stacksize"="64"
|
||||
Reference in New Issue
Block a user