Some of the most recent features added to Xojo, including iOS, 64-bit apps, and Raspberry Pi have been made possible by LLVM. Read on to learn more about it.
What is LLVM?
On a high-level, LLVM is a collection of libraries and tools for building compilers. The LLVM project was started in the early 2000s by Chris Lattner (who eventually went to work at Apple and has now moved on to Tesla) and remains in active development. Because LLVM is a toolkit for building compilers and because it can target most CPU architectures, its use has become much more prominent in recent years. It has widespread industry backing with support from major companies including AMD, Apple, ARM, IBM, Intel, Google, Mozilla, Nvidia, Qualcomm, Sony, Samsung.
The first appearance of LLVM in Xojo was when we started using it to compile and run XojoScript code (2010). Later we used LLVM to build iOS apps (2014), 64-bit apps for x86 (Windows, MacOS, Linux) and 32-bit apps for Raspberry Pi (2015), and most recently we’ve hooked up the Xojo debugger so it works with apps built using LLVM (2016).
In addition to now being used as part of Xojo’s compiler, LLVM is also used with other languages, including: Clang, D, Rust, OpenCL, and Swift.
Why is Xojo using LLVM?
First, a little background. A compiler consists of many things and is typically split into parts called the “front end” and the “back end”. LLVM has components for both front ends and back ends; Xojo uses it as a back end.
For 32-bit x86 apps, Xojo uses its own in-house, proprietary compiler first created in 2004/2005. This powerful and fast compiler handles the front end and back end, but it does have a couple limitations: it can only target 32-bit x86 and it does not do any optimizations.
But technology marches on and we knew we would eventually have to add support for x86-64 (64-bit) and ARM CPU architectures. Updating a compiler is a large undertaking, but fortunately the LLVM compiler toolkit started gaining traction in the industry and became a better alternative to creating our own x86-64 and ARM compiler back ends.
Today when you build an iOS app, a 64-bit app for Windows, MacOS or Linux, or an ARM app for Raspberry Pi you are using LLVM as the back end to generate your native, binary code.
By using LLVM, we are able to respond more quickly to changes in the industry and to add features our users want. As an example, we were able to rapidly add Raspberry Pi support (32-bit ARM Linux) by leveraging much LLVM work that had already been done for x86-64 and ARM for iOS.
As Joe Ranieri (the Xojo compiler guru) likes to say “Every single line of code [you write] is a liability and not an asset”. With LLVM we can implement more features in less time because we don’t have to recreate the wheel, so to speak.
In effect, LLVM enables us to better support the unknown future, including new and updated architectures. One such example is 64-bit ARM Linux, which will likely become necessary at some point.
Learn More
LLVM is great. We love it and are thrilled that it has allowed us to add significant capabilities to Xojo for you. A compiler is a complicated thing and we are pleased that Xojo hides the complexity of compiler technology so that you don’t have to worry about it. You just need to focus on making the best app you can, select your OS target, click build and let Xojo take care of the rest.
If this post has made you curious about LLVM and you’d like to learn more, I recommend the following:
- Wikipedia: LLVM
- LLVM official site
- Accidental Tech Podcast: Interview with Chris Lattner, creator of LLVM
- Joe Ranieri’s Compiler Session from XDC 2016
More on our Compiler Series: Compilers 101 – Overview and Lexer
Download a PDF of the full Compiler series: LLVM Everywhere