GCC 优化级别有多少? [英] How many GCC optimization levels are there?

查看:42
本文介绍了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

它编译了.

有多少优化级别?

推荐答案

为了迂腐,有 8 种不同的有效 -O 选项可以提供给 gcc,尽管有些意思相同.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆