LLVM

LLVM is a compiler infrastructure which contains all steps of the compilation. First created for the optimization of source code for the compilation unrelated to any specific language. LLVM allows numerous pieces of source code to be translated in different targets.

In our case, we will be interested in how we can use LLVM-IR for the Tiger Compiler.

The LLVM IR is a Static Single Assignment (SSA) based representation that provides type safety, low-level operations, and is capable of representing most of high-level languages cleanly. It is the intermediate representation used by Clang, A C language family front end for LLVM.

Compared to the HIR, LLVM IR is typed. Providing type information can help the LLVM back end to optimize even more.

You can find more information about the language in the LLVM Language Reference Manual.

For more documentation on LLVM, use the LLVM Documentation.

A relevant tutorial is available here: Kaleidoscope: Implementing a Language with LLVM. It may be useful if you want to go further.

LLVM is a project written in C++, parts of the code will be explained in further sections.

For a more thorough understanding of LLVM’s inner workings, you are strongly encouraged to read the actual LLVM documentation linked above. This section documents some of the most useful LLVM classes for our implementation of the Tiger Compiler :

../../_images/llvm_uml.jpg
title:

Simple UML for some LLVM classes.