kkleine / rpms / llvm

Forked from rpms/llvm 3 years ago
Clone
Blob Blame History Raw
# llvm-pgo-instrumentation-macros
#
# Author: Konrad Kleine <kkleine@redhat.com>

# To disable generation of profile subpackage, specify this in specfile:
#
#     %global __llvm_pgo_subpackage %{nil}
#
%__llvm_pgo_subpackage 1

# Generate profiledata packages for the compiler
%__llvm_pgo_subpackage_template \
%package -n %{name}-llvm-pgo-profdata \
Summary: Indexed PGO profile data from %{name} package \
%description -n %{name}-llvm-pgo-profdata \
This package contains profiledata for llvm that was generated while \
compiling %{name}. This can be used for doing Profile Guided Optimizations \
(PGO) builds of llvm \
%files -n %{name}-llvm-pgo-profdata \
%{_libdir}/llvm-pgo-profdata/%{name}/%{name}.llvm.profdata \
%{nil}

# Auxilliary PGO profile to which the background job merges continously
%__pgo_background_merge_target %{_builddir}/%{name}.llvm.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}.llvm.%m.%p.profraw

# Where to store all raw PGO profiles
%__pgo_profdir %{_builddir}/raw-pgo-profdata

# Write to this file to gracefully stop the background merge job
%__pgo_shutdown_file %{__pgo_profdir}/pgo-background-merge.shutdown

# Use this before calling an instrumented LLVM binary.
%__pgo_env \\\
  TMPDIR='%{__pgo_profdir}' \\\
  && export TMPDIR \\\
  && mkdir -pv $TMPDIR \\\
  && LLVM_PROFILE_FILE='%{__pgo_llvm_profile_file}' \\\
  && export LLVM_PROFILE_FILE

%__pgo_merge_profdata %[ 0%{__llvm_pgo_subpackage} > 0 ? "\\\
  mkdir -pv %{buildroot}%{_libdir}/llvm-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}/llvm-pgo-profdata/%{name}/%{name}.llvm.profdata \\\
  " : "%{nil}" ]

# The following %%__llvm_pgo_instrumented_XXX RPM macros are meant to be used in
# weaved into the XXX part (see pgo-regen-macros.sh) for how we do that.
#-------------------------------------------------------------------------------

%__llvm_pgo_instrumented_build_flags\
  [ 0%{__llvm_pgo_subpackage} > 0 ] && %{__pgo_env}

%__llvm_pgo_instrumented_spec_build_pre \
    [ 0%{__llvm_pgo_subpackage} > 0 ] \\\
    && %{__pgo_env} \\\
    && /usr/lib/rpm/redhat/pgo-background-merge.sh \\\
      -d %{__pgo_profdir} \\\
      -f %{__pgo_background_merge_target} \\\
      -p %{__pgo_pid_file} & \

# Overriding __spec_build_post macro from /usr/lib/rpm/macros
%__llvm_pgo_instrumented_spec_build_post	\
  if [ 0%{__llvm_pgo_subpackage} > 0 ]\
  then\
      echo 'please exit' > %{__pgo_shutdown_file};\
      [ -e %{__pgo_pid_file} ] && inotifywait -e delete_self %{__pgo_pid_file} || true;\
  fi\

%__llvm_pgo_instrumented_os_install_post\
  %{?__llvm_pgo_subpackage:%{?__pgo_merge_profdata}}

%__llvm_pgo_instrumented_install\
  %[ 0%{__llvm_pgo_subpackage} > 0 ? "%{__llvm_pgo_subpackage_template}" : "%{nil}" ]