I'm writing an ML-like language, and using LLVM as my target back end. I have one question though, and thought I'd throw it out onto the list. In my language, variables aren't mutable- once assigned, they can be shadowed, but not changed. And shadowing of variables is handled by alpha-renaming. What I mean by this that when I see:
let x = 3 in ...
the value of x can not be changed. It can be shadowed, like:
let x = f () in
let x = x + 4 in
but one of the first things I do is rename all the variables so they're unique, so the above code might get changed into:
let x_5734 = f () in
let x_8643 = x_5734 + 4 in
Now, my question is this: is there any downside to not having any stack-based local variables at all- just put everything into registers and let the register allocation code decide what needs to get spilled onto the stack? In other words, is there any problem with generating the following IR for the above code:
%r17 = call i64 @f(i64 0)
%r18 = add i64 %r17 4
The upside of doing this is simpler code generation, and hopefully more efficient code, as I am explicitly telling the optimizer I don't care where this variable lives.
But, I'm somewhat worried that by not having any local variables at all, this may put too much pressure on the register allocator (especially for large functions). Also, how to attach debugging information to a register is something I need to figure out.
Thoughts? Opinions? Is this a good way to proceed, or a bad way?