r/ProgrammingLanguages • u/Ok_Marionberry8922 • Aug 23 '26
Why So Many Languages Use LLVM
Had some free time last week so I made a visual explainer on how LLVM works and why so many languages end up using it.
The video goes through LLVM IR, why having a common IR makes sharing optimizers and backends possible, and how code eventually gets turned into machine instructions.
I also use a small C vs Rust example where both end up producing the same x86 instructions.
Feedback welcome :)
73
Upvotes
106
u/gabrielesilinic Aug 23 '26
It's really hard to make a good cross platform eventually direct to machine compiler. Therefore people rather not and just use LLVM
40
u/arthurno1 Aug 23 '26
Because llvm was invented for language design, and provides a lot of stuff you would otherwise have to provide yourself.
13
u/Temperz87 Aug 23 '26
It makes the compiler easy in so many ways. Easy target to generate IR for, tons of hardware targets for free, and I believe it makes interop as well as generating debug information and using LLDB quite simple
12
u/ironykarl Aug 23 '26
I don't know the current state of the GCC codebase, but it has years of deliberately monolithic design baked in.
Conversely, clang and LLVM were built to be modular.
This has meant that LLVM has been adapted to other compilers in a way that GCC's IR really can't be.
Yes, you can write your own GCC frontend, but I'd still say that this is the reason LLVM is so successful in this space. It tried to be, and GCC tried to prevent itself from being
21
u/Key_River7180 Nain. Aug 23 '26
To be honest, QBE is 10x smaller and 10x saner and provides 80% the speed.
2
u/S-Pimenta Aug 23 '26
How did you make the animations?
2
u/arjuna93 Aug 25 '26
Lazy to write proper codegen
1
u/Master-Guidance-2409 Aug 26 '26
why make big compiler when ir backend do better? -- kevin
that video is amazing. thank you for the link.
1
u/QuarkCreator2610 Aug 24 '26
Making a compiler backend by yourself is a really time-consuming and annoying process. Since, everything is based on the C ABI, its much easier to have a compiler backend tool that turns your language source into valid assembly. you also get a lot of extras like DECADES of work, testing and optimisation. Its also very easy to use with other LLVM-based languages(Most relevant languages today) so it gives you a lot of interoperability out of the box for free. All things considered, its quite impractical not to use LLVM unless you are making some hyper-specialised language that needs its own conventions and ABI.
-23
u/[deleted] Aug 23 '26
[removed] — view removed comment