The Poletto-Sarkar linear scan register allocator ( is reasonably efficient, reasonably effective, easy to implement, and suitable for an infinite register machine such as Parrot. It requires scanning a compilation unit linearly once to find liveness intervals for all unique registers. In pseudo-code:

  • Walk through all instructions, start to finish in linear order of appearance in the source code
  • For every register reference found:
    • Add the register to a list indexed by its start position, if it does not exist in list
    • Update the register's last position, if it's already in the list
  • After the linear scan has finished, walk the list
  • At every start position
    • Fetch the index of the next available register
    • Assign that to the current register reference
  • At every end position:
    • Recycle the index of the register reference

This should be robust even in the face of calls and branches, both forward and backwards. It should survive manual register allocation (though at some potential performance degradation). It does not require identifying or tracking basic blocks. It could work concurrently with PIR emission from POST. It appears to use the most efficient total number of registers, even if it does not arrange them in any particular order (such is the job of the register number recycler). It does not require the use of SSA, but it does not preclude it.