How can you say what will happen or what will not be done by the built-in compiler?
You cannot at all.
You can read the Inline Redux article by Herb Sutter. He reveals a number of technologies to explain when embedding can happen, knowing that the latter happens ... the more information you have.
For example, in the JIT environment, you can look at the loop, understand that its entire body is executed on one object, which seems to be often of type Foo
, specializes the entire object for Foo
, which allows you to fully embed virtual methods and now check at the top loop if the object is Foo
, and if so, switch to a fully integrated version of the shell instead of shared with virtual calls.
So what can be embedded? It depends on when ...
In general, C ++ compilers:
- Insert compilation time (historical)
- Link Binding Time (part of the so-called LTO optimization package)
This means that they can only base their optimizations on static ones (known at compile time).
At the time of compilation, this means that if the static type, the virtual call can be devirtualized (the first step of the attachment: guessing the called function;)). This means that any function whose definition is visible can also be embedded.
At a point in time for a library, you basically discover new function definitions that allow you to embed multiple calls.
At a point in time for a WPA (Whole Program Analysis) executable file, it may begin to add some devirtualization, realizing that some classes never succeed, and therefore we can consider final
with respect to this executable. Neither GCC nor LLVM (and I doubt that VC ++ can) can perform this optimization, although due to the fact that they do not have byte code that supports class hierarchies.
And compilers could, if they wanted to, drop the intermediate representation that they have (bytecode in some way) and wait for the installation for built-in calls specific to the OS. Although I don't know anything (for C ++) that do this.
Changes to the runtime are quite complicated in C ++, because the memory (for example, the addresses of functions) is available to the programmer, so it would be difficult to make only safe conversions ...