Writing a backend for the ZPU


I'm trying to have another stab at writing an LLVM ZPU backend.

Any pointers or encouragement would be greatly appreciated.

So far I've been wandering around the LLVM trying to read up and
I've hacked together something that builds just to experiment and
get a feel for the build system. I was able to write a backend
for GCC which has been in use for years now, but I can't
devote anything like the resources I devoted to the GCC ZPU
backend, but hoping to pull it off anyway. So far I like LLVM better
by far in terms of the actual code and how it's put together, even
if my understanding is very superficial.

The advice I've gotten so far on this list is to use normal registers
before register allocation and then switch to stack slots after
register allocation much like x86 stackifer, using two sets of


Work-in-progress git repository:


Some thoughts/problems:

- In GCC I created registers which were just stack slots in the
stack frame. This allowed the reload and register allocation to
do it's thing. What kind pre-stackifier register file do I define
for the ZPU?

- In GCC I wrote a piece of C that recursively unrolled
intermediate representation to machine code instructions.
So any treedepth was fine as long as it consisted of
operations that were supported by the instruction set. I'm can't
get a handle on how to translate this hack to llvm so far.

A typical ZPU machine code add might look something like this:

a = a + b + 123;


    loadsp 16 # push value at memory location sp+16 onto stack
    loadsp 24 # another value
    im 123
    storesp 20 # store back to original location. Notice 16+4=20

LLVM represents the above as something like:

(set a, (add (add a,b), 123)