Rate This Document
Findability
Accuracy
Completeness
Readability

-fauto-bolt, -fbolt-use, -fbolt-target, -fbolt-option

Description

  • The -fauto-bolt option is used to enable the AutoBOLT optimization. The optimization reuses a profile from instrumentation-based feedback-directed optimization (FDO) or AutoFDO, converts the profile into a BOLT format, calls BOLT, and automatically completes the post-link optimization.
    • The converted profile is saved in the current path by default.
    • You can set -fauto-bolt=PATH to specify a path for saving the BOLT profile, for example, -fauto-bolt=/tmp.
  • The -fbolt-use option is used to directly use the specified profile to complete post-link optimization.
    • By default, the profile named data.fdata in the current path is used for optimization.
    • You can set -fbolt-use=FILE to specify a profile to be used, for example, -fbolt-use=/tmp/a.fdata.
  • -fbolt-target=NAME is used to specify the object optimized by BOLT. After this option is used, only the binary and dynamic libraries specified by NAME are optimized.
  • -fbolt-option=PARAM is used to specify BOLT optimization options. Different options are separated by commas (,), for example, -fbolt-option="-reorder-blocks=cache+,-reorder-functions=hfsort+". To use this option, you must specify PARAM.

Usage

The code of test case test.c is as follows:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#define ARRAY_LEN 30000
static struct timeval tm1;

static inline void start()
{
    gettimeofday(&tm1, NULL);
}

static inline void stop()
{
    struct timeval tm2;
    gettimeofday(&tm2, NULL);
    unsigned long long t = 1000 * (tm2.tv_sec - tm1.tv_sec) +\
                           (tm2.tv_usec - tm1.tv_usec) / 1000;
    printf("%llu ms\n", t);
}

void bubble_sort (int *a, int n)
{
    int i, t, s = 1;
    while (s)
    {
        s = 0;
        for (i = 1; i < n; i++)
        {
            if (a[i] < a[i - 1])
            {
                t = a[i];
                a[i] = a[i - 1];
                a[i - 1] = t;
                s = 1;
            }
        }
    }
}

void sort_array()
{
    printf("Bubble sorting array of %d elements\n", ARRAY_LEN);
    int data[ARRAY_LEN], i;
    for(i=0; i<ARRAY_LEN; ++i)
    {
        data[i] = rand();
    }
    bubble_sort(data, ARRAY_LEN);
}

int main()
{
    start();
    sort_array();
    stop();
    return 0;
}
  • Obtaining a profile

    Use perf to collect a profile.

    1
    2
    gcc -g -O2 -o test test.c -Wl,-q
    perf record -e cycles:up -o pmu.data ./test
    

    Obtain a profile in AutoBOLT mode.

    1
    create_gcov --binary=test --profile=pmu.data --gcov=pmu.gcov --gcov_version=1 --use_lbr=0
    

    Use perf2bolt to obtain a profile.

    1
    perf2bolt -p=pmu.data test -o pmu.fdata -nl
    
  • AutoBOLT mode

    This mode must be used together with the -fauto-profile or -fprofile-use option, and -Wl,-q must be added to retain the relocation information. The following uses the test program as an example:

    1
    gcc -g -O2 -o test test.c -fauto-profile=pmu.gcov -fauto-bolt -Wl,-q
    

    Or

    1
    gcc -g -O2 -o test test.c -fprofile-use -fauto-bolt -Wl,-q
    

    In this update, -fprofile-use and -fauto-profile support -flto. The typical process is as follows:

    1
    2
    3
    gcc -g -O2 -o test test.c -fprofile-generate=./profile -Wl,-q
    ./test
    gcc -g -O2 -o test test.c -fprofile-use=./profile -fauto-bolt -flto -Wl,-q
    
  • BOLT use mode

    In this mode, the profile required for BOLT optimization must be prepared in advance. The profile can be obtained in AutoBOLT mode or by using the perf2bolt tool.

    1
    gcc -g -O2 -o test test.c -fbolt-use=pmu.fdata -Wl,-q
    
  • -fauto-bolt must be used together with -fauto-profile or -fprofile-use.
  • Currently, -fauto-bolt and -fprofile-use can be used together with -flto.
  • -fauto-bolt or -fbolt-use must be used together with -Wl,-q.
  • -fbolt-target and -fbolt-option must be used together with -fauto-bolt or -fbolt-use.
  • The llvm-bolt software package must be installed in the system.