[PATCH]: -fno-inline doesnt prevent inlining

Justin Bogner mail at justinbogner.com
Tue Jan 14 15:14:50 PST 2014


Roman Divacky <rdivacky at freebsd.org> writes:
> Hi,
>
> Currently -fno-inline doesnt do much, it just prevents adding InlineHint
> attributes. This means that we differ from gcc which prevents all
> functions (except always_inline) from inlining. This simple patch
> implements that behaviour, is that ok?
>
> Index: lib/CodeGen/CodeGenFunction.cpp
> ===================================================================
> --- lib/CodeGen/CodeGenFunction.cpp	(revision 199224)
> +++ lib/CodeGen/CodeGenFunction.cpp	(working copy)
> @@ -510,7 +510,7 @@
>  
>    // Pass inline keyword to optimizer if it appears explicitly on any
>    // declaration.
> -  if (!CGM.getCodeGenOpts().NoInline)
> +  if (!CGM.getCodeGenOpts().NoInline) {
>      if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D))
>        for (FunctionDecl::redecl_iterator RI = FD->redecls_begin(),
>               RE = FD->redecls_end(); RI != RE; ++RI)
> @@ -518,6 +518,10 @@
>            Fn->addFnAttr(llvm::Attribute::InlineHint);
>            break;
>          }
> +  } else if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D))
> +    if (!FD->hasAttr<AlwaysInlineAttr>() &&
> +        !FD->hasAttr<ForceInlineAttr>())
> +      Fn->addFnAttr(llvm::Attribute::NoInline);

In addition to Alp's suggesting of hoisting the dyn_cast_or_null to the
top level, this logic would be easier to read if we avoid the double
negative and put the NoInline case first (ie, instead of "if
(!NoInline)" we say "if (NoInline)").

>    if (getLangOpts().OpenCL) {
>      // Add metadata for a kernel function.
> Index: test/CodeGen/noinline.c
> ===================================================================
> --- test/CodeGen/noinline.c	(revision 199224)
> +++ test/CodeGen/noinline.c	(working copy)
> @@ -7,6 +7,7 @@
>  
>  volatile int *pa = (int*) 0x1000;
>  void foo() {
> +// NOINLINE: Function Attrs: noinline
>  // NOINLINE: @foo
>  // NOINLINE: dont_inline_me
>  // NOINLINE-NOT: inlinehint
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits



More information about the cfe-commits mailing list