[PATCH] [PATCH] Teach the Inliner about attribute optnone

Eric Christopher echristo at gmail.com
Tue Sep 10 10:24:33 PDT 2013


While I can understand not inlining into an opt-none function, why not
allow it to be inlined into other functions? Note that I'm not
objecting, just interested in the rationale.

-eric

On Tue, Sep 10, 2013 at 8:48 AM, Andrea Di Biagio
<Andrea_DiBiagio at sn.scee.net> wrote:
> andreadb added you to the CC list for the revision "[PATCH] Teach the Inliner about attribute optnone".
>
> This patch teaches the Inliner about attribute optnone.
>
> The rules are:
>  * a function marked optnone is never inlined;
>  * only functions marked always_inline can be inlined inside a function with attribute optnone.
>
> I added an LLVM test that verifies on a simple example the inliner behavior with the presence of an always_inline function, an optnone function and a "normal" function.
>
> Attribute optnone was originally discussed here: http://llvm.1065342.n5.nabble.com/RFC-add-Function-Attribute-to-disable-optimization-td58549.html
>
> r189101 introduced attribute optnone as a function attribute.
> I plan to send more patches (two at least) to teach the rest of the optimizer about attribute optnone and also teach clang about this new attribute.
>
> Please let me know what do you think.
>
> Thanks,
> Andrea Di Biagio
>
> http://llvm-reviews.chandlerc.com/D1642
>
> Files:
>   lib/Analysis/IPA/InlineCost.cpp
>   test/Transforms/Inline/inline-optnone.ll
>
> Index: lib/Analysis/IPA/InlineCost.cpp
> ===================================================================
> --- lib/Analysis/IPA/InlineCost.cpp
> +++ lib/Analysis/IPA/InlineCost.cpp
> @@ -1201,6 +1201,16 @@
>      return llvm::InlineCost::getNever();
>    }
>
> +  // Never inline functions without always-inline attributes if the
> +  // caller has optnone attribute.
> +  if (CS.getCaller()->hasFnAttribute(Attribute::OptimizeNone))
> +    return llvm::InlineCost::getNever();
> +
> +  // Don't inline this call if the caller has the optnone attribute
> +  // (and the callee doesn't have always_inline, checked previously).
> +  if (Callee->hasFnAttribute(Attribute::OptimizeNone))
> +    return llvm::InlineCost::getNever();
> +
>    // Never inline functions with conflicting attributes (unless callee has
>    // always-inline attribute).
>    if (!functionsHaveCompatibleAttributes(CS.getCaller(), Callee))
> Index: test/Transforms/Inline/inline-optnone.ll
> ===================================================================
> --- test/Transforms/Inline/inline-optnone.ll
> +++ test/Transforms/Inline/inline-optnone.ll
> @@ -0,0 +1,52 @@
> +; RUN: opt < %s -inline -S | FileCheck %s
> +
> +; Test that functions with attribute optnone are not inlined.
> +; Also test that only functions with attribute alwaysinline
> +; are valid candidate for inlining if the caller has optnone attribute.
> +
> +; Function Attrs: alwaysinline nounwind readnone uwtable
> +define i32 @alwaysInlineFunction(i32 %a) #0 {
> +entry:
> +  %mul = mul i32 %a, %a
> +  ret i32 %mul
> +}
> +
> +; Function Attrs: nounwind readnone uwtable
> +define i32 @simpleFunction(i32 %a) #1 {
> +entry:
> +  %add = add i32 %a, %a
> +  ret i32 %add
> +}
> +
> +; Function Attrs: nounwind optnone readnone uwtable
> +define i32 @OptnoneFunction(i32 %a) #2 {
> +entry:
> +  %0 = tail call i32 @alwaysInlineFunction(i32 %a)
> +  %1 = tail call i32 @simpleFunction(i32 %a)
> +  %add = add i32 %0, %1
> +  ret i32 %add
> +}
> +
> +; CHECK-LABEL: @OptnoneFunction
> +; CHECK-NOT: call i32 @alwaysInlineFunction(i32 %a)
> +; CHECK: call i32 @simpleFunction(i32 %a)
> +; CHECK: ret
> +
> +; Function Attrs: nounwind readnone uwtable
> +define i32 @bar(i32 %a) #1 {
> +entry:
> +  %0 = tail call i32 @OptnoneFunction(i32 5)
> +  %1 = tail call i32 @simpleFunction(i32 6)
> +  %add = add i32 %0, %1
> +  ret i32 %add
> +}
> +
> +; CHECK-LABEL: @bar
> +; CHECK: call i32 @OptnoneFunction(i32 5)
> +; CHECK-NOT: call i32 @simpleFunction(i32 6)
> +; CHECK: ret
> +
> +
> +attributes #0 = { alwaysinline nounwind readnone uwtable }
> +attributes #1 = { nounwind readnone uwtable }
> +attributes #2 = { nounwind optnone readnone uwtable }
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>



More information about the llvm-commits mailing list