<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Jun 24, 2015 at 12:56 PM, Xinliang David Li <span dir="ltr"><<a href="mailto:xinliangli@gmail.com" target="_blank">xinliangli@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">The problem is that the other way around is not true: a function linkonce_odr linkage may be neither inline declared nor have in-class definition.</div></blockquote><div><br></div><div>The other common case where a linkonce_odr function will appear is when instantiating a function template. Now consider:</div><div><br></div><div>  struct X {</div><div>    void f() { /*...*/ }</div><div>    inline void g() { /*...*/ }</div><div>  };</div><div><br></div><div>and</div><div><br></div><div>  template<typename T> void f() { /*...*/ }</div><div>  template<typename T> inline void g() { /*...*/ }</div><div><br></div><div>I think you're saying that the inline keyword should cause us to inline more aggressively in the template case but not in the inline-function-in-class-body case. That seems inconsistent to me (but not necessarily the wrong thing): in both cases, the definition of f was put into the header because it was convenient (or necessary), and not necessarily because the user was thinking about inlining, and in both cases the presence of the redundant 'inline' keyword seems like a hint that they want the function to be more aggressively inlined.</div><div><br></div><div>Do we know whether the benefit we see by more aggressively inlining member functions defined within the class definition is actually because they're good candidates for inlining, or is it because inlining small functions more aggressively is a net win in general, and being defined inside the class is a good signal for "small function"?</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><div class="gmail_quote">On Wed, Jun 24, 2015 at 11:53 AM, Robinson, Paul <span dir="ltr"><<a href="mailto:Paul_Robinson@playstation.sony.com" target="_blank">Paul_Robinson@playstation.sony.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span><br>
<br>
> -----Original Message-----<br>
> From: <a href="mailto:llvmdev-bounces@cs.uiuc.edu" target="_blank">llvmdev-bounces@cs.uiuc.edu</a> [mailto:<a href="mailto:llvmdev-bounces@cs.uiuc.edu" target="_blank">llvmdev-bounces@cs.uiuc.edu</a>] On<br>
> Behalf Of Easwaran Raman<br>
</span><span>> Sent: Wednesday, June 24, 2015 9:54 AM<br>
> To: Xinliang David Li<br>
> Cc: <<a href="mailto:llvmdev@cs.uiuc.edu" target="_blank">llvmdev@cs.uiuc.edu</a>> List<br>
> Subject: Re: [LLVMdev] Inline hint for methods defined in-class<br>
><br>
> Ping.<br>
><br>
> On Wed, Jun 17, 2015 at 4:13 PM, Xinliang David Li <<a href="mailto:davidxl@google.com" target="_blank">davidxl@google.com</a>><br>
> wrote:<br>
> > that looks like a different fix. The case mentioned by Easwaran is<br>
> ><br>
> > class A{<br>
> >    int foo () { return 1; }<br>
> >   ...<br>
> > };<br>
> ><br>
> > where 'foo' is not explicitly declared with 'inline' keyword.<br>
> ><br>
> > David<br>
> ><br>
> > On Wed, Jun 17, 2015 at 4:07 PM, Balaram Makam <<a href="mailto:bmakam@codeaurora.org" target="_blank">bmakam@codeaurora.org</a>><br>
> wrote:<br>
> >> AFAIK, this was fixed in r233817.<br>
<br>
</span>That was later reverted.<br>
<div><div><br>
> >><br>
> >> -----Original Message-----<br>
> >> From: <a href="mailto:llvmdev-bounces@cs.uiuc.edu" target="_blank">llvmdev-bounces@cs.uiuc.edu</a> [mailto:<a href="mailto:llvmdev-bounces@cs.uiuc.edu" target="_blank">llvmdev-bounces@cs.uiuc.edu</a>]<br>
> On<br>
> >> Behalf Of Easwaran Raman<br>
> >> Sent: Wednesday, June 17, 2015 6:59 PM<br>
> >> To: <a href="mailto:llvmdev@cs.uiuc.edu" target="_blank">llvmdev@cs.uiuc.edu</a><br>
> >> Cc: David Li<br>
> >> Subject: [LLVMdev] Inline hint for methods defined in-class<br>
> >><br>
> >> Clang adds the InlineHint attribute to functions that are explicitly<br>
> marked<br>
> >> inline, but not if they are defined in the class body. I tried the<br>
> following<br>
> >> patch, which I believe handles the in-class definition<br>
> >> case:<br>
> >><br>
> >> --- a/lib/CodeGen/CodeGenFunction.cpp<br>
> >> +++ b/lib/CodeGen/CodeGenFunction.cpp<br>
> >> @@ -630,7 +630,7 @@ void CodeGenFunction::StartFunction(GlobalDecl GD,<br>
> >>    if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) {<br>
> >>      if (!CGM.getCodeGenOpts().NoInline) {<br>
> >>        for (auto RI : FD->redecls())<br>
> >> -        if (RI->isInlineSpecified()) {<br>
> >> +        if (RI->isInlined()) {<br>
> >>            Fn->addFnAttr(llvm::Attribute::InlineHint);<br>
> >>            break;<br>
> >>          }<br>
> >><br>
> >> I tried this on C++ benchmarks in SPEC 2006. There is no noticeable<br>
> >> performance difference and the maximum text size increase is < 0.25%.<br>
> >> I then built clang with and without this change. This increases the<br>
> text<br>
> >> size by 4.1%.  For measuring performance, I compiled a large (4.8<br>
> million<br>
> >> lines) preprocessed file. This change improves runtime performance by<br>
> 0.9%<br>
> >> (average of 10 runs) in O0 and O2.<br>
> >><br>
> >> I think knowing whether a function is defined inside a class body is a<br>
> >> useful hint to the inliner. FWIW, GCC's inliner doesn't differentiate<br>
> these<br>
> >> from explicit inline functions. If the above results doesn't justify<br>
> this<br>
> >> change, are there other benchmarks that I should evaluate? Another<br>
> >> possibility is to add a separate hint for this instead of using the<br>
> existing<br>
> >> inlinehint to allow for better tuning in the inliner.<br>
<br>
</div></div>A function with an in-class definition will have linkonce_odr linkage,<br>
so it should be possible to identify such functions in the inliner<br>
without introducing the inlinehint attribute.<br>
--paulr<br>
<div><div><br>
> >><br>
> >> Thanks,<br>
> >> Easwaran<br>
> >> _______________________________________________<br>
> >> LLVM Developers mailing list<br>
> >> <a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" rel="noreferrer" target="_blank">http://llvm.cs.uiuc.edu</a><br>
> >> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
> >><br>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" rel="noreferrer" target="_blank">http://llvm.cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" rel="noreferrer" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</div></div></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" rel="noreferrer" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div></div>