clang

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 24.7.76.59 (talk) at 08:36, 12 June 2008. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Jump to navigation Jump to search
clang
Original author(s)Chris Lattner and others
Developer(s)Apple Inc.
Repository
Written inC++
Operating systemUnix-like
PlatformCross-platform
TypeCompiler
LicenseUniversity of Illinois Open Source License [1]
Websiteclang home

clang is a compiler front end for the C, C++, and Objective-C programming languages. It uses the Low Level Virtual Machine (LLVM) as its back end. It is still under development; when finished, it will offer a potential replacement to the GNU Compiler Collection (GCC). It is sponsored by Apple.

Background

In early 2005 Apple hired Chris Lattner and formed a toolchain team to work on the LLVM system for various uses within Apple's development systems.[1] LLVM can replace most of the "lower levels" of the GCC toolchain, offering more aggressive optimization and run-time compiling from its three address code intermediate form (IF). This allows code to be compiled statically, as it is under the traditional GCC system, as well as left for late-compiling from the IF to machine code in a just-in-time compiler to support a wider variety of hardware platforms.

Apple has made use of the LLVM system in a number of commercial systems. One of the most visible uses to date has been an OpenGL code compiler for Mac OS X that converts OpenGL calls into more fundamental calls for graphics processing units that do not support certain features. This was instrumental in allowing Apple to support the entire OpenGL API on computers using "integrated graphics" based on the Intel GMA chipsets, while at the same time greatly increasing performance when these conditions arose.[2] More recently, LLVM's core ability to support a wide variety of underlying hardware was key in Apple's ability to offer high-performance applications on the iPhone, which is based on the ARM processor which had limited support in the existing GCC toolchain. LLVM is a part of the iPhone development kit, and will be a part of Xcode 3.1 when it is released.[3]

While LLVM was initially targeted as part of the GCC toolchain, more recently there has been an interest in replacing other portions of the GCC system as well. GCC is a very large and somewhat cumbersome system to develop. As one long-time gcc developer put it, "Trying to make the hippo dance is not really a lot of fun."[4] As Apple has an intense interest in improving performance in Objective C (ObjC), a topic that sees little development under the normal GCC development effort, their choices for rapidly improving ObjC performance were to make additional changes to the Apple-branch of GCC, or strike out on their own with a fresh approach.

Licensing was also a factor; LLVM was initially developed at the University of Illinois, Urbana-Champaign and released under a BSD-like license that makes it easy to use in commercial programs, whereas GCC is GPL licensed and has certain requirements as a result. As the LLVM system can be "embedded" within commercial systems (like the OpenGL example above), having an entire toolchain based on a similar license would make the legalities much simpler.[5]

clang

clang is a new C-targeted compiler intended specifically to work on top of LLVM.[5] The combination of clang and LLVM provides the majority of a toolchain, allowing the wholescale replacement of the GCC system. Its goals include:

  • a layered library design to allow compiler components to be reused in such features as:
  • smaller memory footprint compared to GCC
  • higher compilation speed than GCC
  • command-line compatibility with GCC (for "drop-in" compatibility)
  • a license that is compatible with commercial products

Current Status

The project is under rapid development. Currently (December 2007), code generation for C and Objective-C is partially complete. Support for C++ and Objective-C++ is still quite incomplete; the project team "[doesn't] expect to have respectable C++ support for another 2 years or so."[5]

References

  1. ^ Adam Treat, mkspecs and patches for LLVM compile of Qt4
  2. ^ Chris Lattner, LLVM for OpenGL and other stuff, Apple Computer, May 2007
  3. ^ Chris Lattner, llvm-gcc 4.2 in Xcode, LLVMdev mailing list, 7 March 2008
  4. ^ Kenneth Zadeck, LLVM/GCC Integration Proposal, 19 Nov 2005, GCC development mailing list
  5. ^ a b c clang team, clang: a C language family frontend for LLVM