Home > Enterprise >  Do Compilers Un-Inline?
Do Compilers Un-Inline?

Time:02-25

It is fairly common knowledge that the most powerful tool in a compilers tool-belt is the inlining of functions into their call sites. But what about doing the reverse? If so, is it done? And when? For example given:

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

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

Does it ever make sense for the compiler to abstract this out to

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

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

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

CodePudding user response:

Yes, for example LLVM has a MachineOutliner optimization pass.

CodePudding user response:

Outlining makes sense even without repeated code, when the outlined section is [[unlikely]]. The function call is a loss, but unlikely, while on the other hand more likely code can fit in cache.

Compilers might also assume that an exception is unlikely, and outline the catch.

  • Related