【C语言常识】mdk:Compiler optimization levels and the debug view

出处:官方编译器手册

The precise optimizations performed by the compiler depend both on the level of optimization chosen, and whether you are optimizing for performance or code size.

The compiler supports the following optimization levels:

-O0

Minimum optimization. The compiler performs simple optimizations that do not impair the debug view.

When debugging is enabled, this option gives the best possible debug view.

-O1

Restricted optimization.

When debugging is enabled, this option gives a generally satisfactory debug view with good code density.

-O2

High optimization. This is the default optimization level.

When debugging is enabled, this option might give a less satisfactory debug view.

-O3

Maximum optimization. This is the most aggressive form of optimization available. Specifying this option enables multifile compilation by default where multiple files are specified on the command line.

When debugging is enabled, this option typically gives a poor debug view.

Because optimization affects the mapping of object code to source code, the choice of optimization level with-Ospace and -Otime generally impacts the debug view.

The option -O0 is the best option to use if a simple debug view is needed. Selecting-O0 typically increases the size of the ELF image by 7 to 15%. To reduce the size of your debug tables, use the--remove_unneeded_entities option.


编译器提供了两个选项用于优化代码大小和性能:
-Ospace 此选项使编译器主要针对代码大小进行优化。 这是缺省选项。
-Otime 此选项使编译器主要针对速度进行优化。
要获得最佳效果,必须使用最合适的命令行选项来生成应用程序。
注意
这些命令行选项指示编译器使用优化,在大多数情况下能实现预期的优化效
果。 但是,不能保证 -Otime 总能生成更快的代码,也不能保证 -Ospace 总能生成
更小的代码。


由编译器执行的精确优化既取决于所选的优化级别,也取决于是优化性能还是
优化代码大小。
编译器支持以下优化级别:
-O0 最低优化。 编译器执行不会影响调试视图的简单优化。
启用调试时,此选项给出可能的最佳调试视图。
-O1 受限优化。
启用调试时,此选项给出具有良好代码密度并且通常令人满意的
调试视图。
-O2 高度优化。 这是缺省设置。启用调试时,此选项可能给出不太令人满意的调试视图。

-O3 最大优化。 这是可用的最积极的优化格式。 如果指定此选项,则当
在命令行中指定多个文件时,缺省启用多文件编译。
启用调试时,此选项通常给出较差的调试视图。


因为优化会影响对象代码到源代码的映射,所以对优化级别和 -Ospace/-Otime 的
选择通常会影响调试视图。 使用 --debug 启用调试时,请使用 -Onum 命令行选项
显式指定最适合的优化级别。需要简单调试视图时,选项 -O0 是可以使用的最佳选项。 

选择 -O0 通常会将 ELF映像的大小增加 7% - 15%。 若要减小调试表的大小,请

使用 --no_debug_macros选项。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值