tags:

views:

95

answers:

5

Hi,

I have to check whether a function is being inlined by the compiler. Is there any way to do this without looking at assembly (which I don't read). I have no choice in figuring this out, so I would prefer if we could not discuss the wisdom of doing this. Thanks!

+3  A: 

Each call site may potentially be different.

The compiler may decide for certain parent methods it is worth inlining and for other parent methods that it is not worth inlining. Thus you can not actually determine the real answer without examing the assembley at each call site.

As a result any tools you use would potentially give you a misleading answer. If you use a tool that checks for the existance of symbol (it may be there because some call sites need it, but potentially it may be inlined at others). Conversely the lack of the symbol does not mean the method/function is not inlined it may be static (as in file static) and thus the compiler does not need to keep the symbol around (yet it was not inlined).

Martin York
+2  A: 

Using the /FAs compiler option to dump the asm with source code is the only way that I know of to be sure.

Note: if you want to force a function to be inline, just use __forceinline.

gatorfax
__forceinline does not force inlining in all cases though. http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx
Ron Warholic
A: 

If you really don't want to jump into assembly, declare the function as __forceinline, and if the executable gets larger, you know it wasn't being inlined.

Nathan
Not necessarily. A typical member get function, for example, could actually result in smaller code when inlined. It would result in a member access via the this pointer rather than a push of this, call the function, access member via this, return from function.
Richard Pennington
True enough, but if it was already being lined, __forceinline shouldn't change anything, so what I should've said is if the executable changes size. Good catch.
Nathan
-1, the problem is that the reverse isn't true for the reasons Richard gives. If the executable doesn't change its size, what can you conclude?
MSalters
+2  A: 

If you enable warnings C4714, C4710, and C4711, it should give you fairly detailed information about which functions are and aren't inlined.

DrPizza
+1  A: 

Generate a "MAP" file. This gives you the addresses of all non-inlined functions. If your function appears in this list, it's not inlined, otherwise it's either inlined or optimized out entirely (e.g. when it's not called at all).

MSalters