compiler construction - register allocation for x86 -
i attempting simple register allocation x86. using linear register allocator have few questions on simple things not finding information about.
int main() { int a, b, c; = 10; b = 20; c = 2; = + b; b = b * 5; c = c * b + a; return c; }
for simple code, ignoring constant propagation, g++ & msvc generate similar code pushes temporaries on stack , uses eax, ebx etc alu ops. clang generates following code o0.
main: # @main movl $0, -4(%rsp) movl $10, -8(%rsp) movl $20, -12(%rsp) movl $2, -16(%rsp) movl -8(%rsp), %eax addl -12(%rsp), %eax movl %eax, -8(%rsp) imull $5, -12(%rsp), %eax movl %eax, -12(%rsp) movl -16(%rsp), %eax imull -12(%rsp), %eax addl -8(%rsp), %eax movl %eax, -16(%rsp) movl -16(%rsp), %eax ret
as evident, temporaries on stack. question based on same thing. at point, should in eax/ebx etc used in add/mul/div operations etc have lifetime more 1 instruction. is, should live range interval have value stored in these registers or should evicted register allocation done , values pushed temporaries ?
or can use of these registers till next alu instruction encountered , lazy push stack when necessary?
Comments
Post a Comment