backend documentation

Hello everyone!

Is there any documentation about LLVM backend implementation, except “Writing an LLVM backend”? I’m trying to write InstrFormats.td and InstrInfo.td for my backend now. After reading “Writing an LLVM backend” and “Creating an LLVM Backend for the Cpu0 Architecture”, many black holes have remained. These tutorials describe it on concrete examples, but general approach is missed. For example, how to implement different addressing modes using ComplexPattern? How to write a matching function? How does addressing modes correlate with address operands? When should we implement our own DAG nodes? Why does some backends have Format field, while other - don’t? And so on…
So, maybe somebody have materials that could help to clarify process of implementing backend? It might be books, articles, presentations etc.

Hi Vadim,

I am the book author of "Creating an LLVM Backend for the Cpu0 Architecture". Your question is right. More documents is good for programmer just like plentiful book in Linux Programming, even though the GCC backend compiler book is seldom. As you can see, I have let readers know how to write a RISC backend in my book but lack of the CISC backend features, like the complex address mode you mentioned. For these topic, LLVM supply many backend source code like X86, readers can learn it from the release source code.

I agree with you. If someone knows these topic well and willing pay time to write it, we will appreciate his work on this.

Jonathan

The Sparc port is maybe the closest thing to a text book example at this time. You can study it; debug some examples and trace through things.

It's very simple because nobody is working on the Sparc port to make it a commercial compiler for the Sparc platform; yet at the same time it has complex patterns, custom inserters etc and all the elements of a more serious port.

Most people learn LLVM by trying to do something with it and not just reading about it. I too wanted some better documentation and more complete examples and such but if you wait for that; you will wait for a very long time (several years at least).

Tablegen is a vital tool to LLVM; yet there is little written about it; especially not about the code generation use of it.

There are people that have done whole ports that have lots of holes in their knowledge; like myself for example and friends of mine that work at other companies that have done whole ports.

As I've mentioned before on the list; make sure your C++ and STL is pretty good; that is one area that can hang you up.

A lot of the information that you want is in the documents that already exist but you have to get some experience with LLVM and go back and read and re-read them many times in order to grock the whole thing.

Reed

Hello,

> InstrInfo.td for my backend now. After reading "Writing an LLVM
> backend" and "Creating an LLVM Backend for the Cpu0 Architecture",
> many black holes have remained. These tutorials describe it on

"Cpu0" links to Tricore port thesis (google for "tricore llvm"), and I
found it to be more insightful than Cpu0 doc itself (which needs more
work IMHO). It shows usage of custom addressing mode, predicates, and
some issues at least that version of LLVm had (with ability to annotate
and propagate annotations thru instruction selection graph, I wonder how
latest LLVM in that regard).

It's very simple because nobody is working on the Sparc port to make
it a commercial compiler for the Sparc platform; yet at the same time
it has complex patterns, custom inserters etc and all the elements of
a more serious port.

Most people learn LLVM by trying to do something with it and not just
reading about it. I too wanted some better documentation and more
complete examples and such but if you wait for that; you will wait
for a very long time (several years at least).

Tablegen is a vital tool to LLVM; yet there is little written about
it; especially not about the code generation use of it.

With my LLVM brainstorming, I find it soothing idea to think of
tablegen as another separate layer. Because treating it as an
unalienable part of LLVM, it's really hard to see how this all differs
from GCC, except that they were missing to PR their GIMPLE IR for long
time.

I'm sure Tablegen is a good expressive language, and sure that if
someone is to write generic solution, they would come up with something
similar to Tablegen eventually. I just wonder if that's exactly the
case when (re)implementing own adhoc solution offers much milder
learning curve...

Anyway, it would be nice to have a backend for (abstract) trivial CPU
with just accumulator, index register and stack pointer and devoid
of any tablegen usage (or maybe it would be tolerable for such CPU,
after all, most of tablegen hardness comes from lack of keyword
arguments and MLAs a typical machine def is ridden with). Such backend
could be used to easily bootstrap a new arch backend, next might be to
use any extra regs as just stack frame cache, and then it will be
just good time to learn advanced tablegen stuff.

I wonder if there would be any interest in an annual (or some
reasonable interval) "workshop" sort of thing that teaches backend
development. That may be a better learning medium for this material
than a book.

-- Sean Silva

There's the obvious factor that, especially if one just occasionally ends up
diving in to the backend trying to fix a bug, a "just about understandable"
online reference may give better results than there being a "really well
structured" periodic workshop. That's why I think it'd be great if, whenever
anyone were to do a talk about LLVM, they could throw the slides up (without
further polishing) somewhere accessible. True they may be incomprehensible
without the context, but there's a chance they might be and as an
infinitesimal-effort thing to do...

Cheers,
Dave

Vadim Khoptynets <vadya.poiuj@gmail.com> writes:

Hello everyone!

Is there any documentation about LLVM backend implementation, except
"Writing an LLVM backend"? I'm trying to write InstrFormats.td and
InstrInfo.td for my backend now. After reading "Writing an LLVM
backend" and "Creating an LLVM Backend for the Cpu0 Architecture",
many black holes have remained.

The reference documentation "The LLVM Target-Independent Code Generator"
is about the best there is, AFAIK. It lacks a lot of important details
but gives a good general overview of the concepts.

                              -David