This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How to determine why C++ compiler is not inlining a function?

Hi Folks,

I have some code where I have functions that are declared inline, and I am compiling with -O3. Some of the functions are inlined, but not all of them. I have looked through the C++ compiler docs, and my functions meet the criteria for inlining set forth in the docs. If I add "#pragma FUNC_ALWAYS_INLINE;" before the functions, then the compiler does inline them, and my loops are pipelined as I would expect.

So, the question is why is the compiler deciding not to inline the functions unless I add "#pragma FUNC_ALWAYS_INLINE;"? Is there a compiler switch that will provide this information? Alternatively, is there a compiler switch that will make it more likely to do the inline for inlines that are explicitly marked? Or do I just need to the use the #pragma FUNC_ALWAYS_INLINE;?

TIA,

B.J.

  • The compiler limits inlining of declared-inline functions to avoid blowing itself up.  The limit is generally based upon the size of the caller and the potentially-inlined function plus all its inlined callees, and can be loosely controlled by the --opt_for_space option.  There is no precise control of inlining for declared-inline functions, but FUNC_ALWAYS_INLINE allows overriding the limit.

    There is no switch that provides information about why a function isn't inlined.  We're considering reporting the reasons in the .nfo file but haven't implemented anything like that yet.

  • Ok.

    Thanks for the info. Consider this a vote to add the reporting to the .nfo file as that would be very useful (especially with a comment like "If you really need this function to be inlined, use the pragma FUNC_ALWAYS_INLINE" as it took me a couple of hours to find it.

    The behavior of the compiler was hard to understand, because it was inlining larger functions and refusing to inline smaller ones (that we inlinable with the pragma). The actual size of the code was not any bigger with the inlines than without out it as the code was simply broken up into functions for ease of understanding -- the functions in question were only called once (within a loop) so the actual inlined code was actually smaller than the non-inlined version.

    In any case, it is good to know that I was not just missing something...

    Best regards,

    B.J.