Skip to content

Commit

Permalink
Add support for PGO builds with clang
Browse files Browse the repository at this point in the history
Summary:
This is also fixes support for PGO under GCC.
There will be files that end up without coverage due to certain tests being disabled because they are too flaky, or else make dangerous changes to the system (like setting the system time), so make the warning this generates not be a hard error.

Also notable is that under clang, the default target when running `make all` remains as `build_all` rather than `profile-opt` in order to support some internal build scenarios. With clang, explicitly building with `make profile-opt` will still produce a PGO'd binary.

Reviewed By: carljm

Differential Revision: D36238598

fbshipit-source-id: 3e1fbf5
  • Loading branch information
Orvid authored and facebook-github-bot committed May 16, 2022
1 parent 53af1f5 commit 5c04dc5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
20 changes: 18 additions & 2 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -6633,6 +6633,7 @@ $as_echo "$as_me: llvm-ar found via xcrun: ${LLVM_AR}" >&6;}
fi

CFLAGS_NODIST="$CFLAGS_NODIST $LTOFLAGS"
CXXFLAGS_NODIST="$CXXFLAGS_NODIST $LTOFLAGS"
LDFLAGS_NODIST="$LDFLAGS_NODIST $LTOFLAGS"
fi

Expand Down Expand Up @@ -6763,11 +6764,26 @@ $as_echo "$as_me: llvm-profdata found via xcrun: ${LLVM_PROFDATA}" >&6;}
fi
LLVM_PROF_ERR=no
case $CC in
*clang*)
# Any changes made here should be reflected in the GCC+Darwin case below
PGO_PROF_GEN_FLAG="-fprofile-instr-generate"
PGO_PROF_USE_FLAG="-fprofile-instr-use=code.profclangd -Wno-error=profile-instr-unprofiled"
LLVM_PROF_MERGER="${LLVM_PROFDATA} merge -output=code.profclangd *.profclangr"
LLVM_PROF_FILE="LLVM_PROFILE_FILE=\"code-%p.profclangr\""
if test $LLVM_PROF_FOUND = not-found
then
LLVM_PROF_ERR=yes
if test "${REQUIRE_PGO}" = "yes"
then
as_fn_error $? "llvm-profdata is required for a --enable-optimizations build but could not be found." "$LINENO" 5
fi
fi
;;
*gcc*)
case $ac_sys_system in
Darwin*)
PGO_PROF_GEN_FLAG="-fprofile-instr-generate"
PGO_PROF_USE_FLAG="-fprofile-instr-use=code.profclangd"
PGO_PROF_USE_FLAG="-fprofile-instr-use=code.profclangd -Wno-error=profile-instr-unprofiled"
LLVM_PROF_MERGER="${LLVM_PROFDATA} merge -output=code.profclangd *.profclangr"
LLVM_PROF_FILE="LLVM_PROFILE_FILE=\"code-%p.profclangr\""
if test "${LLVM_PROF_FOUND}" = "not-found"
Expand All @@ -6781,7 +6797,7 @@ case $CC in
;;
*)
PGO_PROF_GEN_FLAG="-fprofile-generate"
PGO_PROF_USE_FLAG="-fprofile-use -fprofile-correction"
PGO_PROF_USE_FLAG="-fprofile-use -fprofile-correction -Wno-error=missing-profile"
LLVM_PROF_MERGER="true"
LLVM_PROF_FILE=""
;;
Expand Down
20 changes: 18 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1381,6 +1381,7 @@ if test "$Py_LTO" = 'true' ; then
fi

CFLAGS_NODIST="$CFLAGS_NODIST $LTOFLAGS"
CXXFLAGS_NODIST="$CXXFLAGS_NODIST $LTOFLAGS"
LDFLAGS_NODIST="$LDFLAGS_NODIST $LTOFLAGS"
fi

Expand Down Expand Up @@ -1413,11 +1414,26 @@ then
fi
LLVM_PROF_ERR=no
case $CC in
*clang*)
# Any changes made here should be reflected in the GCC+Darwin case below
PGO_PROF_GEN_FLAG="-fprofile-instr-generate"
PGO_PROF_USE_FLAG="-fprofile-instr-use=code.profclangd -Wno-error=profile-instr-unprofiled"
LLVM_PROF_MERGER="${LLVM_PROFDATA} merge -output=code.profclangd *.profclangr"
LLVM_PROF_FILE="LLVM_PROFILE_FILE=\"code-%p.profclangr\""
if test "$LLVM_PROF_FOUND" = "not-found"
then
LLVM_PROF_ERR=yes
if test "${REQUIRE_PGO}" = "yes"
then
AC_MSG_ERROR([llvm-profdata is required for a --enable-optimizations build but could not be found.])
fi
fi
;;
*gcc*)
case $ac_sys_system in
Darwin*)
PGO_PROF_GEN_FLAG="-fprofile-instr-generate"
PGO_PROF_USE_FLAG="-fprofile-instr-use=code.profclangd"
PGO_PROF_USE_FLAG="-fprofile-instr-use=code.profclangd -Wno-error=profile-instr-unprofiled"
LLVM_PROF_MERGER="${LLVM_PROFDATA} merge -output=code.profclangd *.profclangr"
LLVM_PROF_FILE="LLVM_PROFILE_FILE=\"code-%p.profclangr\""
if test "${LLVM_PROF_FOUND}" = "not-found"
Expand All @@ -1431,7 +1447,7 @@ case $CC in
;;
*)
PGO_PROF_GEN_FLAG="-fprofile-generate"
PGO_PROF_USE_FLAG="-fprofile-use -fprofile-correction"
PGO_PROF_USE_FLAG="-fprofile-use -fprofile-correction -Wno-error=missing-profile"
LLVM_PROF_MERGER="true"
LLVM_PROF_FILE=""
;;
Expand Down

0 comments on commit 5c04dc5

Please sign in to comment.