编译器是否内联?

Jac*_*aib 3 c++ compiler-construction optimization

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

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

void bop()
{
  int x;
  auto y = bar(x);
  baz(y);
}
Run Code Online (Sandbox Code Playgroud)

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

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

void foo(int x)
{
  qux(x);
}

void bop()
{
  int x;
  qux(x);
}
Run Code Online (Sandbox Code Playgroud)

yug*_*ugr 6

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