LLVM vs clang on OS X

33,721

Solution 1

LLVM originally stood for "low-level virtual machine", though it now just stands for itself as it has grown to be something other than a traditional virtual machine. It is a set of libraries and tools, as well as a standardized intermediate representation, that can be used to help build compilers and just-in-time compilers. It cannot compile anything other than its own intermediate representation on its own; it needs a language-specific frontend in order to do so. If people just refer to LLVM, they probably mean just the low-level library and tools. Some people might refer to Clang or llvm-gcc incorrectly as "LLVM", which may cause some confusion.

llvm-gcc is a modified version of GCC, which uses LLVM as its backend instead of GCC's own. It is now deprecated, in favor of DragonEgg, which uses GCC's new plugin system to do the same thing without forking GCC.

Clang is a whole new C/C++/Objective-C compiler, which uses its own frontend, and LLVM as the backend. The advantages it provides are better error messages, faster compile time, and an easier way for other tools to hook into the compilation process (like the LLDB debugger and Clang static analyzer). It's also reasonably modular, and so can be used as a library for other software that needs to analyze C, C++, or Objective-C code.

Each of these approaches (plain GCC, GCC + LLVM, and Clang) have their advantages and disadvantages. The last few sets of benchmarks I've seen showed GCC to produce slightly faster code in most test cases (though LLVM had a slight edge in a few), while LLVM and Clang gave significantly better compile times. GCC and the GCC/LLVM combos have the advantage that a lot more code has been tested and works on the GCC flavor of C; there are some compiler specific extensions that only GCC has, and some places where the standard allows the implementation to vary but code depends on one particular implementation. It is a lot more likely if you get a large amount of legacy C code that it will work in GCC than that it will work in Clang, though this is improving over time.

Solution 2

There are 2 different things here.

LLVM is a backend compiler meant to build compilers on top of it. It deals with optimizations and production of code adapted to the target architecture.

CLang is a front end which parses C, C++ and Objective C code and translates it into a representation suitable for LLVM.

llvm gcc was an initial version of a llvm based C++ compiler based on gcc 4.2, which is now deprecated since CLang can parse everything it could parse, and more.

Finally, the main difference between CLang and gcc does not lie in the produced code but in the approach. While gcc is monolithic, CLang has been built as a suite of libraries. This modular design allow great reuse opportunities for IDE or completion tools for example.

At the moment, the code produced by gcc 4.6 is generally a bit faster, but CLang is closing the gap.

Solution 3

llvm-gcc-4.2 uses the GCC front-end to parse your code, then generates the compiled output using LLVM.

The "llvm compiler 2.0" uses the clang front-end to parse your code, and generates the compiled output using LLVM. "clang" is actually just the name for this front-end, but it is often used casually as a name for the compiler as a whole.

Share:
33,721
dominik
Author by

dominik

PhD student at the University of Washington in Databases and Data Visualization.

Updated on December 28, 2020

Comments

  • dominik
    dominik over 3 years

    I have a question concerning llvm, clang, and gcc on OS X.

    What is the difference between the llvm-gcc 4.2, llvm 2.0 and clang? I know that they all build on llvm but how are they different?

    Besides faster compiling, what is the advantage of llvm over gcc?

  • Admin
    Admin over 12 years
    To add to this wonderful answer: clang is also a set of libraries (called libclang) you can use for things like code analyzing, autocompletion, syntax highlighting, etc… This is very handy for IDEs.
  • gnasher729
    gnasher729 about 10 years
    When building for MacOS X or iOS, consider that Clang is the software that Apple uses to build all their MacOS X and iOS software including the operating system, and that Clang is what you get automatically, without effort, and what everyone you'd ever ask for help is using. Apple has never supported gcc past gcc 4.2, and doesn't ship any version of gcc anymore.
  • Brian Campbell
    Brian Campbell about 10 years
    @gnasher729 Yes, this answer was written 3 years ago, when Apple was still shipping both llvm-gcc and Clang, with llvm-gcc as the default compiler. Times have changed since then.