gcc & clang

gcc是GNU的项目,clang是chris lattner的杰作
LLVM-GCC: GCC使用GCC前端来对程序进行语义分析产生IF(Intermidiate Format),然后LLVM使用分析结果完成代码优化和生成
由于GCC的模块程度低又不满足apple的obective-c的新特性的需求,越往后提交的code质量越差,导致apple独立开发编译器
clang编译快速,占内存少,代码质量比gcc好。clang给出的错误提示更加人性化,clang现在已能做到自举
LLVM(Low Level Virtual Machine) 提供了与编译器相关的支持,能够惊醒程序语言的编译期优化、在线编译优化、代码生成,即可以作为多种语言编译器的后台使用。是一套编译优化框架,包含:

  • LLVM Core: 是一套source to target的优化器和匹配不同cpu的代码生成器,它的source就是LLVM IR(LLVM intermediate representation)
  • Clang是c++编写、基于LLVM、发布与LLVM BSD许可证下的c系列语言(c/c++/objective-c)的编译器,可以被模块化的用于代码静态分析。现在Clang(3.3and later)已经完全支持了c++11、部分c++14的所有功能,Clang3.4支持了c++14的部分功能。Clang特性(快,low memory,debug 精准,gcc兼容,模块化)
    Clang开发事出有因,wiki reference:

Apple 使用 LLVM 在不支持全部 OpenGL 特性的 GPU (Intel 低端显卡) 上生成代码 (JIT),令程序仍然能够正常运行。之后 LLVM 与 GCC 的集成过程引发了一些不快,GCC 系统庞大而笨重,而 Apple 大量使用的 Objective-C 在 GCC 中优先级很低。此外 GCC 作为一个纯粹的编译系统,与 IDE 配合很差。加之许可证方面的要求,Apple 无法使用修改版的 GCC 而闭源。于是 Apple 决定从零开始写 C family 的前端,也就是基于 LLVM 的 Clang 了

  • dragonegg整合了LLVM优化器和GCC的解析器,用途就是能够让LLVM优化gcc支持的语言
  • LLDB超牛x的调试器
  • libc++ and libc++ABI,complier-rt,openmp,vimkit,polly,libclc,klee,SAFECode,lld

这里查看LLVM详细介绍

clang optimize level

With version 3.5 the passes are as follow (parsed output of the command above):

default (-O0): -targetlibinfo -verify -verify-di

-O1 is based on -O0
    adds: -correlated-propagation -basiccg -simplifycfg -no-aa -jump-threading -sroa -loop-unswitch -ipsccp -instcombine -memdep -memcpyopt -barrier -block-freq -loop-simplify -loop-vectorize -inline-cost -branch-prob -early-cse -lazy-value-info -loop-rotate -strip-dead-prototypes -loop-deletion -tbaa -prune-eh -indvars -loop-unroll -reassociate -loops -sccp -always-inline -basicaa -dse -globalopt -tailcallelim -functionattrs -deadargelim -notti -scalar-evolution -lower-expect -licm -loop-idiom -adce -domtree -lcssa

-O2 is based on -01
    adds: -gvn -constmerge -globaldce -slp-vectorizer -mldst-motion -inline
    removes: -always-inline

-O3 is based on -O2
    adds: -argpromotion

-Os is identical to -O2

-Oz is based on -Os
    removes: -slp-vectorizer

With version 3.4 the passes are as follow (parsed output of the command above):

-O0: -targetlibinfo -preverify -domtree -verify

-O1 is based on -O0
    adds: -adce -always-inline -basicaa -basiccg -correlated-propagation -deadargelim -dse -early-cse -functionattrs -globalopt -indvars -inline-cost -instcombine -ipsccp -jump-threading -lazy-value-info -lcssa -licm -loop-deletion -loop-idiom -loop-rotate -loop-simplify -loop-unroll -loop-unswitch -loops -lower-expect -memcpyopt -memdep -no-aa -notti -prune-eh -reassociate -scalar-evolution -sccp -simplifycfg -sroa -strip-dead-prototypes -tailcallelim -tbaa

-O2 is based on -01
    adds: -barrier -constmerge -domtree -globaldce -gvn -inline -loop-vectorize -preverify -slp-vectorizer -targetlibinfo -verify
    removes: -always-inline

-O3 is based on -O2
    adds: -argpromotion

-Os is identical to -O2

-Oz is based on -O2
    removes: -barrier -loop-vectorize -slp-vectorizer

gcc optimize level

posted @ 2015-04-20 18:40  Lcnoctave  阅读(736)  评论(0编辑  收藏  举报