If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Can someone explain LLVM+clang?

03-30-2013, 11:57 PM

I've read the wikipedia entries and browsed the sites and watched some YouTube videos, but I still have some simple overview questions:

When I worked with Metrowerks CodeWarrior, they had a C/C++ "front end" that converted source to "IL" (intermediate language) which was a general platform agnostic language and then different back ends for different CPU platforms such as x86 and ARM that convert the IL code to CPU native code. LLVM sounds like it is conceptually identical to what Metrowerks called "IL". It is a virtual machine in the sense that it is like a general platform agnostic CPU. Is this correct?

Secondly, LLVM+clang sounds like just another C/C++ tool chain that promises a variety of implementation improvements. Is this correct? It is supposed to be faster, cleaner, and more tool friendly than gcc, but it still does the same basic thing which is take C/C++ (and also Objective C variants) and convert to native CPU code? Are the final binaries native CPU code or are they LLVM code with an embedded interpreter?

When I worked with Metrowerks CodeWarrior, they had a C/C++ "front end" that converted source to "IL" (intermediate language) which was a general platform agnostic language and then different back ends for different CPU platforms such as x86 and ARM that convert the IL code to CPU native code. LLVM sounds like it is conceptually identical to what Metrowerks called "IL". It is a virtual machine in the sense that it is like a general platform agnostic CPU. Is this correct?"

Secondly, LLVM+clang sounds like just another C/C++ tool chain that promises a variety of implementation improvements. Is this correct? It is supposed to be faster, cleaner, and more tool friendly than gcc, but it still does the same basic thing which is take C/C++ (and also Objective C variants) and convert to native CPU code? Are the final binaries native CPU code or are they LLVM code with an embedded interpreter?

The "Virtual Machine" aspect of the name is historical, from the LLVM homepage: "Despite its name, LLVM has little to do with traditional virtual machines...The name "LLVM" itself is not an acronym; it is the full name of the project."

Clang takes C/C++/ObjC and converts it to the intermediate language used by LLVM. LLVM takes this intermediate language (though they call it an Intermediate Representation (IR)) and converts it to native CPU code. The two are commonly used together but the great strength is that they can be used separately.

One reason LLVM is generating a lot of interest is that it doesn't matter where the intermediate representation comes from: it doesn't need to be from Clang. One of the notable uses is in the open source radeon drivers: the developers have written a front-end that compiles GPU shader code to LLVM's IR, which means they get LLVM's optimisation 'free', just by writing the shader-to-IR front-end.