[LLVMdev] inlining hint

Reid Kleckner rnk at mit.edu
Thu Aug 27 16:02:58 PDT 2009


On Thu, Aug 27, 2009 at 6:00 PM, David Greene<dag at cray.com> wrote:
> On Wednesday 26 August 2009 12:59, Dale Johannesen wrote:
>
>> class X {
>>     int A(int x) {....}
>>     inline int B(int x);
>> };
>> inline int X::B(int x) {...}
>>
>> Per the language standard, A and B are semantically identical, both
>> "inline".  It's been suggested that we should omit the inlinehint on
>> A, on the grounds that many C++ programmers do not know this, and
>> therefore misuse the construct.
>
> No, no, no!  :)  I rely on this behavior.  I assume anything I define
> in the class definition will be inlined (when reasonable).  I do this for
> performance reasons.

I would say that I am a new and inexpert C++ programmer, and I always
thought the idea of putting methods in headers was not a way of saying
to the compiler "please inline this" but rather a way to expose it to
the compiler so that it would be possible to inline.  When writing
templates or helper classes, I've always written the methods inline in
the class definition because it creates less duplication.  If you're
coming from Java, this style is of course natural.

So to answer Dale's original question, I would guess that most
inexpert C++ programmers expect that if they define a method inline,
then they are not telling the compiler it should be inlined, but that
the compiler should use its heuristics to decide if it should be.

Reid



More information about the llvm-dev mailing list