OpenCores
no use no use 1/1 no use no use
LLVM for OpenRISC: Euro-LLVM 2012 workshop by Anton Korobeynikov
by jeremybennett on Apr 14, 2012
jeremybennett
Posts: 815
Joined: May 29, 2008
Last seen: Jun 13, 2019

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 cloned from GitHub at

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:

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 from the website above when the slides and video become available.

Jeremy

--
Tel: +44 (1590) 610184
Cell: +44 (7970) 676050
SkypeID: jeremybennett
Email: jeremy.bennett@embecosm.com
Web: www.embecosm.com

no use no use 1/1 no use no use
© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.