-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacros.llvm-pgo-instrumentation
99 lines (84 loc) · 3.78 KB
/
macros.llvm-pgo-instrumentation
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# llvm-pgo-instrumentation-macros
#
# Author: Konrad Kleine <[email protected]>
# To disable generation of profile subpackage, specify this in specfile:
# %global _toolchain_profile_subpackages %{nil}
# TODO(kwk): Make sure to only enable it when building with clang.
# tag::_toolchain_profile_subpackages[]
%_toolchain_profile_subpackages 1
# end::_toolchain_profile_subpackages[]
# tag::subpackage_template[]
# Generate profiledata packages for the compiler
%_toolchain_profile_subpackage_template \
%package -n %{name}-%{toolchain}-pgo-profdata \
Summary: Indexed PGO profile data from %{name} package \
%description -n %{name}-%{toolchain}-pgo-profdata \
This package contains profiledata for %{toolchain} that was generated while \
compiling %{name}. This can be used for doing Profile Guided Optimizations \
(PGO) builds of %{toolchain} \
%files -n %{name}-%{toolchain}-pgo-profdata \
%{_libdir}/%{toolchain}-pgo-profdata/%{name}/%{name}.%{toolchain}.profdata \
%{nil}
# end::subpackage_template[]
# tag::_pgo_macros_misc[]
# Auxilliary PGO profile to which the background job merges continously
%_pgo_background_merge_target %{_builddir}/%{name}.%{toolchain}.background.merge
# Place where the background job stores its PID file
# %%_pgo_pid_file %{_builddir}/background-merge.pid
%_pgo_pid_file /tmp/background-merge.pid
# How to specify the LLVM_PROFILE_FILE
%_pgo_llvm_profile_file %t/%{name}.%{toolchain}.%m.%p.profraw
# Where to store all raw PGO profiles
%_pgo_tmpdir %{_builddir}/raw-pgo-profdata
%_pgo_shutdown_file %{_pgo_tmpdir}/background-merge.shutdown
# Use this before calling an instrumented LLVM binary.
%_pgo_env \\\
TMPDIR='%{_pgo_tmpdir}' \\\
&& export TMPDIR \\\
&& mkdir -pv $TMPDIR \\\
&& LLVM_PROFILE_FILE='%{_pgo_llvm_profile_file}' \\\
&& export LLVM_PROFILE_FILE
# end::_pgo_macros_misc[]
# tag::find_and_merge_profiles[]
%_pgo_merge_profdata %[ 0%{_toolchain_profile_subpackages} > 0 ? "\\\
mkdir -pv %{buildroot}%{_libdir}/%{toolchain}-pgo-profdata/%{name} \\\
&& %{_pgo_env} \\\
&& llvm-profdata merge \\\
--compress-all-sections \\\
--sparse \\\
%{_pgo_background_merge_target} \\\
$(find %{_builddir}/raw-pgo-profdata -type f -name '*.profraw') \\\
-o %{buildroot}%{_libdir}/%{toolchain}-pgo-profdata/%{name}/%{name}.%{toolchain}.profdata \\\
" : "%{nil}" ]
# end::find_and_merge_profiles[]
# The following %%llvm_pgo_instrumented_XXX macros
# will be used in redhat-rpm-config.
# ------------------------------------------------
# tag::llvm_pgo_instrumented_build_flags[]
%llvm_pgo_instrumented_build_flags [ 0%{_toolchain_profile_subpackages} > 0 ] && %{_pgo_env}
# end::llvm_pgo_instrumented_build_flags[]
# tag::llvm_pgo_instrumented_spec_build_pre[]
%llvm_pgo_instrumented_spec_build_pre \
[ 0%{_toolchain_profile_subpackages} > 0 ] \\\
&& %{_pgo_env} \\\
&& /usr/lib/rpm/redhat/pgo-background-merge.sh \\\
-d %{_pgo_tmpdir} \\\
-f %{_pgo_background_merge_target} \\\
-p %{_pgo_pid_file} & \
# end::llvm_pgo_instrumented_spec_build_pre[]
# tag::llvm_pgo_instrumented_spec_build_post[]
# Overriding __spec_build_post macro from /usr/lib/rpm/macros
%llvm_pgo_instrumented_spec_build_post \
if [ 0%{_toolchain_profile_subpackages} > 0 ]\
then\
echo 'please exit' > %{_pgo_shutdown_file};\
[ -e %{_pgo_pid_file} ] && inotifywait -e delete_self %{_pgo_pid_file} || true;\
fi\
# end::llvm_pgo_instrumented_spec_build_post[]
# tag::llvm_pgo_instrumented_os_install_post[]
%llvm_pgo_instrumented_os_install_post %{?_toolchain_profile_subpackages:%{?_pgo_merge_profdata}}
# end::llvm_pgo_instrumented_os_install_post[]
# tag::llvm_pgo_instrumented_install[]
%llvm_pgo_instrumented_install\
%[ 0%{_toolchain_profile_subpackages} > 0 ? "%{_toolchain_profile_subpackage_template}" : "%{nil}" ]
# end::llvm_pgo_instrumented_install[]