Note: this page is somewhat of a work-in-progress. Please feel free to edit with additions, clarifications, better formatting, etc.

Getting started

1. Skim this document to get a feeling for IR
http://llvm.org/docs/LangRef.html

Look at the table of contents to get the basic idea. Check out the "Type System" section, and browse some of the instructions.

2. Learn to read IR, and then IR-generating functions. First focus on the IR (most codegen functions have sample IR output at the top of the implementation), then how the IR is built.

Some examples to get started:

3. Cross-compiled functions (TODO) 

 

I do not recommend plowing through the LLVM tutorial. It has some useful info, but is mostly useless for our purposes.

Debugging

Most codegen bugs will manifest by Impala crashing. Here are things to look for to help diagnose:

Here are some more things you can do to debug:

Common pitfalls:

Misc. tips

Useful APIs and references

https://github.com/apache/impala/blob/master/be/src/codegen/llvm-codegen.h: the main entry point for generating IR

https://github.com/apache/incubator-impala/blob/master/be/src/codegen/codegen-anyval.h: internal API for handling Expr output, grep for CreateCallUnwrapped for example usage

http://llvm.org/docs/LangRef.html: IR reference

http://llvm.org/docs/ProgrammersManual.html: Guide for writing LLVM C++ code. Not super applicable but has some useful patterns (e.g. iterating through a BasicBlock)

LLVM hosts generated docs for each class, which are indispensable as the C++ API is very large. You can usually just google "llvm foo" where foo is the class you're interested in. Some important ones:

http://llvm.org/docs/doxygen/html/classllvm_1_1IRBuilder.html

http://llvm.org/docs/doxygen/html/classllvm_1_1IRBuilderBase.html: most of what you want is in IRBuilder, but IRBuilderBase has a few unexpected gems)

http://llvm.org/docs/doxygen/html/classllvm_1_1Value.html

http://llvm.org/docs/doxygen/html/classllvm_1_1Function.html

http://llvm.org/docs/doxygen/html/classllvm_1_1Type.html

http://adriansampson.net/blog/llvm.html: LLVM for Grad Students; gives a good and simple introduction to LLVM