[LLVMdev] Conditions that cause Clang refuse inlining a function

David Sela sela.david at gmail.com
Thu Sep 4 06:57:29 PDT 2014


Can these thresholds be customized with flags?
The always_inline attribute is only a hint and I can't know if the compiler
will actually do the inline or not.


On Thu, Sep 4, 2014 at 4:08 PM, David Blaikie <dblaikie at gmail.com> wrote:

> There are lots of reasons a compiler will choose not to inline a function
> (inlining, while usually a win for performance is a time/space tradeoff, so
> often a compiler will try not to make a function 'too large' by inlining
> too many functions into it - it will simply so at some threshold)
>
> In any case, if the correctness of your program depends on the function
> being inlined, you can use the always_inline attribute.
> On Sep 4, 2014 5:46 AM, "David Sela" <sela.david at gmail.com> wrote:
>
>> Hi Anton,
>> Thanks for the answer.
>>
>> The link you provided doesn't answer the question. It lists the ways to
>> overcome the linking error if the inline was not successful.
>> The only condition that is found there to make the compiler not inline is
>> "when compiling without optimization".
>>
>> I asked the question in the forum because I think that this info is not
>> documented and most chances that the people that know the code inside-out
>> will know the answer.
>>
>> Thanks,
>> David
>>
>>
>>
>> On Thu, Sep 4, 2014 at 3:30 PM, Anton Korobeynikov <
>> anton at korobeynikov.info> wrote:
>>
>>> Hello
>>>
>>> First of all, such a question definitely belongs to cfe-dev, not llvmdev.
>>>
>>> Next, 'inline' is certainly a hint, and the full the answer is a first
>>> entry here: http://clang.llvm.org/compatibility.html#inline
>>>
>>> On Thu, Sep 4, 2014 at 3:42 PM, David Sela <sela.david at gmail.com> wrote:
>>> > Hi,
>>> >
>>> > I want to have some functions in my code inline so I use the inline
>>> keyword:
>>> >
>>> > inline void foo() {}
>>> >
>>> > On some functions the compiler inlines the function but it fails to do
>>> so on
>>> > other functions and thus I get a linkage error:
>>> >
>>> > error: undefined reference to 'foo'
>>> >
>>> > What are the conditions that make the compiler refuse inline?
>>> >
>>> > Thanks,
>>> > David
>>> >
>>> > p.s. I know that there are ways to pass compilation and let the
>>> compiler
>>> > decide if to inline like using __attribute__((always_inline)) but I
>>> must
>>> > have the function inline.
>>> >
>>> > _______________________________________________
>>> > LLVM Developers mailing list
>>> > LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>>> > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>> >
>>>
>>>
>>>
>>> --
>>> With best regards, Anton Korobeynikov
>>> Faculty of Mathematics and Mechanics, Saint Petersburg State University
>>>
>>
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140904/ba5cfeb7/attachment.html>


More information about the llvm-dev mailing list