Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is LLVM and why is it so popular all of a sudden? [closed]

In recent months, I have been seeing mentions of "LLVM" all over the place. I've looked it up, but the description of a "modern compiler infrastructure" doesn't really tell me anything. I can't find much about it, other than some mention of a c compiler that comes along with it (which doesn't seem to be any different from any other C compiler out there.)

Is there some difference between this LLVM thing and any other compiler, say, GCC? Or is it an over-hyped replacement benefiting from being newer than the competition?

like image 312
Ethan McTague Avatar asked Jan 05 '17 01:01

Ethan McTague


1 Answers

There is some academic literature on the matter, I recommend the AOSA book chapter on it, written by the principal author (Chris Lattner).

LLVM is a collection of libraries built to support compiler development and related tasks. Each library supports a particular component in a typical compiler pipeline (lexing, parsing, optimizations of a particular type, machine code generation for a particular architecture, etc.). What makes it so popular is that its modular design allows its functionality to be adapted and reused very easily. This is handy when you're developing a compiler for an existing language to target a new hardware architecture (you only have to write the hardware specific components, all the lexing, parsing, machine independent optimization, etc. are handled for you), or developing a compiler for a new language (all the back end stuff is handled for you), or when you're doing something compiler adjacent (like analyzing source code, embedding a language in a larger application, etc.).

In order to support this, LLVM employs a pretty sophisticated internal representation (called the LLVM IR, creatively enough) that is basically assembly language for a theoretical hardware architecture designed to make targeting it with a compiler very easy. Most of the LLVM libraries take the IR in, operate on it, and output the modified IR, supporting the project's aim of modularity. This is in contrast to GCC, which (historically, I haven't checked recently) has a less complete IR and thus the separate phases of compilation are very tightly coupled because they have to share a lot of information.

Clang is the flagship compiler built on the LLVM framework.

like image 119
Irisshpunk Avatar answered Sep 17 '22 05:09

Irisshpunk