Skip to content

Commit 5f01d97

Browse files
authored
[SingleSource] Avoid race condition in symlink creation for forced opt vectorizer tests (#381)
Commit 6ac4455 added variants of the vectorizer tests, built from the same source file. But each variant uses the same reference output (e.g. `early-exit.reference_output`). A symlink to this file is made in the build directory, and for parallel builds we can get an error like: ``` CMake Error: failed to create symbolic link '/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-test-suite/build.rva23/SingleSource/UnitTests/Vectorizer/early-exit.reference_output': File exists ``` Essentially the same problem was fixed before in-tree in a086e60. This patch implements a fix along the same lines. llvm_singlesource now accepts a `DEST_SUFFIX` which is plumbed through so that a unique symlink is created per test variant. A script like the following will reproduce the issue: ``` targets=" SingleSource/UnitTests/Vectorizer/early-exit SingleSource/UnitTests/Vectorizer/tf-early-exit SingleSource/UnitTests/Vectorizer/tfactivelanemask-early-exit SingleSource/UnitTests/Vectorizer/ftic-early-exit SingleSource/UnitTests/Vectorizer/tf-ftic-early-exit SingleSource/UnitTests/Vectorizer/tfactivelanemask-ftic-early-exit " for i in $(seq 1 50); do echo "attempt $i" rm -f SingleSource/UnitTests/Vectorizer/early-exit.reference_output ninja -t clean $targets >/dev/null || exit 1 if ! ninja -j32 $targets; then echo "reproduced: parallel build failed; look above for the create_symlink File exists error" exit 0 fi done echo "did not reproduce" exit 1 ``` I made use of an LLM (GPT 5.4) to debug the failure, find an in-tree example of the same issue being worked around, and to apply that pattern here.
1 parent 6ac4455 commit 5f01d97

2 files changed

Lines changed: 26 additions & 11 deletions

File tree

SingleSource/UnitTests/Vectorizer/CMakeLists.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
set(CMAKE_CXX_STANDARD 17)
22
llvm_singlesource()
33

4+
function(llvm_vectorizer_variant prefix)
5+
llvm_singlesource(PREFIX "${prefix}-" DEST_SUFFIX "-${prefix}")
6+
endfunction()
7+
48
# The VPlan-native path is specific to llvm.
59
if ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
610
add_subdirectory(VPlanNativePath)
@@ -12,22 +16,22 @@ if ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
1216
"-mllvm" "-prefer-predicate-over-epilogue=predicate-dont-vectorize"
1317
"-mllvm" "-force-tail-folding-style=data"
1418
)
15-
llvm_singlesource(PREFIX "tfactivelanemask-")
19+
llvm_vectorizer_variant("tfactivelanemask")
1620

1721
# Add targets for all tests with forced tail folding using data without lane mask.
1822
set(CXXFLAGS ${BASE_CXXFLAGS})
1923
list(APPEND CXXFLAGS
2024
"-mllvm" "-prefer-predicate-over-epilogue=predicate-dont-vectorize"
2125
"-mllvm" "-force-tail-folding-style=data-without-lane-mask"
2226
)
23-
llvm_singlesource(PREFIX "tf-")
27+
llvm_vectorizer_variant("tf")
2428

2529
# Add targets with instruction cost forced to 1.
2630
set(CXXFLAGS ${BASE_CXXFLAGS})
2731
list(APPEND CXXFLAGS
2832
"-mllvm" "-force-target-instruction-cost=1"
2933
)
30-
llvm_singlesource(PREFIX "ftic-")
34+
llvm_vectorizer_variant("ftic")
3135

3236
# Add targets with instruction cost forced to 1 and forced tail-folding.
3337
set(CXXFLAGS ${BASE_CXXFLAGS})
@@ -36,7 +40,7 @@ if ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
3640
"-mllvm" "-prefer-predicate-over-epilogue=predicate-dont-vectorize"
3741
"-mllvm" "-force-tail-folding-style=data"
3842
)
39-
llvm_singlesource(PREFIX "tfactivelanemask-ftic-")
43+
llvm_vectorizer_variant("tfactivelanemask-ftic")
4044

4145
# Add targets with instruction cost forced to 1 and forced tail-folding without lane mask.
4246
set(CXXFLAGS ${BASE_CXXFLAGS})
@@ -45,7 +49,7 @@ if ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
4549
"-mllvm" "-prefer-predicate-over-epilogue=predicate-dont-vectorize"
4650
"-mllvm" "-force-tail-folding-style=data-without-lane-mask"
4751
)
48-
llvm_singlesource(PREFIX "tf-ftic-")
52+
llvm_vectorizer_variant("tf-ftic")
4953

5054
set(CXXFLAGS ${BASE_CXXFLAGS})
5155
endif()

cmake/modules/SingleMultiSource.cmake

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ include(TestSuite)
2929
# Configure the current directory as a SingleSource subdirectory - i.e. every
3030
# C/C++/Fortran file is treated as its own test.
3131
function(llvm_singlesource)
32-
cmake_parse_arguments(_LSARG "" "PREFIX" "" ${ARGN})
32+
cmake_parse_arguments(_LSARG "" "DEST_SUFFIX;PREFIX" "" ${ARGN})
3333
if(DEFINED Source)
3434
set(sources ${Source})
3535
else()
@@ -42,7 +42,11 @@ function(llvm_singlesource)
4242
set(_target ${_LSARG_PREFIX}${name})
4343
llvm_test_executable_no_test(${_target} ${source})
4444
set_property(TARGET ${_target} PROPERTY TEST_NAME ${name})
45-
llvm_test_traditional(${_target})
45+
set(DEST_SUFFIX_ARGS)
46+
if(_LSARG_DEST_SUFFIX)
47+
list(APPEND DEST_SUFFIX_ARGS DEST_SUFFIX ${_LSARG_DEST_SUFFIX})
48+
endif()
49+
llvm_test_traditional(${_target} ${DEST_SUFFIX_ARGS})
4650
llvm_add_test_for_target(${_target})
4751
endforeach()
4852
endfunction()
@@ -79,15 +83,21 @@ endmacro()
7983
# HASH_PROGRAM_OUTPUT, etc.
8084
# Create llvm_test_run() and llvm_test_verify() invocation for that.
8185
function(llvm_test_traditional target)
86+
cmake_parse_arguments(_LTTARGS "" "DEST_SUFFIX" "" ${ARGN})
8287
get_property(name TARGET ${target} PROPERTY TEST_NAME)
8388
if(NOT name)
8489
set(name ${target})
8590
endif()
91+
set(DEST_SUFFIX_ARGS)
92+
if(_LTTARGS_DEST_SUFFIX)
93+
list(APPEND DEST_SUFFIX_ARGS DEST_SUFFIX ${_LTTARGS_DEST_SUFFIX})
94+
endif()
8695

8796
# Find the reference input
8897
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${name}.reference_input)
89-
list(APPEND RUN_OPTIONS < %S/${name}.reference_input)
90-
llvm_test_data(${target} ${name}.reference_input)
98+
list(APPEND RUN_OPTIONS < %S/${name}.reference_input${_LTTARGS_DEST_SUFFIX})
99+
llvm_test_data(${target} ${DEST_SUFFIX_ARGS}
100+
${name}.reference_input)
91101
endif()
92102

93103
# Always run in the same directory as the executable
@@ -135,8 +145,9 @@ function(llvm_test_traditional target)
135145
if(FP_IGNOREWHITESPACE)
136146
set(DIFFPROG "${DIFFPROG} -i")
137147
endif()
138-
llvm_test_verify(${DIFFPROG} %o %S/${REFERENCE_OUTPUT})
139-
llvm_test_data(${target} ${REFERENCE_OUTPUT})
148+
llvm_test_verify(${DIFFPROG} %o %S/${REFERENCE_OUTPUT}${_LTTARGS_DEST_SUFFIX})
149+
llvm_test_data(${target} ${DEST_SUFFIX_ARGS}
150+
${REFERENCE_OUTPUT})
140151
endif()
141152
set(TESTSCRIPT "${TESTSCRIPT}" PARENT_SCOPE)
142153
endfunction()

0 commit comments

Comments
 (0)