2012-04-24 555 views
10

我正在編譯一個我一直在用LLVM 2.6和llvm-gcc前端進行編譯的項目。我試圖用LLVM 3.1和clang來測試它的編譯。當我這樣做,我得到了以下錯誤消息有關-O5優化級別:LLVM和Clang中的優化級別

error: invalid value '5' in '-O5' 

然而,LLVM 2.6和LLVM-GCC已經工作得很好與-O5標誌。我看到了有關鐺優化級別以下文件:

-O0 -O1 -O2 -Os -O3 -O4 
     Specify which optimization level to use. -O0 means "no optimization": this level compiles the 
     fastest and generates the most debuggable code. -O2 is a moderate level of optimization which 
     enables most optimizations. -Os is like -O2 with extra optimizations to reduce code size. -O3 
     is like -O2, except that it enables optimizations that take longer to perform or that may 
     generate larger code (in an attempt to make the program run faster). On supported platforms, -O4 
     enables link-time optimization; object files are stored in the LLVM bitcode file format and whole 
     program optimization is done at link time. -O1 is somewhere between -O0 and -O2. 

所以我試圖找出什麼在我與擺在首位在做工作的Makefile中的-O5(我沒有寫Makefile文件)。這是否改變了並用於LLVM?或者它仍然是一個有用的功能,我只需要以其他方式激活它。

此外,在情況下,它是非常有用的,我運行的是給錯誤的命令基本上是:

/bin/clang -g -c -mcmodel=medium -fstrict-aliasing -Wstrict-aliasing -O5 -emit-llvm -fkeep-inline-functions -fno-stack-protector -c -o foo.bc foo.cpp 

同樣的情況下,它很重要,我一個Linux(Ubuntu的10.04)x86_64的系統上運行。

回答

12

gcc的對待任何-On對於n> = 4 as -O3

-O標誌將接受任何數量從 0-9,但只有零到三個實現,我不認爲 任何人都有計劃在不久的將來實施四到九年。 事實上,人們使用這個-O9成語有點令人不安,因爲 這意味着他們希望gcc可能會提供的每一個可能的優化,即使編譯花了幾周時間,也沒有增加。

更大的水平不應該使用,你只是低質量的Makefile。

所以指定-O9是有點 - 型廢話

因此,當使用gcc編譯器,你有-O的有效變種「但這種人去到十一!」:-O0, -O1, -O2, -O3。但是驅動程序會默認將任何-On轉換爲-O3。

LLVM(包括鐺和駕駛員的LLVM-GCC的變體)僅支持水平,直至-O4-O4只是一樣-O3 -flto)。所以你不應該在沒有測試的情況下使用-O4,因爲lto比較慢,可能會破壞你的程序。

2

Makefile中的錯誤可能是llvm-gcc沒有將錯誤識別爲clang所做的。