Microsoft taps open source LLVM compiler for cross-platform .Net

Microsoft looks beyond home-grown options in choosing a framework for .Net compiler

Microsoft taps open source LLVM compiler for cross-platform .Net

Does it make sense to build something from scratch when there's a perfectly good solution available -- especially if it's open source? Once upon a time, Microsoft's default was to build its own rather than use someone else's work; now, the reverse is becoming true.

Consider the LLILC project. Rather than reinvent the wheel, Microsoft's new compiler for its CoreCLR .Net runtime leverages an existing cross-platform compiler framework: LLVM. Now six months into the project, its maintainers -- a foundation comprised largely but not exclusively of folks from Microsoft -- reports "great progress" with LLILC, but also "much still to do."

LLILC is currently capable of performing just-in-time compilation ("jitting") of "all the [.Net] methods in some fairly complex scenarios." How complex? "Roslyn is a C# compiler written entirely in C#," the dev team states, "and LLILC can jit Roslyn compiling itself."

LLILC isn't yet replacing CoreCLR's original jitting mechanism; instead, the LLILC and CoreCLR jit engines run side by side. If the first one encounters something it can't handle, it's handed off to the second engine, which allows the compilation pipeline to continue running. Full garbage collection and proper exception handling support are two features lined up for the next phase of work.

The .Net Foundation, the project's official maintainer, features team members and contributors from far and wide -- GitHub and the Debian Mono group have advisers on board, for instance -- but is composed mainly of folks from Microsoft and is being used to sponsor a technology Microsoft itself invented. That said, those working on LLILC are shaping their contributions to fit LLVM, rather than trying to rework LLVM to fit LLILC's needs.

"Our intention has always been to upstream as quickly as possible," the project team writes. "We're still working on making good at that intention, but so far the number of changes we’ve had to make are fairly modest."

This is doubly significant -- under LLVM's liberal licensing, its maintainers are not obliged to contribute any changes made to it. The opposite would be true if LLVM were GPL-licensed. Microsoft itself has released its contributions to GPL-based projects, such as Linux kernel code to support the operating system running under Hyper-V. The same treatment will also have to be given to the GPL-licensed RRE, an incarnation of the R language that Microsoft acquired recently and is integrating with its software.

When using a non-GPL project, many of those issues need never arise. LLILC could be embedded in closed-source projects or used in other ways amenable to Microsoft's business model.

It's unlikely LLILC will eclipse the original, native-Windows .Net compiler -- the latter has decades of work behind it -- but increasingly Microsoft needs to be a cross-platform entity. Building on top of the good work done by others is a sensible antidote to the "not invented here" mentality that characterized Microsoft for too long.

Copyright © 2015 IDG Communications, Inc.