Writing an LLVM backend
  1. Introduction
  2. Writing a backend
    1. Machine backends
      1. Outline
      2. Implementation details
    2. Language backends
  3. Related reading material

Written by Misha Brukman

Introduction

This document describes techniques for writing backends for LLVM which convert the LLVM representation to machine assembly code or other languages.

Writing a backend
Machine backends
Outline

In general, you want to follow the format of X86 or PowerPC (in lib/Target).

To create a static compiler (one that emits text assembly), you need to implement the following:

You also need to write an instruction selector for your platform. The recommended method is the pattern-matching instruction selector, examples of which you can see in other targets: lib/Target/*/*ISelPattern.cpp. The former method for writing instruction selectors (not recommended for new targets) is evident in lib/Target/*/*ISelSimple.cpp, which are InstVisitor-based translators, generating code for an LLVM instruction at a time. Creating an instruction selector is perhaps the most time-consuming part of creating a back-end.

To create a JIT for your platform:

Note that lib/target/Skeleton is a clean skeleton for a new target, so you might want to start with that and adapt it for your target, and if you are wondering how things are done, peek in the X86 or PowerPC target.

The Skeleton target is non-functional but provides the basic building blocks you will need for your endeavor.

Implementation details
Language backends

For now, just take a look at lib/Target/CBackend for an example of how the C backend is written.

Related reading material

Valid CSS! Valid HTML 4.01! Misha Brukman
The LLVM Compiler Infrastructure
Last modified: $Date$