找出确切的gcc隐式选项

时间:2016-06-20 06:11:17

标签: gcc compiler-optimization compiler-options

我有一个程序,只有在使用特定版本的gcc进行编译并使用一些优化(class TrivialDescriptor(object): def __init__(self, data): self._data = data def __get__(self, obj, objtype): return self._data class MyDescriptor(object): def __get__(self, obj, objtype): return 42 class MyClass(object): d = TrivialDescriptor(MyDescriptor()) 或更高版本,但不是-O1)时才有效。

这个程序在C意义上是不正确的,但是我需要理解为什么它不适用于-O0。它太大了,无法通过比较生成的汇编代码进行手动检查,因此我希望GCC告诉我与-O1执行相对应的确切标志,但不使用-O1本身。我们的想法是,通过一次删除每个优化,我能够更好地理解问题。

我转到我的specific gcc's optimization options page并尝试添加所有-O0选项,根据文档,这些选项由-O1启用,但这还不够(程序的行为仍然像-O0)。

有没有办法获得某种基于"低级"的标准化命令行?与GCC内部相对应的选项-f

1 个答案:

答案 0 :(得分:1)

您可以将标志Q --help=target,optimizer与任何优化程序标志(例如-O2或-O1)结合使用,以查看应用的标志。 记录在案here

如果您使用的是bash,则可以使用下面的oneliner来查看例如-O0和-O1)

$ diff -u  <(gcc -O0  -Q --help=optimizer ) <(gcc -Q --help=optimizer -O1)
--- /dev/fd/63  2016-06-20 08:20:36.957943807 +0200
+++ /dev/fd/62  2016-06-20 08:20:36.958943794 +0200
@@ -11,22 +11,22 @@
   -fassociative-math                   [disabled]
   -fasynchronous-unwind-tables                 [enabled]
   -fauto-inc-dec                       [enabled]
-  -fbranch-count-reg                   [disabled]
+  -fbranch-count-reg                   [enabled]
   -fbranch-probabilities               [disabled]
   -fbranch-target-load-optimize        [disabled]
   -fbranch-target-load-optimize2       [disabled]
   -fbtr-bb-exclusive                   [disabled]
   -fcaller-saves                       [disabled]
-  -fcombine-stack-adjustments          [disabled]
-  -fcompare-elim                       [disabled]
+  -fcombine-stack-adjustments          [enabled]
+  -fcompare-elim                       [enabled]
   -fconserve-stack                     [disabled]
-  -fcprop-registers                    [disabled]
+  -fcprop-registers                    [enabled]
   -fcrossjumping                       [disabled]
   -fcse-follow-jumps                   [disabled]
   -fcx-fortran-rules                   [disabled]
   -fcx-limited-range                   [disabled]
   -fdce                                [enabled]
-  -fdefer-pop                          [disabled]
+  -fdefer-pop                          [enabled]
   -fdelayed-branch                     [disabled]
   -fdelete-dead-exceptions             [disabled]
   -fdelete-null-pointer-checks                 [enabled]
@@ -38,7 +38,7 @@
   -fexpensive-optimizations            [disabled]
   -ffinite-math-only                   [disabled]
   -ffloat-store                        [disabled]
-  -fforward-propagate                  [disabled]
+  -fforward-propagate                  [enabled]
   -ffp-contract=                       fast
   -ffunction-cse                       [enabled]
   -fgcse                               [disabled]
@@ -48,27 +48,27 @@
   -fgcse-sm                            [disabled]
   -fgraphite                           [disabled]
   -fgraphite-identity                  [disabled]
-  -fguess-branch-probability           [disabled]
+  -fguess-branch-probability           [enabled]
   -fhandle-exceptions
   -fhoist-adjacent-loads               [disabled]
-  -fif-conversion                      [disabled]
-  -fif-conversion2                     [disabled]
+  -fif-conversion                      [enabled]
+  -fif-conversion2                     [enabled]
   -findirect-inlining                  [disabled]
   -finline                             [enabled]
   -finline-atomics                     [enabled]
   -finline-functions                   [disabled]
-  -finline-functions-called-once       [disabled]
+  -finline-functions-called-once       [enabled]
   -finline-small-functions             [disabled]
   -fipa-cp                             [disabled]
   -fipa-cp-alignment                   [disabled]
   -fipa-cp-clone                       [disabled]
   -fipa-icf                            [disabled]
   -fipa-icf-functions                  [disabled]
-  -fipa-profile                        [disabled]
+  -fipa-profile                        [enabled]
   -fipa-pta                            [disabled]
-  -fipa-pure-const                     [disabled]
+  -fipa-pure-const                     [enabled]
   -fipa-ra                             [disabled]
-  -fipa-reference                      [disabled]
+  -fipa-reference                      [enabled]
   -fipa-sra                            [disabled]
   -fira-algorithm=                     CB
   -fira-hoist-pressure                 [enabled]
@@ -92,7 +92,7 @@
   -fmath-errno                         [enabled]
   -fmodulo-sched                       [disabled]
   -fmodulo-sched-allow-regmoves        [disabled]
-  -fmove-loop-invariants               [disabled]
+  -fmove-loop-invariants               [enabled]
   -fnon-call-exceptions                [disabled]
   -fnothrow-opt                        [disabled]
   -fomit-frame-pointer                 [disabled]
@@ -145,14 +145,14 @@
   -fshort-double                       [disabled]
   -fshort-enums                        [enabled]
   -fshort-wchar                        [disabled]
-  -fshrink-wrap                        [disabled]
+  -fshrink-wrap                        [enabled]
   -fsignaling-nans                     [disabled]
   -fsigned-zeros                       [enabled]
   -fsimd-cost-model=                   unlimited
   -fsingle-precision-constant          [disabled]
   -fsplit-ivs-in-unroller              [enabled]
-  -fsplit-wide-types                   [disabled]
-  -fssa-phiopt                         [disabled]
+  -fsplit-wide-types                   [enabled]
+  -fssa-phiopt                         [enabled]
   -fstack-reuse=                       all
   -fstdarg-opt                         [enabled]
   -fstrict-aliasing                    [disabled]
@@ -164,20 +164,20 @@
   -ftracer                             [disabled]
   -ftrapping-math                      [enabled]
   -ftrapv                              [disabled]
-  -ftree-bit-ccp                       [disabled]
+  -ftree-bit-ccp                       [enabled]
   -ftree-builtin-call-dce              [disabled]
-  -ftree-ccp                           [disabled]
-  -ftree-ch                            [disabled]
+  -ftree-ccp                           [enabled]
+  -ftree-ch                            [enabled]
   -ftree-coalesce-inlined-vars                 [disabled]
   -ftree-coalesce-vars                 [enabled]
-  -ftree-copy-prop                     [disabled]
-  -ftree-copyrename                    [disabled]
+  -ftree-copy-prop                     [enabled]
+  -ftree-copyrename                    [enabled]
   -ftree-cselim                        [enabled]
-  -ftree-dce                           [disabled]
-  -ftree-dominator-opts                [disabled]
-  -ftree-dse                           [disabled]
+  -ftree-dce                           [enabled]
+  -ftree-dominator-opts                [enabled]
+  -ftree-dse                           [enabled]
   -ftree-forwprop                      [enabled]
-  -ftree-fre                           [disabled]
+  -ftree-fre                           [enabled]
   -ftree-loop-distribute-patterns      [disabled]
   -ftree-loop-distribution             [disabled]
   -ftree-loop-if-convert               [enabled]
@@ -191,16 +191,16 @@
   -ftree-partial-pre                   [disabled]
   -ftree-phiprop                       [enabled]
   -ftree-pre                           [disabled]
-  -ftree-pta                           [disabled]
+  -ftree-pta                           [enabled]
   -ftree-reassoc                       [enabled]
   -ftree-scev-cprop                    [enabled]
-  -ftree-sink                          [disabled]
+  -ftree-sink                          [enabled]
   -ftree-slp-vectorize                 [disabled]
-  -ftree-slsr                          [disabled]
-  -ftree-sra                           [disabled]
+  -ftree-slsr                          [enabled]
+  -ftree-sra                           [enabled]
   -ftree-switch-conversion             [disabled]
   -ftree-tail-merge                    [disabled]
-  -ftree-ter                           [disabled]
+  -ftree-ter                           [enabled]
   -ftree-vectorize                     [disabled]
   -ftree-vrp                           [disabled]
   -funroll-all-loops                   [disabled]