Skip to content

Commit ff0d764

Browse files
authored
Merge pull request #22073 from nkcsgexi/PGO-swift
cmake: allow building the Swift compiler with Clang's Profile Guided Optimization (PGO)
2 parents 77689f5 + 018799c commit ff0d764

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ option(SWIFT_ENABLE_PARSEABLE_MODULE_INTERFACES
180180
"Generate .swiftinterface files alongside .swiftmodule files"
181181
TRUE)
182182

183+
# Allow building Swift with Clang's Profile Guided Optimization
184+
if(SWIFT_PROFDATA_FILE AND EXISTS ${SWIFT_PROFDATA_FILE})
185+
if(NOT CMAKE_C_COMPILER_ID MATCHES Clang)
186+
message(FATAL_ERROR "SWIFT_PROFDATA_FILE can only be specified when compiling with clang")
187+
endif()
188+
add_definitions("-fprofile-instr-use=${SWIFT_PROFDATA_FILE}")
189+
endif()
190+
183191
#
184192
# User-configurable Android specific options.
185193
#

utils/build-script-impl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ KNOWN_SETTINGS=(
266266
user-config-args "" "**Renamed to --extra-cmake-options**: User-supplied arguments to cmake when used to do configuration."
267267
only-execute "all" "Only execute the named action (see implementation)"
268268
llvm-lit-args "" "If set, override the lit args passed to LLVM"
269-
clang-profile-instr-use "" "If set, profile file to use for clang PGO"
269+
clang-profile-instr-use "" "If set, profile file to use for clang PGO while building llvm/clang"
270+
swift-profile-instr-use "" "If set, profile file to use for clang PGO while building swift"
270271
coverage-db "" "If set, coverage database to use when prioritizing testing"
271272
build-toolchain-only "" "If set, only build the necessary tools to build an external toolchain"
272273
skip-local-host-install "" "If we are cross-compiling multiple targets, skip an install pass locally if the hosts match"
@@ -759,6 +760,11 @@ function set_build_options_for_host() {
759760
)
760761
fi
761762

763+
if [[ "${SWIFT_PROFILE_INSTR_USE}" ]]; then
764+
swift_cmake_options+=(
765+
-DSWIFT_PROFDATA_FILE="${SWIFT_PROFILE_INSTR_USE}"
766+
)
767+
fi
762768
swift_cmake_options+=(
763769
-DCOVERAGE_DB="${COVERAGE_DB}"
764770
)

0 commit comments

Comments
 (0)