Rate This Document
Findability
Accuracy
Completeness
Readability

Source Code Build After Annotation

BiSheng compiler can enable the compilation optimization guide provided by the annotation information only after the corresponding optimization function is enabled.

Function control option: -mllvm -enable-prob-annotate=true

Profile summary input option: -mllvm -profile-summary-json-file=***.json

After the preceding two compilation options are enabled, you can compile and build the annotated source code. This feature takes effect when the optimization level is greater than O0.

Example:

Assume that the annotated source code (test.c) is as follows:

 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;
}

Enable related features for compilation (-mllvm -profile-summary-json-file=/path/to/***.json is optional).

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