[LLVMdev] Writing a backend for the ZPU

Øyvind Harboe oyvind.harboe at zylin.com
Thu Nov 18 12:57:44 PST 2010


Hi,

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
instructions.

http://lists.cs.uiuc.edu/pipermail/llvmdev/2008-November/018621.html
http://lists.cs.uiuc.edu/pipermail/llvmdev/2008-June/015430.html

Work-in-progress git repository:

http://repo.or.cz/w/llvm/zpu.git


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
    add
    im 123
    add
    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)

-- 
Øyvind Harboe

Can Zylin Consulting help on your project?

US toll free 1-866-980-3434 / International +47 51 63 25 00

http://www.zylin.com/zy1000.html
ARM7 ARM9 ARM11 XScale Cortex
JTAG debugger and flash programmer




More information about the llvm-dev mailing list