gccg++优化标识-O1-O2-O3-Os-Ofast-Og的作⽤
⽂章⽬录
注意:⽤GDB调试的时候需要关闭优化选项
当优化标识被启⽤之后,gcc编译器将会试图在不改变程序语义的情况下改变程序的结构,
以满⾜代码⼤⼩最⼩或运⾏速度更快等⽬标
内容摘⾃:
1. -O,-O1
这两个命令的效果是⼀样的,⽬的都是在不影响编译速度的前提下,尽量采⽤⼀些优化算法降低代码⼤⼩和可执⾏代码的运⾏速度。并开启如下的优化选项:
-fauto-inc-dec
-fbranch-count-reg
-fcombine-stack-adjustments
正本提单-fcompare-elim
-fcprop-registers
-fdce
-fdefer-pop
-fdelayed-branch
-fd
-fforward-propagate
-fguess-branch-probability
-
内罗毕是哪个国家的
fif-conversion2
-fif-conversion
-finline-functions-called-once
-fipa-pure-const
-fipa-profile
-fipa-reference
-fmerge-constants
-fmove-loop-invariants
-freorder-blocks
-fshrink-wrap
-fshrink-wrap-parateindependently
-
fsplit-wide-types
-fssa-backprop
-fssa-phiopt
-fstore-merging
-ftree-bit-ccp
-ftree-ccp
-ftree-ch
-ftree-coalesce-vars
-ftree-copy-prop
-ftree-dce
-ftree-dominator-opts
-
ftree-d
-ftree-forwprop
-ftree-fre
-ftree-phiprop
-ftree-sink
-ftree-slsr
-ftree-sra
-ftree-pta
-ftree-ter
-funit-at-a-time
2. -O2
该优化选项会牺牲部分编译速度,除了执⾏-O1所执⾏的所有优化之外,还会采⽤⼏乎所有的⽬标配置⽀持的优化算法,⽤以提⾼⽬标代码的运⾏速度
english是什么意思
3. -O3
该选项除了执⾏-O2所有的优化选项之外,⼀般都是采取很多向量化算法,提⾼代码的并⾏执⾏程度,利⽤现代CPU中的流⽔线,Cache等4. -Os
-fthread-jumps -falign-functions -falign-jumps
-falign-loops -falign-labels -fcaller-saves
-fcrossjumping
-fc-follow-jumps -fc-skip-blocks
-
fdelete-null-pointer-checks
-fdevirtualize -fdevirtualize-speculatively
-fexpensive-optimizations
-fgc -fgc-lm
direct-fhoist-adjacent-loads
-finline-small-functions
-findirect-inlining
-fipa-cpreiz
-fipa-cp-alignment
-fipa-bit-cp
-fipa-sra
-
fipa-icf
见证奇迹的人生
-fisolate-erroneous-paths-dereference
-flra-remat
-foptimize-sibling-calls
-foptimize-strlen
-fpartial-inlining
-fpeephole2 -freorder-blocks-algorithm=stc
-freorder-blocks-and-partition -freorder-functions
-frerun-c-after-loop
-fsched-interblock -fsched-spec
-fschedule-insns -fschedule-insns2
-
fstrict-aliasing -fstrict-overflow世界杯 英文
-ftree-builtin-call-dce2014上海高考
-ftree-switch-conversion -ftree-tail-merge
-fcode-hoisting
-ftree-pre
-ftree-vrp
-fipa-ra
-finline-functions // 采⽤⼀些启发式算法对函数进⾏内联
-funswitch-loops // 执⾏循环unswitch 变换
-fpredictive-commoning //
-fgc-after-reload //执⾏全局的共同⼦表达式消除
-
ftree-loop-vectorize //
-ftree-loop-distribute-patterns
-fsplit-paths
-ftree-slp-vectorize
-fvect-cost-model
-ftree-partial-pre
-fpeel-loops
-fipa-cp-clone options
这个优化标识和-O3有异曲同⼯之妙,当然两者的⽬标不⼀样,
-O3的⽬标是宁愿增加⽬标代码的⼤⼩,也要拼命的提⾼运⾏速度,
但是这个选项是在-O2的基础之上,尽量的降低⽬标代码的⼤⼩,这对于存储容量很⼩的设备来说⾮常重要。
有利可图
为了降低⽬标代码⼤⼩,会禁⽤下列优化选项,⼀般就是压缩内存中的对齐空⽩(alignment padding)
5. -Ofast
该选项将不会严格遵循语⾔标准,除了启⽤所有的-O3优化选项之外,也会针对某些语⾔启⽤部分优化。如:-ffast-math ,对于Fortran 语⾔,还会启⽤下列选项
6.-Og
优化调试体验。 -Og应该是标准edit-compile-debug周期的优化级别选择,
在保持快速编译和良好调试体验的同时,提供合理的优化级别。
⽤于⽣成可调试代码,因为某些收集调试信息的编译器通道在以下位置被禁⽤ -O0。
像-O0 -Og完全禁⽤了许多优化过程,因此控制它们的单个选项⽆效。除此以外-Og 使所有 -O1 优化标志,但那些可能会⼲扰调试的标志除外:
-falign-functions -falign-jumps
-falign-loops -falign-labels
-freorder-blocks
-freorder-blocks-algorithm=stc
-freorder-blocks-and-partition -fprefetch-loop-arrays
-fno-protect-parens
-fstack-arrays
-fbranch-count-reg -fdelayed-branch
-fd
-fif-conversion
-fif-conversion2
-finline-functions-called-once
-fmove-loop-invariants
-fssa-phiopt
-ftree-bit-ccp
-ftree-d
-ftree-pta
-ftree-sra