有多少个 GCC 优化级别? [英] How many GCC optimization levels are there?
本文介绍了有多少个 GCC 优化级别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有多少个 GCC 优化级别?
How many GCC optimization levels are there?
我试过 gcc -O1、gcc -O2、gcc -O3 和 gcc -O4
I tried gcc -O1, gcc -O2, gcc -O3, and gcc -O4
如果我使用一个非常大的数字,它将不起作用.
If I use a really large number, it won't work.
不过,我试过了
gcc -O100
然后编译.
有多少优化级别?
推荐答案
说到学究,您可以给 gcc 提供 8 种不同的有效 -O 选项,尽管有些选项的含义相同.
To be pedantic, there are 8 different valid -O options you can give to gcc, though there are some that mean the same thing.
此答案的原始版本表示有 7 个选项.GCC 已添加 -Og
使总数达到 8
The original version of this answer stated there were 7 options. GCC has since added -Og
to bring the total to 8
来自手册页:
-O
(同-O1
)-O0
(不做优化,未指定优化级别时默认)-O1
(最少优化)-O2
(优化更多)-O3
(进一步优化)-Ofast
(非常积极地优化到违反标准的程度)-Og
(优化调试体验.-Og 启用不干扰调试的优化.它应该是标准编辑-编译-调试循环的优化级别选择,提供合理的优化级别同时保持快速编译和良好的调试体验.)-Os
(优化大小.-Os
启用所有-O2
优化,这些优化通常不会增加代码大小.它还可以进一步执行优化旨在减少代码大小.-Os
禁用以下优化标志:-falign-functions -falign-jumps -falign-loops -falign-labels -freorder-blocks -freorder-blocks-and-partition -fprefetch-loop-arrays -ftree-vect-loop-version
)
-O
(Same as-O1
)-O0
(do no optimization, the default if no optimization level is specified)-O1
(optimize minimally)-O2
(optimize more)-O3
(optimize even more)-Ofast
(optimize very aggressively to the point of breaking standard compliance)-Og
(Optimize debugging experience. -Og enables optimizations that do not interfere with debugging. It should be the optimization level of choice for the standard edit-compile-debug cycle, offering a reasonable level of optimization while maintaining fast compilation and a good debugging experience.)-Os
(Optimize for size.-Os
enables all-O2
optimizations that do not typically increase code size. It also performs further optimizations designed to reduce code size.-Os
disables the following optimization flags:-falign-functions -falign-jumps -falign-loops -falign-labels -freorder-blocks -freorder-blocks-and-partition -fprefetch-loop-arrays -ftree-vect-loop-version
)
可能还有平台特定的优化,正如@pauldoo 所指出的,OS X 有 -Oz
There may also be platform specific optimizations, as @pauldoo notes, OS X has -Oz
这篇关于有多少个 GCC 优化级别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文