Search code examples
c++llvm

Is LLVM a typical virtual machine?


I'm wondering if LLVM is a typical Virtual Machine like Java's or .Net's or is it simply runtime environment, just like oridinary C++ runtime?


Solution

  • It's neither of those things.

    LLVM used to stand for 'low level virtual machine' but that never meant a complete virtual machine in the sense of Java or .NET, and 'LLVM' has since stopped being an abbreviation.

    A central part of LLVM is LLVM IR.

    IR stands for intermediate representation, which is terminology used in compilers referring to the program representation used between the front and back ends. IR allows the details of parsing a language to be decoupled from the details of code generation. In traditional compiler design ideally front-end and back-end components can be freely mixed so that N front ends and M back-ends would allow you to create NxM compilers.

    LLVM's IR is different from traditional intermediate representations; instead of being based on abstract syntax trees LLVM IR is a kind of assembly language, or byte code similar to Java and .NET. That's where the 'virtual machine' came in. However LLVM IR does not enforce high level semantics, such as array bounds checking, like .NET and the JVM do. Also, LLVM IR can be JIT compiled, but typically it is statically compiled to native code just like any traditional compiler's back-end would do to IR.


    LLVM has grown to name an umbrella project for many components around a core compiler infrastructure. Originally LLVM was the IR and tools for operating on it (optimization, codegen) but has grown to encompass a lot more including some front ends that target LLVM IR, a machine code framework for parsing and generating assembly, generic object file handling, a debugger, a linker...

    If you're interested there's an LLVM conference each year that covers what's going on in LLVM and projects using LLVM, and they record and post the presentations: http://llvm.org/devmtg/. This year's is being held just next week.