This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG8564e2fea559: [Inlining] Add a clang option to limit inlining of functions (authored by wolfgangp). Herald added a project: clang.
Changed prior to commit: https://reviews.llvm.org/D131986?vs=453079&id=453748#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D131986/new/ https://reviews.llvm.org/D131986 Files: clang/docs/ClangCommandLineReference.rst clang/include/clang/Basic/CodeGenOptions.def clang/include/clang/Driver/Options.td clang/lib/CodeGen/CodeGenModule.cpp clang/lib/Driver/ToolChains/Clang.cpp clang/test/CodeGen/inline-stacksize.c Index: clang/test/CodeGen/inline-stacksize.c =================================================================== --- /dev/null +++ clang/test/CodeGen/inline-stacksize.c @@ -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" Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -6592,6 +6592,8 @@ 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 = Index: clang/lib/CodeGen/CodeGenModule.cpp =================================================================== --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -2372,6 +2372,9 @@ 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). Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -1985,6 +1985,11 @@ 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">, Index: clang/include/clang/Basic/CodeGenOptions.def =================================================================== --- clang/include/clang/Basic/CodeGenOptions.def +++ clang/include/clang/Basic/CodeGenOptions.def @@ -399,6 +399,9 @@ /// 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) Index: clang/docs/ClangCommandLineReference.rst =================================================================== --- clang/docs/ClangCommandLineReference.rst +++ clang/docs/ClangCommandLineReference.rst @@ -945,6 +945,10 @@ 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
Index: clang/test/CodeGen/inline-stacksize.c =================================================================== --- /dev/null +++ clang/test/CodeGen/inline-stacksize.c @@ -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" Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -6592,6 +6592,8 @@ 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 = Index: clang/lib/CodeGen/CodeGenModule.cpp =================================================================== --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -2372,6 +2372,9 @@ 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). Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -1985,6 +1985,11 @@ 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">, Index: clang/include/clang/Basic/CodeGenOptions.def =================================================================== --- clang/include/clang/Basic/CodeGenOptions.def +++ clang/include/clang/Basic/CodeGenOptions.def @@ -399,6 +399,9 @@ /// 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) Index: clang/docs/ClangCommandLineReference.rst =================================================================== --- clang/docs/ClangCommandLineReference.rst +++ clang/docs/ClangCommandLineReference.rst @@ -945,6 +945,10 @@ 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
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits