RPM: Gcc,llvm,clang Compiler comparison

Source: Internet
Author: User

Transferred from: http://www.cnblogs.com/qoakzmxncb/archive/2013/04/18/3029105.html

In Xcode, we often see these compilation options (such as), some may be a bit dazed, this article will be on the GCC4.2, LLVM GCC 4.2, LLVM Compliler 2.0 Three compile options for a detailed introduction.

Gcc

GCC (GNU Compiler Collection,gnu Compiler Set) is a set of programming language compilers developed by GNU. It is a set of free software issued under the GPL and LGPL licenses, a key part of the GNU program, and a standard compiler for the free Unix-like and Mac OS X operating systems of Apple computers.

GCC was formerly the GNU C language compiler because it could only handle the C language. GCC expands quickly to become able to handle C + +. It also became available for processing Fortran, Pascal, Objective-c, Java, and Ada and other languages.

LLVM

LLVM is the abbreviation for low level Virtual machine, which provides compiler-related support for programming language compile-time optimization, link optimization, online compilation optimization, and code generation. In short, it can be used as a background for multiple language compilers. If this is still more abstract, the introduction of the next Clang will know: Clang is a C + + written, based on LLVM, released under the LLVM BSD license c/c++/objective c/objective C + + compiler, its goal (one) is beyond GCC 。

LLVM history

Apple has been using GCC as the official compiler, including the next in the middle and later. GCC has been doing a good job as a compiler standard for the open source world, but Apple has made higher demands on the build tools.

    on the one hand, Apple has added many features to the Objective-c language (and even later to c), but the GCC developers don't buy Apple's account-they don't do it, so they split up into two separate branches, This also causes Apple's compiler version to lag far behind the official version of GCC. On the other hand, GCC's code coupling is too high, not independent, and the later version, the lower the quality of the code, but many of the features Apple wants to do (such as better IDE support) require a modular way to invoke GCC, but GCC has never done so. Even recently, the GCC Operating Environment exemption clause (English version) has fundamentally limited the development of LLVM-GCC. So, this does not make Apple have been looking for an efficient, modular, negotiated and more relaxed open source alternative, so Apple came to the compiler, Chris Lattner (2000, The Graduate of Chris Lattner, like most Chinese university students, After a step-by-step test of GRE, he eventually went to UIUC (University of Illinois at Urbana-Champaign) and began a hard-read computer master's and PhD's career. At this stage, he not only traveled around the United States major attractions, but also hard to learn scientific and cultural knowledge, turned the "Dragon book" ("Compilers:principles, Techniques, and Tools"), became the GPA cattle "Note: Final credits 4.0 full score", and constantly explore the unknown areas of the compiler, published an article after another, is the Chinese traditional concept of "Miyoshi students." His master's thesis presents a complete set of compiling ideas for the optimization program at compile time, link time, run time and even idle time, which lays the foundation of LLVM directly. LLVM was more mature when he was a doctor, using GCC as the front-end for semantic analysis of user programs to produce if (Intermidiate Format), and then LLVM using the analysis results to complete code optimization and generation. The study made him a small, well-known compiler expert when he graduated in 2005, so he was early in the apple phase to become the backbone of his compiler project.

Just enter Apple,chris Lattner: First in the OpenGL team to do code optimization, the LLVM runtime compiler on the OpenGL stack, so that the OpenGL stack can produce more efficient graphics code. If the video card is advanced enough, the code is thrown directly into the GPU execution. However, for some graphics cards that do not support all OpenGL features (such as the Intel GMA Card at the time), LLVM can optimize these instructions to be efficient CPU instructions, so that the program can still function properly. This powerful OpenGL implementation was used on later releases of Mac OS X 10.5. At the same time, LLVM's link optimizations are added directly to Apple's code linker, while LLVM-GCC is also synchronized to use GCC4 code.

Clang history

Apple's goal of absorbing Chris Lattner is much bigger and cumbersome than improving the GCC code optimization--GCC system, while Apple's heavily used objective-c has a low priority in GCC. In addition, GCC, as a purely compiled system, works poorly with the IDE. In addition to licensing requirements, Apple cannot continue to improve the quality of GCC code using LLVM. As a result, Apple decided to write the front-end Clang of C, C + + and Objective-c languages from scratch, completely replacing GCC.

As the name says, Clang only supports the three C-family languages of c,c++ and Objective-c. Starting in 2007, the C compiler was first completed, and because Objective-c is relatively simple, it is just a simple extension of C, and in many cases can even be rewritten as a C language to the OBJECTIVE-C runtime function call, so in 2009, is fully available for production environments. The support of C + + is also being carried out enthusiastically.

The following diagram shows the different points of the GCC, LLVM-GCC, LLVM compiler three compilation options:

Contrast

As a new compiler, let's look at the pros and cons of Clang and GCC:

Clang characteristics

    1. Fast: By compiling carbon.h tests for almost all C header files on OS X, including preprocessing (Preprocess), Syntax (Lex), parsing (parse), semantic parsing (Semantic analysis), abstract syntax tree generation Syntax Tree) Time, Clang is Apple GCC 4.0 2.5x fast. (2007-7-25)
    1. Memory footprint is small: Clang memory footprint is the source of 130%,apple GCC is more than 10x.
    2. Diagnostic information is readable: I do not typesetting, recommend to visit the site. The syntax of the error is not only the source code hints, but also in the wrong call and the relevant context below the ~~~~~ and ^ hints, compared to the GCC hints are heavenly.
    3. GCC compatibility.
    4. The design is clear, simple, easy to understand and easy to expand and enhance. The learning curve is gentle compared to the old code-based GCC.
    5. Library-based modular design for easy IDE integration and reuse of other uses. For historical reasons, GCC is a single executable compiler that has completed all the processes from preprocessing to final code generation, and many of the information in the middle is not reused by other programs. Clang the compilation process into separate phases, and the AST information can be serialized. With the support of the library, the program is able to obtain information at the AST level, which greatly enhances the ability to manipulate the code. For the IDE, code completion, refactoring is an important function, but if there is no underlying support, only using tags analysis or regular expression matching is difficult to achieve.

Of course, GCC also has its advantages:

    • Support Java/ada/fortran
    • The current Clang C + + support lags behind GCC, see http://clang.llvm.org/cxx_status.html. (recently Clang has been able to self-compile, see HTTP://WWW.PHORONIX.COM/SCAN.PHP?PAGE=NEWS_ITEM&PX=NZK2MW)
    • GCC supports more platforms
    • GCC is more popular and widely used to support complete
    • GCC-based C, no C + + compiler is required to compile

which to choose

So, which of the three compile options do you want to choose? It is not recommended to use the old GCC4.2, because Apple will not maintain it, and LLVM-GCC will look better. Changing the compilation options in the middle of a project is a big change, so if you want to change it, you need to go through a careful and complete test.

For a new project, LLVM-GCC looks like a safe choice, and Apple thinks it's stable enough to be a pre-set option for Xcode 4 (you might not equate the two words of stable maturity with Xcode 4 itself), and since the option uses GCC Parser, backwards compatibility should be no problem.
I say LLVM-GCC is a safe option, but I don't mean CLANG/LLVM is less secure, but maturity is not so efficient, I'll take some of the previous code to Xcode 4, recompile with the LLVM 2.0 compiler, so far no problems have been found.

Reference Documentation:

Http://baike.baidu.com/view/4848.htm

Http://hi.baidu.com/zhanghuikl/blog/item/71e8a6018172df0f728da53e.html

http://www.programmer.com.cn/9436/

RPM: Gcc,llvm,clang Compiler comparison

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.