Skip to content

Commit a3384b5

Browse files
sarnexIcohedron
authored andcommitted
[SPIR-V] Add SPIR-V Linker (llvm#126319)
I want to use `spirv-link` from `SPIR-V-Tools` in a test, so let's build it if `LLVM_INCLUDE_SPIRV_TOOLS_TESTS` is set, as we do with the other tools. Signed-off-by: Sarnie, Nick <[email protected]>
1 parent 37a1156 commit a3384b5

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

llvm/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ if (LLVM_INCLUDE_SPIRV_TOOLS_TESTS)
232232
list(APPEND LLVM_TEST_DEPENDS spirv-dis)
233233
list(APPEND LLVM_TEST_DEPENDS spirv-val)
234234
list(APPEND LLVM_TEST_DEPENDS spirv-as)
235+
list(APPEND LLVM_TEST_DEPENDS spirv-link)
235236
endif()
236237

237238
add_custom_target(llvm-test-depends DEPENDS ${LLVM_TEST_DEPENDS})

llvm/test/CodeGen/SPIRV/lit.local.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ if config.spirv_tools_tests:
1616
config.substitutions.append(("spirv-dis", os.path.join(config.llvm_tools_dir, "spirv-dis")))
1717
config.substitutions.append(("spirv-val", os.path.join(config.llvm_tools_dir, "spirv-val")))
1818
config.substitutions.append(("spirv-as", os.path.join(config.llvm_tools_dir, "spirv-as")))
19+
config.substitutions.append(("spirv-link", os.path.join(config.llvm_tools_dir, "spirv-link")))

llvm/tools/spirv-tools/CMakeLists.txt

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ if (NOT "SPIRV" IN_LIST LLVM_TARGETS_TO_BUILD)
99
message(FATAL_ERROR "Building SPIRV-Tools tests is unsupported without the SPIR-V target")
1010
endif ()
1111

12-
# SPIRV_DIS and SPIRV_VAL variables can be used to provide paths to existing
13-
# spirv-dis and spirv-val binaries, respectively. Otherwise, build them from
12+
# SPIRV_DIS, SPIRV_VAL, SPIRV_AS and SPIRV_LINK variables can be used to provide paths to existing
13+
# spirv-dis, spirv-val, spirv-as, and spirv-link binaries, respectively. Otherwise, build them from
1414
# SPIRV-Tools source.
15-
if (NOT SPIRV_DIS OR NOT SPIRV_VAL OR NOT SPIRV_AS)
15+
if (NOT SPIRV_DIS OR NOT SPIRV_VAL OR NOT SPIRV_AS OR NOT SPIRV_LINK)
1616
include(ExternalProject)
1717

1818
set(BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/SPIRVTools-bin)
@@ -21,8 +21,8 @@ if (NOT SPIRV_DIS OR NOT SPIRV_VAL OR NOT SPIRV_AS)
2121
GIT_REPOSITORY https://github.com/KhronosGroup/SPIRV-Tools.git
2222
GIT_TAG main
2323
BINARY_DIR ${BINARY_DIR}
24-
BUILD_COMMAND ${CMAKE_COMMAND} --build ${BINARY_DIR} --target spirv-dis spirv-val spirv-as
25-
BUILD_BYPRODUCTS ${BINARY_DIR}/tools/spirv-dis ${BINARY_DIR}/tools/spirv-val ${BINARY_DIR}/tools/spirv-as
24+
BUILD_COMMAND ${CMAKE_COMMAND} --build ${BINARY_DIR} --target spirv-dis spirv-val spirv-as spirv-link
25+
BUILD_BYPRODUCTS ${BINARY_DIR}/tools/spirv-dis ${BINARY_DIR}/tools/spirv-val ${BINARY_DIR}/tools/spirv-as ${BINARY_DIR}/tools/spirv-link
2626
DOWNLOAD_COMMAND git clone https://github.com/KhronosGroup/SPIRV-Tools.git SPIRVTools &&
2727
cd SPIRVTools &&
2828
${Python3_EXECUTABLE} utils/git-sync-deps
@@ -43,7 +43,7 @@ else ()
4343
set(LLVM_LINK_OR_COPY copy)
4444
endif ()
4545

46-
# Link the provided or just built spirv-dis and spirv-val binaries.
46+
# Link the provided or just built binaries.
4747
if (SPIRV_DIS)
4848
add_custom_target(spirv-dis
4949
COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} "${SPIRV_DIS}" "${LLVM_RUNTIME_OUTPUT_INTDIR}/spirv-dis")
@@ -73,3 +73,13 @@ else ()
7373
DEPENDS SPIRVTools
7474
)
7575
endif ()
76+
77+
if (SPIRV_LINK)
78+
add_custom_target(spirv-link
79+
COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} "${SPIRV_LINK}" "${LLVM_RUNTIME_OUTPUT_INTDIR}/spirv-link")
80+
else ()
81+
add_custom_target(spirv-link
82+
COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} "${BINARY_DIR}/tools/spirv-link${CMAKE_EXECUTABLE_SUFFIX}" "${LLVM_RUNTIME_OUTPUT_INTDIR}/spirv-link${CMAKE_EXECUTABLE_SUFFIX}"
83+
DEPENDS SPIRVTools
84+
)
85+
endif ()

0 commit comments

Comments
 (0)