Skip to main content

Module inline_pass

Module inline_pass 

Source
Expand description

Public API for inline_pass. Function inlining pass.

Replaces call instructions to small, non-recursive, non-variadic functions with a copy of the callee body.

§Algorithm

For each eligible call site in a caller function:

  1. Split the caller block at the call instruction, producing a pre-block (instructions before the call) and a post-block (instructions after the call, plus the original terminator).
  2. Clone the callee’s blocks into the caller, mapping:
    • Callee Argument(ArgId(i)) → the i-th call argument.
    • Callee InstrId(j)InstrId(caller_instr_count + j).
    • Callee BlockId(k)BlockId(caller_block_count + k).
  3. Wire the pre-block to the cloned callee entry with an unconditional branch.
  4. Replace each ret %v in the clone with br post-block, and collect return values into a phi at the head of the post-block (or directly if there is only one return site).
  5. Remove the original call instruction.

§Eligibility

A call site is inlineable when:

  • The callee is a definition (not a declaration).
  • The callee is not variadic.
  • The call is not recursive (callee ≠ caller by name).
  • The callee body has at most size_limit non-terminator instructions.

Structs§

Inliner
Function inlining pass.