Are there strong reasons to do this by adding attributes rather than
changing the optimizer's behavior? I'm uncertain.

On one hand, it would be more efficient in the optimizer to just switch to
the always-inliner pass.

On the other hand, if we are doing an LTO build, adding attributes ensures
that even the link-top inline step doesn't inline those functions.

On the other other hand, if we are doing an LTO build, we might want to
only prevent inlining during the per-TU optimization run, not during the
LTO optimization run.

Thoughts?


On Tue, Jan 14, 2014 at 11:58 AM, Roman Divacky <[email protected]>wrote:

> 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);
>
>    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
> [email protected]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to