As some of you know, I spent the last two days at the Euro-LLVM
conference in London. The final event was a workshop "Building a backend
in 24 hours" given by Anton Korobeynikov. Anton used the OpenRISC as his
example processor, based on work he carried out on 5/6 April. His work
can be downloaded cloned from GitHub at

        https://github.com/asl/llvm-openrisc.git

The changes can be seen by a git diff against git commit
9751b81fc97dcb6ecc4be4304ef8e6e8cf79f6e4, the point at which he branched
from the main tree.

As promised, this is my short summary of the presentation. The slides
and I believe video will be available shortly through the LLVM website:

        http://llvm.org/devmtg/2012-04-12/

OVERVIEW
========

Anton started by outlining the levels at which target specific code can
be introduced
- LLVM IR passes
- Selection DAG (SDAG) passes
- MI passes
- MC streamers

LLVM IR passes
- some things easier to do here
- can simplify codegen
- safer (more fixed pass order)

SDAG passes
- first strictly backend IR - lower level than LLVM IR
- built on a per-BB basis
- concludes with instruction selection

MI passes
- register allocation
- yet another sort of IR

MC streamers
- lower MI level to MCInst
- let the MC streamers decide what to do next

Customization
- can add own passes - e.g. for delay slot filling

BACKEND DETAILS
===============

- standalone library
- C++ and TableGen
  - TableGen is domain specific language to specify
    - reg sets
    - calling conventions
    - instruction patterns
- inheritance and overloading are used to add target specific bits

Stub Backend
- Q: what is needed to do nothing
- A: quite a lot
     - 15 classes
     - 1KLOC c++ and TableGen
- 15 key classes to be defined

EXAMPLE: OPENRISC
=================

Goal to process a trivial LLVM IR fragment

Steps:
- add or32 as target triple
- implement the 15 stub classes
- define all regs and classes
- define calling convention
- implement hooks
  - copying physical regs, prologue/epilogue etc
- add standard boiler plate
- implement LowerFunctionArguments
  - non-trivial: look at MSP 430 for example
- convert MI to MC (straightforward)
- MCInst printing (also straightforward)
- add first instruction: function return
  - add pattern
  - note branch delay TODO

Adding Clang
- to write testcases in C
- provide TargetInfo for binutils-ish tool chain
- detailed tool chain description done later

Next steps
- reg-reg arithmetic
- load/store: match address modes
- proper function frames
- delay slot filling
- branch folding
- ...

Q&A
===

I asked how long it would take to complete the implementation, so that
reasonable swathes of complex C/C++ could be compiled. Apparently the
MSP 430 took him 3 weeks working evenings and weekends. Longer for a
non-expert of course.

Hope this is useful. Full detail when the slides become available.


Jeremy

-- 
Tel:     +44 (1590) 610184
Cell:    +44 (7970) 676050
SkypeID: jeremybennett
Email:   [email protected]
Web:     www.embecosm.com


_______________________________________________
OpenRISC mailing list
[email protected]
http://lists.openrisc.net/listinfo/openrisc

Reply via email to