Aniket Inge
Aniket Inge

Reputation: 25705

Why Apple used CLang in their OpenGL/OpenCL implementation

I don't know if its the right place to ask this question. But why did Apple choose to use llvm and its clang implementation to code for OpenCL/OpenGL?? What benefits did it bring to them and how? Excuse my ignorance on this topic, I know not much about this.

Upvotes: 3

Views: 2039

Answers (3)

Marc J. Driftmeyer
Marc J. Driftmeyer

Reputation: 101

Apple created Clang as a drop in replacement to GCC for C/C++/ObjC and ObjC++. The creator of LLVM works at Apple inside their compiler divisions. In a joint effort with the University of Illinois who hosts the projects Apple has created complete replacements for GCC, GDB [see LLDB], libstdc++ [see libc++] and several new projects.

The GPLv3 was the final straw that ended Apple's interest in contributing to GCC which is the reason Apple ended it at GCC 4.2.x.

LLVM/Clang is rapidly supplanting GCC across the industry.

LLVM is now a misnomer of a title.

Present Target hardware supported in LLVM/Clang:

-- Targeting ARM -- Targeting CppBackend -- Targeting Hexagon -- Targeting Mips -- Targeting MBlaze -- Targeting MSP430 -- Targeting NVPTX -- Targeting PowerPC -- Targeting Sparc -- Targeting X86 -- Targeting XCore -- Clang version: 3.3

Soon added out-of-the-box AMD R600 code base.

Clang is C99 compliant. OpenCL uses a subset of C99. Clang is the most complete C11 compliant Compiler suite available free of charge.

FreeBSD has moved to LLVM/Clang as the default set up for the upcoming 10.0 distribution.

AMD and Nvidia build their OpenCL stacks with LLVM/Clang.

Intel is moving their OpenCL and much more to LLVM/Clang.

Google is all in with LLVM/Clang. Ditto for Adobe, Sony, IBM, Cray, etc.

GCC is a mess of an architecture. The modularity of LLVM/Clang makes its rate of improvement and options for developers a much greater ceiling.

The Developer and User Guides for LLVM/Clang 3.2 are now very solid, with 3.3 trunk adding a much greater amount of docs to understand the benefits of LLVM/Clang.

The pace of development of high quality compiler code is second to none.

Upvotes: 5

David Mirabito
David Mirabito

Reputation: 495

Straight from an LLVM/Apple Developer

More info, PDF Slides

LLVM is used in two different ways, at runtime:

  1. Runtime code specialization within the fixed-function vertex-processing pipeline. Basically, the OpenGL pipeline has many parameters (is fog enabled? do vertices have texture info? etc) which rarely change: executing the fully branchy code swamps the branch predictors and performs poorly. To solve this, the code is precompiled to LLVM .bc form, from which specializations of the code are made, optimized, and JIT compiled as they are needed at runtime.

  2. OpenGL vertex shaders are small programs written using a family of programming langauges with highly domain-specific features (e.g. dot product, texture lookup, etc). At runtime, the OpenGL stack translates vertex programs into LLVM form, runs LLVM optimizer passes and then JIT compiles the code.

(more details in the link above)

Upvotes: 2

neo571
neo571

Reputation: 69

Because they contribute to the develop of Clang/LLVM and because source code compiled with LLVM/Clang produce faster binary than GCC ...

Clang's developers claim that it provides reduced memory footprint and increased compilation speed compared to competing compilers, such as GCC. To support their claim, they present that, as of October 2007, Clang compiled the Carbon libraries well over twice as fast as GCC, while using about one-sixth GCC's memory and disk space.

http://en.wikipedia.org/wiki/Clang

Upvotes: 0

Related Questions