[LLVMdev] Creating an LLVM backend for a very small stack machine

Chris Lattner clattner at apple.com
Mon Feb 23 10:13:21 PST 2009


On Feb 23, 2009, at 7:38 AM, Wesley J. Landaker wrote:

> On Sunday 22 February 2009 23:18:25 Chris Lattner wrote:
>> Have you seen:
>> http://llvm.org/docs/WritingAnLLVMBackend.html
>
> I have, and it's certainly helpful. Since the Kalescope tutorial is so
> amazingly easy to work through that it makes me jealous for a similar
> tutorial on the backend. But I'm definitely not complaining. =)
>
>> If you're targeting a stack machine, I'd strongly recommend not using
>> the llvm register allocators and just run you own custom stackifier
>> pass instead.
>
> After reading
> <http://www.llvm.org/docs/CodeGenerator.html#regAlloc_ssaDecon> is  
> correct
> to say that if I don't use an existing LLVM register allocation  
> pass, that
> I would need to do my stackification directly on the SSA form?
>
> Could/should I still reuse parts like the PHIElimination pass? It  
> sounded
> sort of like this was very coupled with the register allocators.

Sure, reusing just phi elim and 2-addr elim should be possible.

> I'm was initial sort of thinking that for a first (unoptimized) cut  
> I might
> be able to just use the "simple" built-in allocator that spills every
> value, then replace that afterwards with a stack-based allocator.  
> Does that
> sound practical, or would I be painting myself into a corner in the  
> first
> step?

Sure, that could work.  The x86 floating point stack is a stack with  
maximum depth of 8 entries.  The x86 backend implements it by register  
allocating for a 7 entry "register file" and then doing a custom  
transformation to change the code to use pushes/pops exchanges etc.

-Chris



More information about the llvm-dev mailing list