关于-O0、O1、O2、O3优化

本文详细介绍了GCC编译器的-O0至-O3等优化选项及其各自的作用,解释了如何通过不同级别的优化标志来改善程序性能和代码大小。此外,还讨论了在不同优化级别下编译器的工作原理。

ref1

官网的一个链接

gcc -O0 -O1 -O2 -O3 四级优化选项及每级分别做什么优化

gcc编译优化-O0 -O1 -O2 -O3 -OS解析 

Options That Control Optimization-出自官方 

gcc  -Q --help=optimizers
These options control various sorts of optimizations.
这些选项控制各种各样的优化。

Without any optimization option, the compiler's goal is to reduce the cost 
of compilation and to make debugging produce the expected results. Statements 
are independent: if you stop the program with a breakpoint between statements, 
you can then assign a new value to any variable or change the program counter 
to any other statement in the function and get exactly the results you expect 
from the source code.
没有任何优化选项,编译器的目标是降低编译成本,并使调试产生预期的结果。语句是独立的:
如果您在语句之间使用断点停止程序,那么您可以为任何变量分配一个新值,或者将程序计数器
更改为函数中的任何其他语句,并从源代码中获得您期望的结果。

Turning on optimization flags makes the compiler attempt to improve the performance 
and/or code size at the expense of compilation time and possibly the ability to debug 
the program.
打开优化标志使编译器试图以编译时间和调试程序的能力为代价来提高性能和/或代码大小。

The compiler performs optimization based on the knowledge it has of the program. 
Compiling multiple files at once to a single output file mode allows the compiler 
to use information gained from all of the files when compiling each of them.
编译器根据对程序的了解执行优化。将多个文件同时编译为一个输出文件模式允许编译器在编译每个文
件时使用从所有文件获得的信息。


Not all optimizations are controlled directly by a flag. Only optimizations 
that have a flag are listed in this section.
不是所有的优化都直接由一个标志控制。本节只列出具有标志的优化。


Most optimizations are only enabled if an -O level is set on the command line. 
Otherwise they are disabled, even if individual optimization flags are specified.
大多数优化仅在命令行上设置- O级别时启用。否则将禁用它们,即使指定了各个优化标志。


Depending on the target and how GCC was configured, a slightly different set of
optimizations may be enabled at each -O level than those listed here. You can 
invoke GCC with -Q --help=optimizers to find out the exact set of optimizations 
that are enabled at each level. See Overall Options, for examples.
根据目标和 GCC 的配置方式,可以在每个- O 级别启用一组与本文列出的优化略有不同的优化。
可以使用-Q --help=optimizers 查找在每个级别启用的优化的确切集合.有关示例,请参见总体选项。



评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值