哪些特定的优化标志负责优化变量
Which specific optimization flags are responsible for optimizing out variables
我想特别 select 优化标志以防止 gdb 中的 <optimized out>
变量(参数),而不求助于 -O0
。
我的背景是调试 glibc,它不能用 -O0
构建,因为它需要某种函数内联。但是我可以看到这通常很有用,例如在不完全破坏性能的情况下启用有用的调试。
根据 gcc -c -Q -O0 --help=optimizers
,除了在 -O0
启用的优化标志(使用 gcc 5.3.1)之外,-O1
还启用了以下 31 个优化标志:
-fbranch-count-reg
-fcombine-stack-adjustments
-fcompare-elim
-fcprop-registers
-fdefer-pop
-fforward-propagate
-fguess-branch-probability
-fif-conversion
-fif-conversion2
-finline-functions-called-once
-fipa-profile
-fipa-pure-const
-fipa-reference
-fmove-loop-invariants
-fshrink-wrap
-fsplit-wide-types
-fssa-phiopt
-ftree-bit-ccp
-ftree-ccp
-ftree-ch
-ftree-copy-prop
-ftree-copyrename
-ftree-dce
-ftree-dominator-opts
-ftree-dse
-ftree-fre
-ftree-pta
-ftree-sink
-ftree-slsr
-ftree-sra
-ftree-ter
注意:我知道 selective 优化 / volatile 作为手动修复,但我正在寻找更通用的解决方案。
没有直接回答你的问题,但你可能想要的是 -Og
:
-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.
在 -Og
上使用 --help=optimizers
并将其与您在 -O0
上使用 --help=optimizers
得到的结果进行比较,然后为您提供问题的答案。
我想特别 select 优化标志以防止 gdb 中的 <optimized out>
变量(参数),而不求助于 -O0
。
我的背景是调试 glibc,它不能用 -O0
构建,因为它需要某种函数内联。但是我可以看到这通常很有用,例如在不完全破坏性能的情况下启用有用的调试。
根据 gcc -c -Q -O0 --help=optimizers
,除了在 -O0
启用的优化标志(使用 gcc 5.3.1)之外,-O1
还启用了以下 31 个优化标志:
-fbranch-count-reg
-fcombine-stack-adjustments
-fcompare-elim
-fcprop-registers
-fdefer-pop
-fforward-propagate
-fguess-branch-probability
-fif-conversion
-fif-conversion2
-finline-functions-called-once
-fipa-profile
-fipa-pure-const
-fipa-reference
-fmove-loop-invariants
-fshrink-wrap
-fsplit-wide-types
-fssa-phiopt
-ftree-bit-ccp
-ftree-ccp
-ftree-ch
-ftree-copy-prop
-ftree-copyrename
-ftree-dce
-ftree-dominator-opts
-ftree-dse
-ftree-fre
-ftree-pta
-ftree-sink
-ftree-slsr
-ftree-sra
-ftree-ter
注意:我知道 selective 优化 / volatile 作为手动修复,但我正在寻找更通用的解决方案。
没有直接回答你的问题,但你可能想要的是 -Og
:
-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.
在 -Og
上使用 --help=optimizers
并将其与您在 -O0
上使用 --help=optimizers
得到的结果进行比较,然后为您提供问题的答案。