开发者

MSVC - Any way to check if function is actually inlined?

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 pr开发者_如何学JAVAefer if we could not discuss the wisdom of doing this. Thanks!


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


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).


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.


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).


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜