鲲鹏社区首页
中文
注册
开发者
我要评分
获取效率
正确性
完整性
易理解
在线提单
论坛求助

选项 -fipa-struct-reorg

内存空间布局优化,将结构体成员在内存中的排布进行重新排列组合,以提高cache命中率。

  • 结构体拆分:将结构体的冷热成员单独拆分成一个结构体类型
    图1 结构体拆分优化原理示意图

将以下结构体:

1
2
3
4
5
6
struct S
{
    type1 field1; // Hot field
    type2 field2;
};
S *v;

转化为:

1
2
3
4
5
6
7
8
9
struct S_hot
{
    type1 field1;
};
struct S_cold 
{
    type2 field2;
};
S_hot *v_hot;S_cold *v_cold;
  • 结构体数组优化:将结构体的数组转化为数组的结构体。
    图2 结构体数组优化原理示意图

    将以下结构体:

    1
    2
    3
    4
    5
    6
    struct 
    {
        type1 field1;
        type2 field2;
        type3 field3;
    } arr[N];
    

    转化为:

    1
    2
    3
    4
    5
    6
    struct
    {
        type1 field1[N];
        type2 field2[N];
        type3 field3[N];
    } arr;
    

使用方法

在编译选项中加入:

1
-O3 -flto -flto-partition=one -fipa-struct-reorg

-fipa-struct-reorg选项,需要在-O3 -flto -flto-partition=one同时开启的基础上才使能。

SPEC性能提升效果:SPEC CPU 2017 intrate 505.mcf子项性能提升20%。