Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attempting to write an LLVM backend. No good tutorial available [closed]

I am trying to write an LLVM backend for my custom processor that I have designed recently.

I tried to follow the official tutorial at http://llvm.org/docs/WritingAnLLVMBackend.html

But it is so vague, so incomplete and blurry that I failed to follow it.

I then started to search for other tutorials online and all of them suffer from the same symptoms of the original tutorial. It seems the authors assume lots of pre-readings and write their tutorials without necessary preliminary explanations.

How can I find a tutorial or anything that can set me up to write a functional backend in LLVM?

-- Update: I see two down votes and two up votes. The down votes says my question is not related to programming. I wonder how the moderators have concluded that writing a compiler is not related to programming.

like image 262
Ehsan Avatar asked Oct 09 '16 17:10

Ehsan


People also ask

What is an LLVM backend?

The backend of LLVM features a target-independent code generator that may create output for several types of target CPUs — including X86, PowerPC, ARM, and SPARC. The backend may also be used to generate code targeted at SPUs of the Cell processor or GPUs to support the execution of compute kernels.

Is LLVM written in C++?

LLVM is written in C++ and is designed for compile-time, link-time, run-time, and "idle-time" optimization.

What is SelectionDAG?

A SelectionDAG has designated “Entry” and “Root” nodes. The Entry node is always a marker node with an Opcode of ISD::EntryToken . The Root node is the final side-effecting node in the token chain. For example, in a single basic block function it would be the return node.

Does LLVM compile to machine code?

LLVM is a language-agnostic compiler toolchain that handles program optimization and code generation. It is based on its own internal representation, called LLVM IR, which is then transformed into machine code.


1 Answers

I've came across the same problem and there is no good tutorials indeed. But hope some of them I've found should help you if it is still actual or anyone else who read this.

First of all there is a common advice to copy-paste an existing backend and modify it for your CPU. But this is not a good practice because you don't understand what you are doing. So I've found a book with short description of llvm architecture. It can help you much. Also there is a step-by-step tutorial for implementing backend for CPU0 processor. Other sources are miscelantious slides that could be easyly found by yourself.

like image 172
alexanius Avatar answered Nov 24 '22 06:11

alexanius