Is there a GCC keyword to allow structure-reordering?
我知道为什么gcc在默认情况下不重新排序结构的成员,但我很少编写依赖于结构顺序的代码,所以有什么方法可以标记结构以便自动重新排序?
以前的GCC版本有
-fipa-struct-reorg
Perform structure reorganization optimization, that change C-like structures layout in order to better utilize spatial locality. This transformation is affective for programs containing arrays of structures. Available in two compilation modes: profile-based (enabled with-fprofile-generate ) or static (which uses built-in heuristics). Require-fipa-type-escape to provide the safety of this transformation. It works only in whole program mode, so it requires-fwhole-program and-combine to be enabled. Structures considered'cold' by this transformation are not affected (see--param struct-reorg-cold-struct-ratio=value ).
由于发布说明中的以下原因,从GCC 4.8.x中删除了它
The struct reorg and matrix reorg optimizations (command-line options
-fipa-struct-reorg and-fipa-matrix-reorg ) have been removed. They did not always work correctly, nor did they work with link-time optimization (LTO), hence were only applicable to programs consisting of a single translation unit.
但是,您仍然可以在GCC SVN上尝试
在GCC中没有这样的选择。而且,我确信,它不能以任何明智的方式引入。关于填充优化,请看下面的讨论。
我知道的唯一例外是热/冷结构字段拆分,在某些情况下可以这样做(但我不确定,GCC甚至可以在配置文件引导模式下这样做,我知道ICC可以)。此功能不受用户控制,并在调用图上执行,在调用图上可以证明数据流上的这种转换是保守的。
我认为在编译整个程序(LTO模式,使用-flto标志)时可以重新组织/拆分结构的元素。在这种情况下,您可以获得程序的完整图片,对于不可转义的符号,应该可以对它们重新排序,以获得更好的缓存行为等。
在GCC主干中,这是在积极开发中的。这是在GNU大锅2015中提出的。您可能需要尝试gcc主干或struct reorg分支。
https://gcc.gnu.org/wiki/couldron2015?action=attachfile&do=view&target=olga+golovanevasky_uux+memory+layout+optimizations+of+structures+and+objects.pdf