-fprofile-use
和 -fauto-profile
有什么区别?
文档是这样说的:
https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#Optimize-Options
-fprofile-use
-fprofile-use=path
Enable profile feedback-directed optimizations, and the following optimizations which are generally profitable only with profile feedback available: [...]
If path is specified, GCC looks at the path to find the profile feedback data files. See -fprofile-dir.
在下面
-fauto-profile
-fauto-profile=path
Enable sampling-based feedback-directed optimizations, and the following optimizations which are generally profitable only with profile feedback available: [...]
path is the name of a file containing AutoFDO profile information. If omitted, it defaults to fbdata.afdo in the current directory.
([...]
中针对 -fauto-profile
的优化列表更长。)
最佳答案
我是通过一条我什至不记得的路径偶然发现这个线程的,并且在我前进的过程中正在学习这些东西。但如果我能从中学到一些东西,我不喜欢看到一个没有答案的问题!所以我开始读书了。
反馈导向优化
正如 GCC 所说,这两种都是应用反馈导向优化的模式。通过运行该程序并剖析它做了什么、它是如何做的、它在哪些功能上花费了多长时间等 - 我们可能会促进额外的、定向优化数据。分析器的结果被“反馈”给优化器。接下来,据推测,您可以使用配置文件优化的二进制文件和配置文件that,然后编译另一个 FDO 版本,依此类推...因此是 feedback 部分姓名。
真正的答案,即这两个开关之间的区别,并没有非常清楚地记录在案,但如果我们需要进一步观察,它是可用的。
-fprofile-使用
首先,您对 -fprofile-use
的引述实际上只是声明它需要 -fprofile-generate
,而这个选项并不是有据可查:来自 -use
的引用只是告诉您阅读您已经在的页面,在所有情况下,-generate
仅被提及但从未定义。有用! 但是!我们可以引用这个问题的答案:How to use profile guided optimizations in g++?
正如该回答所述,这里有问题的 GCC 文档部分温和地指出...-fprofile-generate
导致 instrumentation 要添加到输出二进制文件中。正如该页面所总结的那样,经过检测的可执行文件添加了一些内容,以促进在其运行时进行额外的检查或洞察。
(我知道的另一种形式的检测 - 也是我使用过的一种 - 是编译器附加库 UBSan,我通过 GCC's -fsanitize=undefined
option 使用它。这会在运行时捕获一些未定义的行为。GCC 与此已经揭示了 UB,否则我可能会花很长时间才能找到 - 这让我想知道我的程序到底是如何运行的!Clang can use this library too,也许还有其他编译器。)
-自动配置文件
相比之下,-fauto-profile
就不同了。在您引用的概要中暗示了关键区别,如果不是很清楚的话:
path
is the name of a file containing AutoFDO profile information.
此模式使用 AutoFDO 处理分析和后续优化。我们去谷歌:AutoFDO前几行并没有尽可能简洁地解释这一点,我认为最好的总结被埋在了页面的深处:
The major difference between AutoFDO [
-fauto-profile
] and FDO [-fprofile-use
] is that AutoFDO profiles on optimized binary instead of instrumented binary. This makes it very different in handling cloned functions.
它是如何做到这一点的? -fauto-profile
要求您提供由 Linux 内核的分析器写出的分析文件,Perf , 转换为 AutoFDO 格式。 Perf 不是添加检测,而是使用 CPU 的硬件特性和操作系统的内核级特性来分析有关程序运行时的各种统计信息:
perf
is powerful: it can instrument CPU performance counters, tracepoints, kprobes, and uprobes (dynamic tracing). It is capable of lightweight profiling. [...] Performance counters are CPU hardware registers that count hardware events such as instructions executed, cache-misses suffered, or branches mispredicted. They form a basis for profiling applications to trace dynamic control flow and identify hotspots.
因此,它可以分析一个优化的程序,而不是一个经过检测的程序。我们可能会合理地假设这更能代表您的程序在现实世界中的 react - 因此可以促进收集更有用的分析数据并因此应用更有效的优化。
这里总结了一个示例,说明如何将所有这些结合在一起并让 -fauto-profile
对您的程序执行某些操作:Feedback directed optimization with GCC and Perf
(也许现在我已经了解了所有这些,总有一天我会尝试这些选项!)
关于c++ - -fprofile-use 和 -fauto-profile 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29700460/