Search code examples
compiler-constructioncompiler-optimization

Difference between a register being live-in and live-out to an instruction


What is the difference between a register being live-in and live-out?

My understanding is that a live-out register means that the register specified in the current line contains a variable that is not changed from its successive line.

Here is some machine code from my Compilers Exam that could assist with an answer

L0 : lim z, 0
L1 : jmp L6
L2 : sub x, x, y
L3 : mov t, z
L4 : lim z, 0
L5 : addi z, t, 1
L6 : blth y, x, L2

Solution

  • The short answer is that for a given instruction in the program, a register is live-in if it is live before the instruction is executed and it is live-out if it is live after the instruction is executed.

    To start from the beginning, a register is live at a given point in the program if its contents will be used before the register is reset. As an example, At the point between L2 and L3, the register z is live since it will be used in the future (by L3) but t is dead since there is no use of t before the value is changed. This implies that z is live-in for L3 and live-out for L2 while t isn't.