recommendation books on code generation?


i am reading LLVM code, focusing on the code generation (backend) part. however, it is still rather tough to understand all the code, so i think i need to improve my background on compiler backend first.

any recommendation on good books that introduces all the related techniques used by LLVM: DAG lowering, DAG legalization,instruction selection, scheduling, register allocation, etc…

i looked at the Dragon book, but it seems outdated, and didnt introduce all the above concepts.

many thanks,


I don't think you need any special books.

There is nothing complicated going on that is not in a basic compiler book. Mostly you have to understand how they implemented basic things in this framework.

Knowing modern C++ (i.e. templates, overloading, etc...) and STL pretty well is more important than knowing about compiler theory in order to understand things.

The documentation online just needs to be read many times and you need to do your own port or try and understand one for an architecture that you already know pretty well.

You need to know what a phi node is. That is about the only thing that is mostly something you could not just learn from reading the code because it's a special term.


For me it was helpful to use the debugger (gdb) to step through things too.

If you wanted to write a new register allocator, that would be a different story.

Then you would do well to read the literature to try and understand about various schemes that have already been invented.

No need to reinvent the wheel.

Most people doing a port can figure things out by just using their brain and the documentation already at the LLVM web site; but like I said, a good solid knowledge of modern C++ and STL is necessary; otherwise you may struggle with code that is really very simple but is hard to understand because of the language issues.


Hi, (taking the plunge)

I believe it's the case that if one were an experienced compiler engineer
before coming to LLVM it might be a different story to if one were getting
up to speed on how compilers work by starting with LLVM (which sounds like
it might be the case here). Certainly in looking at the LLVM code in areas I
don't know about there is the undeniable fact that one is trying to
understand _production optimized_ code at the same time as trying to
understand the basic concepts the code implements, which is harder than
learning about the concepts from more basic code then studying a better
implementation. I don't know of a book, but as a suggestion: is there anyone
who's teaching a course on compilers using LLVM who has the lecture notes
(or even better actual lectures) online?


"David Tweed" <> writes:

I don't know of a book, but as a suggestion: is there anyone who's
teaching a course on compilers using LLVM who has the lecture notes
(or even better actual lectures) online?

The LCC book (A Retargetable C Compiler: Design and Implementation
[Addison-Wesley, 1995, ISBN 0805316701, ISBN-13 9780805316704]) has very
good descriptions of pattern-matching instruction selectors and simple
register allocators. LLVM doesn't work exactly the same way but the
concepts are similar enough to translate fairly well.


I've been told by one person that they're scheduled to give a very practical
compiler university course using LLVM next year, so I was pretty sure that
there must be several courses elsewhere in the world that have already been
given. Looks like I was wrong about that.

That was me. I am also planning on writing a book on LLVM for Pearson over the summer. If anyone would be interested in doing technical reviews, please let me know off list.

The material for the course will all be available online, so may be usable by other people wanting to teach similar courses.