从 GCC 获取优化报告

发布于 2024-12-07 00:21:16 字数 131 浏览 1 评论 0原文

我想知道是否有一个选项可以与 GCC 一起使用来获取有关编译器实际选择和执行的优化的详细报告。这可以通过使用 -opt-report 的 Intel C 编译器来实现。我不想查看汇编文件并找出优化方案。我专门寻找编译器选择的循环展开和循环平铺因子。

I would like to know if there is an option I can use with GCC to get a detailed report on the optimization actually chosen and performed by the compiler. This is possible with the Intel C compiler using the -opt-report. I do not want to look at the assembly file and figure out the optimization. I am specifically looking for the loop unrolling and loop tiling factors chosen by the compiler.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

眼眸里的快感 2024-12-14 00:21:16

虽然它不是聚合信息意义上的报告,但您可以尝试使用 -fdump-ipa-all 选项,该选项使 gcc 生成转储文件,这至少可以让您避免分析汇编代码以了解发生了什么。

关于循环优化,-fdump-rtl-loop2 选项可能会令人感兴趣。

有关所有这些的详细信息,请参阅调试程序或 GCC 的选项 手册的内容。

Although it's not a report in the sense of aggregated information, you might try the -fdump-ipa-all option which makes gcc produce dump files which at least keep you from having to analyse assembler code on what happened.

Regarding loop optimization the -fdump-rtl-loop2 option might be of interest.

For details on all this please see the section Options for Debugging Your Program or GCC of the manual.

过潦 2024-12-14 00:21:16

GCC 的报告并不像英特尔那样直接,但我们可以更喜欢。这里是 GCC 优化时使用的详细选项。

-fopt-信息
-fopt-信息选项
-fopt-info-options=文件名
控制来自各种优化过程的优化转储。如果使用“-options”形式,则选项是“-”分隔的选项关键字的列表,用于选择转储详细信息和优化。

这些选项可以分为三组:

描述应发出哪种消息的选项,
描述转储的详细程度的选项,以及
描述应包括哪些优化的选项。
每组的选项可以自由混合,因为它们不重叠。但是,如果发生任何冲突,后面的选项将覆盖命令行上前面的选项。

以下选项控制应发出哪种类型的消息:

“optimized”
成功应用优化后打印信息。由通行证决定哪些信息是相关的。例如,矢量化器会打印成功矢量化的循环的源位置。

‘错过’
打印有关错过优化的信息。各个通道控制输出中包含哪些信息。

'笔记'
打印有关优化的详细信息,例如某些转换、有关决策的更详细消息等。

“全部”
打印详细的优化信息。这包括“优化”、“错过”和“注释”。

以下选项控制转储详细程度:

“internals”
默认情况下,仅发出“高级”消息。此选项支持额外的、更详细的消息,这些消息可能只有 GCC 开发人员感兴趣。

可以使用以下一个或多个选项关键字来描述一组优化:

'ipa'
启用所有过程间优化的转储。

'环形'
启用所有循环优化的转储。

'排队'
启用所有内联优化的转储。

'奥普'
启用所有 OMP(卸载和多重处理)优化的转储。

'vec'
启用所有矢量化优化的转储。

'选择'
启用所有优化的转储。这是上面列出的优化组的超集。

如果省略 options,则默认为“optimized-optall”,这意味着从所有传递中转储有关成功优化的消息,省略被视为“内部”的消息。

如果提供了文件名,则所有适用优化的转储将连接到文件名中。否则转储将输出到 stderr。尽管接受多个 -fopt-info 选项,但只有其中一个可以包含文件名。如果提供了其他文件名,则除了第一个此类选项之外的所有选项都将被忽略。

请注意,如果有多个翻译单元,输出文件名将被覆盖。如果需要多个翻译单元的组合输出,则应使用 stderr。

在以下示例中,优化信息输出到 stderr:

gcc -O3 -fopt-info
这个例子:

gcc -O3 -fopt-info-missed=missed.all
将所有传递的错过优化报告输出到missed.all,这一个:

gcc -O2 -ftree-vectorize -fopt-info-vec-missed
在 stderr 上打印有关矢量化传递中错过的优化机会的信息。请注意,-fopt-info-vec-missed 等效于 -fopt-info-missed-vec。 -fopt-info 之后列出的优化组名称和消息类型的顺序并不重要。

另一个例子,

gcc -O3 -fopt-info-inline-optimized-missed=inline.txt
将所有内联过程中错过的优化以及优化位置的信息输出到 inline.txt 中。

最后,考虑:

gcc -fopt-info-vec-missed=vec.miss -fopt-info-loop-optimized=loop.opt
这里两个输出文件名 vec.miss 和 Loop.opt 发生冲突,因为只允许一个输出文件。在这种情况下,只有第一个选项生效,后续选项将被忽略。因此,仅生成 vec.miss,其中包含来自矢量化器的有关错过机会的转储。

The reports from GCC is not that straight forward as like intel, but we can prefer. here is the detailed options use for optimization done by GCC.

-fopt-info
-fopt-info-options
-fopt-info-options=filename
Controls optimization dumps from various optimization passes. If the ‘-options’ form is used, options is a list of ‘-’ separated option keywords to select the dump details and optimizations.

The options can be divided into three groups:

options describing what kinds of messages should be emitted,
options describing the verbosity of the dump, and
options describing which optimizations should be included.
The options from each group can be freely mixed as they are non-overlapping. However, in case of any conflicts, the later options override the earlier options on the command line.

The following options control which kinds of messages should be emitted:

‘optimized’
Print information when an optimization is successfully applied. It is up to a pass to decide which information is relevant. For example, the vectorizer passes print the source location of loops which are successfully vectorized.

‘missed’
Print information about missed optimizations. Individual passes control which information to include in the output.

‘note’
Print verbose information about optimizations, such as certain transformations, more detailed messages about decisions etc.

‘all’
Print detailed optimization information. This includes ‘optimized’, ‘missed’, and ‘note’.

The following option controls the dump verbosity:

‘internals’
By default, only “high-level” messages are emitted. This option enables additional, more detailed, messages, which are likely to only be of interest to GCC developers.

One or more of the following option keywords can be used to describe a group of optimizations:

‘ipa’
Enable dumps from all interprocedural optimizations.

‘loop’
Enable dumps from all loop optimizations.

‘inline’
Enable dumps from all inlining optimizations.

‘omp’
Enable dumps from all OMP (Offloading and Multi Processing) optimizations.

‘vec’
Enable dumps from all vectorization optimizations.

‘optall’
Enable dumps from all optimizations. This is a superset of the optimization groups listed above.

If options is omitted, it defaults to ‘optimized-optall’, which means to dump messages about successful optimizations from all the passes, omitting messages that are treated as “internals”.

If the filename is provided, then the dumps from all the applicable optimizations are concatenated into the filename. Otherwise the dump is output onto stderr. Though multiple -fopt-info options are accepted, only one of them can include a filename. If other filenames are provided then all but the first such option are ignored.

Note that the output filename is overwritten in case of multiple translation units. If a combined output from multiple translation units is desired, stderr should be used instead.

In the following example, the optimization info is output to stderr:

gcc -O3 -fopt-info
This example:

gcc -O3 -fopt-info-missed=missed.all
outputs missed optimization report from all the passes into missed.all, and this one:

gcc -O2 -ftree-vectorize -fopt-info-vec-missed
prints information about missed optimization opportunities from vectorization passes on stderr. Note that -fopt-info-vec-missed is equivalent to -fopt-info-missed-vec. The order of the optimization group names and message types listed after -fopt-info does not matter.

As another example,

gcc -O3 -fopt-info-inline-optimized-missed=inline.txt
outputs information about missed optimizations as well as optimized locations from all the inlining passes into inline.txt.

Finally, consider:

gcc -fopt-info-vec-missed=vec.miss -fopt-info-loop-optimized=loop.opt
Here the two output filenames vec.miss and loop.opt are in conflict since only one output file is allowed. In this case, only the first option takes effect and the subsequent options are ignored. Thus only vec.miss is produced which contains dumps from the vectorizer about missed opportunities.

蓝颜夕 2024-12-14 00:21:16

您还可以考虑 fsave-optimization-record 选项

You may also consider fsave-optimization-record option

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文