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

Andrea_DiBiagio at sn.scee.net Andrea_DiBiagio at sn.scee.net
Tue Sep 10 10:59:37 PDT 2013


Hi Eric,

llvm-commits-bounces at cs.uiuc.edu wrote on 10/09/2013 18:24:33:

> From: Eric Christopher <echristo at gmail.com>
> 
> 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
> 

the main reason why in my opinion we shouldn't inline a optnone function 
is to guaratee that the code coming from an optnone function is never 
optimized. 
The only other alternative I can think of to guarantee this would be to 
propagate the optnone attribute to the caller function which I think is 
undesirable because the aim of the attribute is to allow a single function 
to be not optimized in the context of an otherwise optimized compilation 
unit.

Does this sound reasonable to you?

> 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
> >
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


**********************************************************************
This email and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are addressed. 
If you have received this email in error please notify postmaster at scee.net
This footnote also confirms that this email message has been checked for 
all known viruses.
Sony Computer Entertainment Europe Limited
Registered Office: 10 Great Marlborough Street, London W1F 7LP, United 
Kingdom
Registered in England: 3277793
**********************************************************************

P Please consider the environment before printing this e-mail



More information about the llvm-commits mailing list