Let’s Talk LLVM

Rabin Gaire
3 min readAug 25, 2019

--

LLVM Project

What’s LLVM?

According to Wikipedia, “The LLVM compiler infrastructure project is a set of compiler and toolchain technologies which can be used to develop a front end for any programming language and a back end for any instruction set architecture.”

LLVM was developed at the University of Illinois by Vikram Adve and Chris Lattner. It was originally developed as a research infrastructure to investigate dynamic compilation techniques for static and dynamic programming languages. Back then LLVM was an Acronym to Low-Level Virtual Machine but since the project has evolved significantly the Acronym has been removed in favor of LLVM name itself.

Today there are a lot of developer/compiler toolchains under the umbrella of LLVM project, now LLVM project consists of a debugger, optimizer, internal representation(IR) and many more.

Before getting to know about the importance of the LLVM project, let’s look into the monolithic structure of compiler technology. Suppose I wanted to develop a language called X, I would have to write my own, scanner/lexer, Parser, Intermediate Representation, Optimizer, and a Targeted Instruction set for all the chips where my language X is supposed to run. You can already see this was a big hassle in designing a programming language. To get around this; languages like Python and Ruby choose target language as C so that they don’t have to write N number of compilers for N set of architecture that they wanted to support.

The big idea of the LLVM project was to make this process easier, rather targeting some other programming language, language designer nowdays can target to LLVM IR, where LLVM IR is then passed to LLVM IR Optimizer and then to targeted machine code. Since LLVM is built by the community of smart developers around the world and has been around for a while now, it supports a variety of computer architecture and, there have been a lot of optimizations done towards this project making it one of the top compiler toolchain in the world.

LLVM Frontend-Backend Compiler Architecture

So the big questions remain? Why does anyone want to write yet another new language?

Scenario one:

You are solving a domain-specific problem, you are looking for a lightweight language to run on top of custom-designed hardware. You could write a new language on top of LLVM infrastructure giving complete control over the hardware and software aspect of the project.

Scenario Two:

You have a very old system written on a very old programming language. It takes a lot of time, money and resource to rewrite that system on a modern programming language. What you could do is write an optimized compiler for the language that the old system is running, making it faster and capable of running on newer hardware. There is an agency called strumenta that helps businesses building domain-specific languages like this.

So you have seen the use cases of language design, I might as well have convinced you that you don’t have to build the next big language that will eventually take over the world. I also want you guys to understand that language design is also a career choice and there is a lot of opportunity laying around for the people who are interested in this field of computer science.

Before I sign off languages like C/C++ (clang compiler), Rust, Swift, Julia and many more are powered by LLVM compiler infrastructure, this blog post tried to give an introduction on what LLVM project is and next blog will try to shed some light on LLVM IR stay tuned. Bye Bye.

References:

LLVM Project Logo taken from LLVM project webpage (http://llvm.org)

LLVM Frontend-Backend Compiler Architecture Image has been taken from (https://medium.com/@JMangia/swift-c-llvm-compiler-optimization-842012568bb7)

--

--