Skip to content

Commit 1625d97

Browse files
author
Harlan
authored
Switch to llvm-profdata's pooled profdata merge (#3281)
1 parent 8de7045 commit 1625d97

File tree

18 files changed

+48
-433
lines changed

18 files changed

+48
-433
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ function(_add_variant_c_compile_link_flags)
116116
"-arch" "${CFLAGS_ARCH}"
117117
"-F" "${SWIFT_SDK_${CFLAGS_SDK}_PATH}/../../../Developer/Library/Frameworks"
118118
"-m${SWIFT_SDK_${CFLAGS_SDK}_VERSION_MIN_NAME}-version-min=${DEPLOYMENT_VERSION}")
119+
endif()
119120

120-
if(CFLAGS_ANALYZE_CODE_COVERAGE)
121-
list(APPEND result "-fprofile-instr-generate"
122-
"-fcoverage-mapping")
123-
endif()
121+
if(CFLAGS_ANALYZE_CODE_COVERAGE)
122+
list(APPEND result "-fprofile-instr-generate"
123+
"-fcoverage-mapping")
124124
endif()
125125

126126
_compute_lto_flag("${CFLAGS_ENABLE_LTO}" _lto_flag_out)

cmake/modules/AddSwiftUnittests.cmake

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ function(add_swift_unittest test_dirname)
4242
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
4343
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY
4444
LINK_FLAGS " -Xlinker -rpath -Xlinker ${SWIFT_LIBRARY_OUTPUT_INTDIR}/swift/macosx")
45-
46-
if(SWIFT_ANALYZE_CODE_COVERAGE)
47-
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY
48-
LINK_FLAGS " -fprofile-instr-generate -fcoverage-mapping")
49-
endif()
5045
endif()
5146

5247
if(SWIFT_ENABLE_GOLD_LINKER AND
@@ -58,6 +53,11 @@ function(add_swift_unittest test_dirname)
5853
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY
5954
LINK_FLAGS " -fuse-ld=lld")
6055
endif()
56+
57+
if(SWIFT_ANALYZE_CODE_COVERAGE)
58+
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY
59+
LINK_FLAGS " -fprofile-instr-generate -fcoverage-mapping")
60+
endif()
6161
endfunction()
6262

6363

test/CMakeLists.txt

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -147,25 +147,12 @@ if(PYTHONINTERP_FOUND)
147147
set(VARIANT_SDK "${SWIFT_SDK_${SDK}_PATH}")
148148

149149
# A directory where to put the xUnit-style XML test results.
150-
set(swift_test_results_dir
150+
set(SWIFT_TEST_RESULTS_DIR
151151
"${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/swift-test-results/${VARIANT_TRIPLE}")
152152

153-
if(SWIFT_ANALYZE_CODE_COVERAGE STREQUAL "MERGED")
154-
set(command_profdata_merge_start
155-
COMMAND "${PYTHON_EXECUTABLE}" "${profdata_merge_worker}"
156-
-l "${swift_test_results_dir}/profdata_merge.log"
157-
start
158-
-o "${swift_test_results_dir}")
159-
set(command_profdata_merge_stop
160-
COMMAND "${PYTHON_EXECUTABLE}" "${profdata_merge_worker}" stop)
161-
else()
162-
set(command_profdata_merge_start)
163-
set(command_profdata_merge_stop)
164-
endif()
165-
166153
set(command_clean_test_results_dir
167-
COMMAND "${CMAKE_COMMAND}" -E remove_directory "${swift_test_results_dir}"
168-
COMMAND "${CMAKE_COMMAND}" -E make_directory "${swift_test_results_dir}")
154+
COMMAND "${CMAKE_COMMAND}" -E remove_directory "${SWIFT_TEST_RESULTS_DIR}"
155+
COMMAND "${CMAKE_COMMAND}" -E make_directory "${SWIFT_TEST_RESULTS_DIR}")
169156

170157
set(test_bin_dir "${CMAKE_CURRENT_BINARY_DIR}${VARIANT_SUFFIX}")
171158
set(validation_test_bin_dir
@@ -246,7 +233,7 @@ if(PYTHONINTERP_FOUND)
246233
"--param" "test_sdk_overlay_dir=${SWIFTLIB_DIR}/${SWIFT_SDK_${SDK}_LIB_SUBDIR}")
247234
endif()
248235

249-
list(APPEND LIT_ARGS "--xunit-xml-output=${swift_test_results_dir}/lit-tests.xml")
236+
list(APPEND LIT_ARGS "--xunit-xml-output=${SWIFT_TEST_RESULTS_DIR}/lit-tests.xml")
250237

251238
foreach(test_subset ${TEST_SUBSETS})
252239
set(directories)
@@ -280,14 +267,12 @@ if(PYTHONINTERP_FOUND)
280267
${command_upload_stdlib}
281268
${command_upload_swift_reflection_test}
282269
${command_clean_test_results_dir}
283-
${command_profdata_merge_start}
284270
COMMAND
285271
${PYTHON_EXECUTABLE} "${LIT}"
286272
${LIT_ARGS}
287273
"--param" "swift_test_subset=${test_subset}"
288274
"--param" "swift_test_mode=${test_mode}"
289275
${directories}
290-
${command_profdata_merge_stop}
291276
DEPENDS ${dependencies}
292277
COMMENT "Running ${test_subset} Swift tests for ${VARIANT_TRIPLE}"
293278
${cmake_3_2_USES_TERMINAL})

test/Unit/lit.site.cfg.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ config.llvm_libs_dir = "@LLVM_LIBS_DIR@"
77
config.build_mode = lit_config.params.get('build_mode', "@SWIFT_BUILD_MODE@")
88
config.swift_obj_root = "@SWIFT_BINARY_DIR@"
99
config.target_triple = "@TARGET_TRIPLE@"
10+
config.swift_test_results_dir = \
11+
lit_config.params.get("swift_test_results_dir", "@SWIFT_TEST_RESULTS_DIR@")
1012

1113
config.coverage_mode = "@SWIFT_ANALYZE_CODE_COVERAGE@"
1214

test/lit.cfg

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,6 @@ class SwiftTest(lit.formats.ShTest, object):
141141
self.coverage_mode = coverage_mode
142142
self.skipped_tests = set()
143143

144-
def profdir_for_test(self, test):
145-
_, tmp_base = lit.TestRunner.getTempPaths(test)
146-
return tmp_base + ".profdir"
147-
148144
def before_test(self, test, litConfig):
149145
if self.coverage_mode:
150146
# FIXME: The compiler crashers run so fast they fill up the
@@ -153,24 +149,23 @@ class SwiftTest(lit.formats.ShTest, object):
153149
test.config.environment["LLVM_PROFILE_FILE"] = os.devnull
154150
self.skipped_tests.add(test.getSourcePath())
155151
return
156-
profdir = self.profdir_for_test(test)
157-
if not os.path.exists(profdir):
158-
os.makedirs(profdir)
159152

160-
test.config.environment["LLVM_PROFILE_FILE"] = \
161-
os.path.join(profdir, "swift-%p.profraw")
153+
_, tmp_base = lit.TestRunner.getTempPaths(test)
154+
if self.coverage_mode == "NOT_MERGED":
155+
profdir = tmp_base + '.profdir'
156+
if not os.path.exists(profdir):
157+
os.makedirs(profdir)
158+
159+
test.config.environment["LLVM_PROFILE_FILE"] = \
160+
os.path.join(profdir, "swift-%p.profraw")
161+
else:
162+
test.config.environment["LLVM_PROFILE_FILE"] = \
163+
os.path.join(config.swift_test_results_dir,
164+
"swift-%4m.profraw")
162165

163166
def after_test(self, test, litConfig, result):
164167
if test.getSourcePath() in self.skipped_tests:
165168
self.skipped_tests.remove(test.getSourcePath())
166-
return result
167-
if self.coverage_mode == "MERGED":
168-
profdir = self.profdir_for_test(test)
169-
files = glob.glob(os.path.join(profdir, "swift-*.profraw"))
170-
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
171-
sock.connect(('localhost', 12400))
172-
sock.send("\n".join(files))
173-
sock.close()
174169
return result
175170

176171

@@ -330,6 +325,7 @@ clang_module_cache_path = tempfile.mkdtemp(prefix="swift-testsuite-clang-module-
330325
mcp_opt = "-module-cache-path %r" % clang_module_cache_path
331326
clang_mcp_opt = "-fmodules-cache-path=%r" % clang_module_cache_path
332327
lit_config.note("Using Clang module cache: " + clang_module_cache_path)
328+
lit_config.note("Using test results dir: " + config.swift_test_results_dir)
333329

334330
completion_cache_path = tempfile.mkdtemp(prefix="swift-testsuite-completion-cache")
335331
ccp_opt = "-completion-cache-path %r" % completion_cache_path

test/lit.site.cfg.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ config.variant_triple = "@VARIANT_TRIPLE@"
2929
config.variant_sdk = "@VARIANT_SDK@"
3030
config.variant_suffix = "@VARIANT_SUFFIX@"
3131
config.swiftlib_dir = "@LIT_SWIFTLIB_DIR@"
32+
config.swift_test_results_dir = \
33+
lit_config.params.get("swift_test_results_dir", "@SWIFT_TEST_RESULTS_DIR@")
3234
config.darwin_xcrun_toolchain = "@SWIFT_DARWIN_XCRUN_TOOLCHAIN@"
3335
config.android_ndk_path = "@SWIFT_ANDROID_NDK_PATH@"
3436
config.android_ndk_gcc_version = "@SWIFT_ANDROID_NDK_GCC_VERSION@"

tools/SourceKit/CMakeLists.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,10 @@ macro(add_sourcekit_executable name)
249249
set_target_properties(${name}
250250
PROPERTIES
251251
LINK_FLAGS "-Wl,-exported_symbol,_main")
252-
253-
if(SWIFT_ANALYZE_CODE_COVERAGE)
254-
set_property(TARGET "${name}" APPEND_STRING PROPERTY
255-
LINK_FLAGS " -fprofile-instr-generate -fcoverage-mapping")
256-
endif()
252+
endif()
253+
if(SWIFT_ANALYZE_CODE_COVERAGE)
254+
set_property(TARGET "${name}" APPEND_STRING PROPERTY
255+
LINK_FLAGS " -fprofile-instr-generate -fcoverage-mapping")
257256
endif()
258257
endif()
259258
add_sourcekit_default_compiler_flags("${name}")

tools/SourceKit/tools/complete-test/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
1414
set_target_properties(complete-test
1515
PROPERTIES
1616
LINK_FLAGS "-Wl,-rpath -Wl,@executable_path/../lib")
17+
endif()
1718

18-
if(SWIFT_ANALYZE_CODE_COVERAGE)
19-
set_property(TARGET complete-test APPEND_STRING PROPERTY
20-
LINK_FLAGS " -fprofile-instr-generate -fcoverage-mapping")
21-
endif()
19+
if(SWIFT_ANALYZE_CODE_COVERAGE)
20+
set_property(TARGET complete-test APPEND_STRING PROPERTY
21+
LINK_FLAGS " -fprofile-instr-generate -fcoverage-mapping")
2222
endif()
2323

2424
swift_install_in_component(tools

tools/SourceKit/tools/sourcekitd-repl/CMakeLists.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ if(HAVE_UNICODE_LIBEDIT)
1818
set_target_properties(sourcekitd-repl
1919
PROPERTIES
2020
LINK_FLAGS "-Wl,-rpath -Wl,@executable_path/../lib")
21-
22-
if(SWIFT_ANALYZE_CODE_COVERAGE)
23-
set_property(TARGET sourcekitd-repl APPEND_STRING PROPERTY
24-
LINK_FLAGS " -fprofile-instr-generate -fcoverage-mapping")
25-
endif()
21+
endif()
22+
if(SWIFT_ANALYZE_CODE_COVERAGE)
23+
set_property(TARGET sourcekitd-repl APPEND_STRING PROPERTY
24+
LINK_FLAGS " -fprofile-instr-generate -fcoverage-mapping")
2625
endif()
2726

2827
swift_install_in_component(tools

tools/SourceKit/tools/sourcekitd-test/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
2525
set_target_properties(sourcekitd-test
2626
PROPERTIES
2727
LINK_FLAGS "-Wl,-rpath -Wl,@executable_path/../lib")
28+
endif()
2829

29-
if(SWIFT_ANALYZE_CODE_COVERAGE)
30-
set_property(TARGET sourcekitd-test APPEND_STRING PROPERTY
31-
LINK_FLAGS " -fprofile-instr-generate -fcoverage-mapping")
32-
endif()
30+
if(SWIFT_ANALYZE_CODE_COVERAGE)
31+
set_property(TARGET sourcekitd-test APPEND_STRING PROPERTY
32+
LINK_FLAGS " -fprofile-instr-generate -fcoverage-mapping")
3333
endif()
3434

3535
swift_install_in_component(tools

0 commit comments

Comments
 (0)