标注后源码构建

需要打开对应的优化开关,毕昇编译器才可以启用标注信息提供的编译优化指导。

功能控制选项:-mllvm -enable-prob-annotate=true

ProfileSummary输入选项:-mllvm -profile-summary-json-file=***.json

请在开启以上两个编译选项后,编译构建标注后源码,该特性支持在优化等级大于O0的情况下生效。

示例说明:

假设有标注后的源码(test.c)如下:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
extern double *a;
extern int N;
double __attribute__((hotness(0.630930))) func() {
    double res = 0;
    __attribute__((likelihood(0.999950))) for (int i = 0; i < N; ++i) {
        __attribute__((likelihood(0.250000))) if ((int)a[i] % 2 == 0) {
            res += a[i] + i;
        } else {
            res -= a[i] - i;
        }
    }
    return res;
}

开启相关特性支持进行编译(其中,-mllvm -profile-summary-json-file=/path/to/***.json为可选选项):

1
clang  -O1 -mllvm -enable-prob-annotate=true -mllvm -profile-summary-json-file=/path/to/***.json test.c