Skip to content

Inlining

Dibyendu Majumdar edited this page Jul 12, 2020 · 5 revisions

Some random thoughts about inlining.

What should be inlined?

  • Function that has no upvalues ... ?
  • That doesn't take varargs.
  • Total number of locals must be inside a range

We need to be able to establish that the function cannot be replaced. So it must not be a global. It needs to be a local function in the same chunk. We also need to ensure that the up-value representing the function has no updates - i.e. up-value / and local are both never re-assigned

TODO so what do we know at a call-site?

How to do it

AST level

Maybe at AST level. Duplicate the body of the function to the call-site. Assign args. Assign return values.

The problem is it is harder to analyze the use of variables at the AST stage.

IR level

For this we need to adjust all regs of the inlined function.

Pre-requisites

Variables and blocks must still make sense after the inlining.

Clone this wiki locally