Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is LLVM a typical virtual machine?

Tags:

c++

llvm

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?

like image 436
smallB Avatar asked Nov 01 '12 15:11

smallB


People also ask

Is LLVM a virtual machine?

LLVM is an acronym that stands for low level virtual machine. It also refers to a compiling technology called the LLVM project, which is a collection of modular and reusable compiler and toolchain technologies.

Is LLVM like JVM?

Assuming you mean JVM rather than Java: The LLVM is a low level register-based virtual machine. It is designed to abstract the underlying hardware and draw a clean line between a compiler back-end (machine code generation) and front-end (parsing, etc.). The JVM is a much higher level stack-based virtual machine.

What is LLVM used for?

LLVM is a library that is used to construct, optimize and produce intermediate and/or binary machine code. LLVM can be used as a compiler framework, where you provide the "front end" (parser and lexer) and the "back end" (code that converts LLVM's representation to actual machine code).

Is LLVM platform independent?

Can I compile C or C++ code to platform-independent LLVM bitcode? ¶ No. C and C++ are inherently platform-dependent languages.


1 Answers

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 internal 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 internal 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.

like image 81
bames53 Avatar answered Oct 12 '22 07:10

bames53