gcc到底帮我打开了哪些具体优化选项
当我们使用gcc编译程序时,一般会选用某个优化编译选项,比如-O2、-O3、-Os,但这些选项使得gcc到底帮我打开了哪些具体优化选项呢?利用gcc的-Q和–help可以给我们答案:
[root@localhost ~]# gcc -c -Q -O3 --help=optimizers > /tmp/O3-opts [root@localhost ~]# gcc -c -Q -O2 --help=optimizers > /tmp/O2-opts [root@localhost ~]# gcc -c -Q -Os --help=optimizers > /tmp/Os-opts [root@localhost ~]# diff /tmp/Os-opts /tmp/O2-opts 49c49 < -finline-functions [enabled] --- > -finline-functions [disabled] [root@localhost ~]# diff /tmp/O2-opts /tmp/O3-opts 40c40 < -fgcse-after-reload [disabled] --- > -fgcse-after-reload [enabled] 49c49 < -finline-functions [disabled] --- > -finline-functions [enabled] 53c53 < -fipa-cp-clone [disabled] --- > -fipa-cp-clone [enabled] 78c78 < -fpredictive-commoning [disabled] --- > -fpredictive-commoning [enabled] 147c147 < -ftree-vectorize [disabled] --- > -ftree-vectorize [enabled] 154c154 < -funswitch-loops [disabled] --- > -funswitch-loops [enabled] [root@localhost ~]#
如果,我们发现在使用某个编译选项,比如-O3时,程序执行有问题,而在使用另外一个编译选项,比如-O2时,程序执行完好,那么就可以利用这种方法最快的定位到程序是受那个具体优化选项的影响。
关于-Q和–help的更多用法,请参考man手册。
转载请保留地址:http://lenky.info/archives/2012/08/18/1873 或 http://lenky.info/?p=1873
备注:如无特殊说明,文章内容均出自Lenky个人的真实理解而并非存心妄自揣测来故意愚人耳目。由于个人水平有限,虽力求内容正确无误,但仍然难免出错,请勿见怪,如果可以则请留言告之,并欢迎来讨论。另外值得说明的是,Lenky的部分文章以及部分内容参考借鉴了网络上各位网友的热心分享,特别是一些带有完全参考的文章,其后附带的链接内容也许更直接、更丰富,而我只是做了一下归纳&转述,在此也一并表示感谢。关于本站的所有技术文章,欢迎转载,但请遵从CC创作共享协议,而一些私人性质较强的心情随笔,建议不要转载。
法律:根据最新颁布的《信息网络传播权保护条例》,如果您认为本文章的任何内容侵犯了您的权利,请以或书面等方式告知,本站将及时删除相关内容或链接。