Skip to content

Commit 6bd6416

Browse files
mantogninivmaksimo
authored andcommitted
Make spirv-link usable in tests
This instructs CMake where to find spirv-link (i.e. within the SPIRV-Tools) and makes it available to lit tests. This patch also adds a test that is currently failing because global variables without initializer aren't read properly after linking.
1 parent cbe0886 commit 6bd6416

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

llvm-spirv/test/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ if(SPIRV_TOOLS_FOUND)
1515
set(SPIRV_TOOLS_SPIRV_AS_FOUND True)
1616
endif()
1717

18+
find_program(SPIRV_TOOLS_SPIRV_LINK NAMES spirv-link PATHS ${SPIRV_TOOLS_PREFIX}/bin)
19+
if(SPIRV_TOOLS_SPIRV_LINK)
20+
set(SPIRV_TOOLS_SPIRV_LINK_FOUND True)
21+
endif()
22+
1823
find_program(SPIRV_TOOLS_SPIRV_VAL NAMES spirv-val PATHS ${SPIRV_TOOLS_PREFIX}/bin)
1924
if(SPIRV_TOOLS_SPIRV_VAL)
2025
set(SPIRV_TOOLS_SPIRV_VAL_FOUND True)
@@ -28,6 +33,11 @@ if(NOT SPIRV_TOOLS_SPIRV_AS)
2833
set(SPIRV_TOOLS_SPIRV_AS_FOUND False)
2934
endif()
3035

36+
if(NOT SPIRV_TOOLS_SPIRV_LINK)
37+
message(WARNING "spirv-link not found! SPIR-V test involving the linker will not be run.")
38+
set(SPIRV_TOOLS_SPIRV_LINK_FOUND False)
39+
endif()
40+
3141
if(NOT SPIRV_TOOLS_SPIRV_VAL)
3242
message(WARNING "spirv-val not found! SPIR-V generated for test suite will not be validated.")
3343
set(SPIRV_TOOLS_SPIRV_VAL_FOUND False)

llvm-spirv/test/lit.cfg.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@
6060
config.available_features.add('spirv-as')
6161
using_spirv_tools = True
6262

63+
if config.spirv_tools_have_spirv_link:
64+
llvm_config.add_tool_substitutions(['spirv-link'], [config.spirv_tools_bin_dir])
65+
config.available_features.add('spirv-link')
66+
using_spirv_tools = True
67+
6368
if config.spirv_tools_have_spirv_val:
6469
llvm_config.add_tool_substitutions(['spirv-val'], [config.spirv_tools_bin_dir])
6570
using_spirv_tools = True

llvm-spirv/test/lit.site.cfg.py.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ config.host_arch = "@HOST_ARCH@"
1616
config.python_executable = "@PYTHON_EXECUTABLE@"
1717
config.test_run_dir = "@CMAKE_CURRENT_BINARY_DIR@"
1818
config.spirv_tools_have_spirv_as = @SPIRV_TOOLS_SPIRV_AS_FOUND@
19+
config.spirv_tools_have_spirv_link = @SPIRV_TOOLS_SPIRV_LINK_FOUND@
1920
config.spirv_tools_have_spirv_val = @SPIRV_TOOLS_SPIRV_VAL_FOUND@
2021
config.spirv_tools_bin_dir = "@SPIRV_TOOLS_BINDIR@"
2122
config.spirv_tools_lib_dir = "@SPIRV_TOOLS_LIBDIR@"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
; REQUIRES: spirv-link
2+
;
3+
; FIXME This currently crashes when translating back from SPIR-V.
4+
; XFAIL: *
5+
;
6+
; RUN: llvm-as %s -o %t.bc
7+
; RUN: llvm-spirv %t.bc -o %t.spv
8+
; RUN: spirv-val %t.spv
9+
; RUN: spirv-link %t.spv -o %t.linked.spv
10+
; RUN: llvm-spirv -r %t.linked.spv -o %t.rev.bc
11+
; RUN: llvm-dis %t.rev.bc -o - | FileCheck %s
12+
;
13+
; This checks that SPIR-V programs with global variables are still consumable
14+
; after spirv-link.
15+
16+
target triple = "spir-unknown-unknown"
17+
18+
@foo = common dso_local local_unnamed_addr addrspace(1) global i32 0, align 4
19+
; CHECK: @foo = internal addrspace(1) global i32 0, align 4
20+
21+
define dso_local spir_kernel void @bar() local_unnamed_addr {
22+
entry:
23+
store i32 42, i32 addrspace(1)* @foo, align 4
24+
ret void
25+
}

0 commit comments

Comments
 (0)