编译器是否取消内联



众所周知,编译器工具带中最强大的工具是将函数内联到其调用站点。但反过来做呢?如果是,完成了吗?什么时候?例如:

void foo(int x)
{
auto y = bar(x);
baz(y);
}
void bop()
{
int x;
auto y = bar(x);
baz(y);
}

编译器将其抽象为是否有意义

void qux(int x)
{
auto y = bar(x);
baz(y);
}
void foo(int x)
{
qux(x);
}
void bop()
{
int x;
qux(x);
}

是的,例如LLVM有一个MachineOutliner优化过程。

即使没有重复的代码,当大纲部分是[[unlikely]]时,大纲也有意义。函数调用是一种损失,但不太可能,而另一方面,更可能的是代码可以放入缓存。

编译器也可能认为不太可能出现异常,并概述catch

最新更新