Biz & IT —

Things that go Clang in the night: LLVM 2.4 released

Version 2.4 of the Low Level Virtual Machine (LLVM) has been officially …

The open source Low Level Virtual Machine (LLVM) project has officially announced the availability of version 2.4. The new release includes important optimizations, GCC integration improvements, and a new port for the PIC16 microprocessor.

LLVM provides a compiler infrastructure framework that can be used to construct virtual machines and native code generators. It offers a low-level, language-neutral intermediate representation that is easy to target and is highly conducive to optimization. Several front-ends are supported, including one for C and C++ that has been adapted from the GNU Compiler Collection (GCC). It has numerous backends, including static native code generators for several architectures, a JIT compiler, and code emitters for portable C and for MSIL, the intermediate language used by Microsoft's .NET framework.

LLVM has been adopted by Apple in several contexts, including the iPhone SDK. Apple hired the lead developer several years ago and has funded much of the ongoing development.

Version 2.4 brings significant performance improvements. According to the release notes, compiling without optimization (-O0) is roughly 30 percent faster than in version 2.3. This performance boost was achieved by optimizing many aspects of the code generator and by taking advantage of the new fast instruction selection feature, which is designed to generate code as quickly as possible with minimal consideration for final runtime performance.

LLVM's code optimizers also got some enhancements. The addition of a new loop deletion pass and improvements made to the ADCE pass will speed up the optimizer. Another addition in 2.4 is the SparsePropagation framework, which facilitates sparse conditional property propagation with a customizable lattice.

LLVM 2.4 also marks the very first release of VMKit, a project that aims to build complete implementations of the .NET and Java virtual machines with the LLVM JIT compiler. Some of the nice .NET features that are touted in this release of VMKit include partial support for the Mono class libraries and .NET generics.

One very significant part of the LLVM effort is the Clang project, which aims to build a completely new LLVM front-end—one that can be used in place of the current GCC-based front-ends—for C-like languages. Clang is progressing rapidly and is already capable of compiling some C applications. Clang offers a lot of really compelling advantages over GCC. Some early benchmarks show that it delivers insanely fast compilation and much lower memory overhead. In some real-world tests, Clang is 2.5 times faster than GCC and uses five times less memory. It also uses less disk space during the compilation process.

Another important bonus of using Clang and LLVM instead of GCC is that the former is better able to identify and articulate where problems are in code. The intermediate format it uses is much closer to the original code, so it can tell developers a lot of things that GCC cannot. This is particularly useful for IDE integration and static analysis. The codebase is also cleaner and slimmer than GCC, which makes it easier to work with and encourages more rapid progress.

Clang is designed to be compatible with code that can be compiled today with GCC. That's very exciting for the open source software community, because it means that Clang and LLVM could some day be used as a complete replacement for the entire GCC stack. GCC has improved a lot over the years, especially with the transition to GCC 4, but it's still a very crufty and cumbersome code base. LLVM and Clang would offer a more future-proof solution and faster compilation.

The new version of Clang in LLVM 2.4 can compile some major C applications, such as SQLite 3. According to the release notes, it also has good code generation support for Obj-C on Mac OS X and can be used with LLVM to build most of the example projects included with the Mac OS X Developer Tools.

Although Clang is very promising, it still has a long way to go before it will be capable of displacing GCC. LLVM still doesn't support as many architectures as GCC, and Clang's C++ support is still at an early stage of development.