The LDC D compiler for LLVM can inline indirect function calls under some circumstances if it can prove that the target is statically known. Here's a toy example (in D) of where this might happen:
void main() {
uint num;
void incNum() {
num++;
}
auto myDelegate = &incNum;
myDelegate();
}
In this case, even though the myDelegate()
call is nominally an indirect call, the target is obvious to a human reader and to LLVM/LDC's flow analysis, so it gets inlined.
How widespread a feature is the ability to inline indirect function calls to statically knowable targets in modern compilers? Is LLVM the only one ahead-of-time compiler that can do this? Is it more common with JIT compilers?