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) 提供了與編譯器相關的支持,可以驚醒程序語言的編譯期優化、在線編譯優化、代碼生成,便可以做爲多種語言編譯器的後臺使用。是一套編譯優化框架,包含:css

  • 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++十一、部分c++14的全部功能,Clang3.4支持了c++14的部分功能。Clang特性(快,low memory,debug 精準,gcc兼容,模塊化)
    Clang開發事出有因,wiki reference:html

    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,lldc++

這裏查看LLVM詳細介紹objective-c

clang optimize level

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

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):app

-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框架

相關文章
相關標籤/搜索