GCC编译器选项:哪组启用选项是正确的?

时间:2013-08-14 23:46:29

标签: c gcc compiler-optimization

我试图找出为GCC启用了哪些编译器选项(4.7.3,在Mac OS X 10.6.8上安装Macports)。我知道以下方法:

  1. 将{-Q选项与GCC 4.3.3 compiler options enabled建议的简单输入文件一起使用:

    gcc -Q -v -o hello hello.c
    
  2. 使用-Q --help = x组合(对于x的值,请参阅GCC documentation)例如:

    gcc -Q --help=target
    
  3. 要查看已启用的定义:

    echo "" | gcc -E -dM - | sort
    
  4. 然而,当我使用相同的优化选项集运行方法1和2时,我得到两组不同的启用/禁用选项。

    $ gcc -Q -v -O3 -march=native -o hello hello.c
    
    GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
    options passed:  -v -D__DYNAMIC__ hello.c -march=corei7-avx -mcx16 -msahf
    -mno-movbe -maes -mpclmul -mpopcnt -mno-abm -mno-lwp -mno-fma -mno-fma4
    -mno-xop -mno-bmi -mno-bmi2 -mno-tbm -mavx -mno-avx2 -msse4.2 -msse4.1
    -mno-lzcnt -mno-rdrnd -mno-f16c -mno-fsgsbase --param l1-cache-size=32
    --param l1-cache-line-size=64 --param l2-cache-size=6144 -mtune=corei7-avx
    -fPIC -mmacosx-version-min=10.6.8 -O3
    options enabled:  -Wnonportable-cfstrings -fPIC -falign-labels
    -fasynchronous-unwind-tables -fauto-inc-dec -fbranch-count-reg
    -fcaller-saves -fcombine-stack-adjustments -fcommon -fcompare-elim
    -fcprop-registers -fcrossjumping -fcse-follow-jumps -fdebug-types-section
    -fdefer-pop -fdelete-null-pointer-checks -fdevirtualize -fearly-inlining
    ...
    

    ,而

    $ gcc -Q -O3 -march=native --help=optimizers
    
    -falign-functions                   [enabled]
    -falign-jumps                       [enabled]
    -falign-labels                      [enabled]
    -falign-loops                       [enabled]
    -fasynchronous-unwind-tables        [enabled]
    -fbranch-count-reg                  [enabled]
    -fbranch-probabilities              [disabled]
    -fbranch-target-load-optimize       [disabled]
    -fbranch-target-load-optimize2      [disabled]
    -fbtr-bb-exclusive                  [disabled]
    -fcaller-saves                      [enabled]
    -fcombine-stack-adjustments         [enabled]
    -fcommon                            [enabled]
    -fcompare-elim                      [enabled]
    -fconserve-stack                    [disabled]
    -fcprop-registers                   [enabled]
    -fcrossjumping                      [enabled]
    -fcse-follow-jumps                  [enabled]
    -fcx-fortran-rules                  [disabled]
    -fcx-limited-range                  [disabled]
    -fdata-sections                     [disabled]
    -fdce                               [enabled]
    -fdefer-pop                         [enabled]
    -fdelayed-branch                    [disabled]
    -fdelete-null-pointer-checks        [enabled]
    -fdevirtualize                      [enabled]
    -fdse                               [enabled]
    -fearly-inlining                    [enabled]
    ...
    

    查看选项-falign-functions,-falign-jumps,-falign-labels和-falign-loops方法2声明它们都已启用,而方法1表示仅启用-falign-labels。还可以根据方法2启用选项-fdce和-fdse,但不根据方法1启用。

    问题:我应该信任哪种方法?

    旁注:方法2的列表不完整,因为选项已分组,并且仅列出了使用--help =选项请求的组。要查看方法2中的所有选项,请执行:

    $ gcc -Q -O3 -march=native --help=optimizers --help=target --help=c 
    --help=common --help=warnings | sort
    

1 个答案:

答案 0 :(得分:1)

来自GCC文件:

  

- help = {class | [^] qualifier} [,...]打印(在标准输出上)编译器理解的命令行选项的描述   适合所有指定的类和限定符。

,而

  

如果在-help =之前命令行中出现-Q选项   选项,然后更改--help =显示的描述性文本。   不是描述显示的选项,而是给出指示   选项是启用,禁用还是设置为特定值   (假设编译器在--help =的位置知道这一点   使用选项)

似乎--help只显示可以启用哪些选项,而-Q允许人们查看它是否实际启用。也:

  

输出对上一个命令行的效果很敏感   选项