Skip to content

Commit ac706af

Browse files
[sycl-post-link] Adds property listing exported functions (#4626)
These changes make sycl-post-link generate a list of exported functions as properties for each generated module. This is enabled through the -emit-exported-symbols option. The properties follow the naming proposed in the "Dynamic linking of device code" documentation (`sycl/doc/SharedLibraries.md`). Signed-off-by: Steffen Larsen <[email protected]>
1 parent 4bb2d9a commit ac706af

File tree

7 files changed

+169
-31
lines changed

7 files changed

+169
-31
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8938,6 +8938,7 @@ void SYCLPostLink::ConstructJob(Compilation &C, const JobAction &JA,
89388938
// Symbol file and specialization constant info generation is mandatory -
89398939
// add options unconditionally
89408940
addArgs(CmdArgs, TCArgs, {"-symbols"});
8941+
addArgs(CmdArgs, TCArgs, {"-emit-exported-symbols"});
89418942
addArgs(CmdArgs, TCArgs, {"-split-esimd"});
89428943
addArgs(CmdArgs, TCArgs, {"-lower-esimd"});
89438944
}

clang/test/Driver/sycl-device-lib.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
// RUN: | FileCheck %s -check-prefix=SYCL_LLVM_LINK_NO_DEVICE_LIB
128128
// SYCL_LLVM_LINK_NO_DEVICE_LIB: clang{{.*}} "-cc1" {{.*}} "-fsycl-is-device"
129129
// SYCL_LLVM_LINK_NO_DEVICE_LIB-NOT: llvm-link{{.*}} "-only-needed"
130-
// SYCL_LLVM_LINK_NO_DEVICE_LIB: sycl-post-link{{.*}} "-symbols" "-split-esimd" "-lower-esimd" "-O2" "-spec-const=rt" "-o" "{{.*}}.table" "{{.*}}.bc"
130+
// SYCL_LLVM_LINK_NO_DEVICE_LIB: sycl-post-link{{.*}} "-symbols" "-emit-exported-symbols" "-split-esimd" "-lower-esimd" "-O2" "-spec-const=rt" "-o" "{{.*}}.table" "{{.*}}.bc"
131131

132132
/// ###########################################################################
133133
/// test llvm-link behavior for special user input whose filename resembles SYCL device library

llvm/include/llvm/Support/PropertySetIO.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ class PropertySetRegistry {
191191
static constexpr char SYCL_PROGRAM_METADATA[] = "SYCL/program metadata";
192192
static constexpr char SYCL_MISC_PROP[] = "SYCL/misc properties";
193193
static constexpr char SYCL_ASSERT_USED[] = "SYCL/assert used";
194+
static constexpr char SYCL_EXPORTED_SYMBOLS[] = "SYCL/exported symbols";
194195

195196
// Function for bulk addition of an entire property set under given category
196197
// (property set name).

llvm/lib/Support/PropertySetIO.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ constexpr char PropertySetRegistry::SYCL_KERNEL_PARAM_OPT_INFO[];
200200
constexpr char PropertySetRegistry::SYCL_PROGRAM_METADATA[];
201201
constexpr char PropertySetRegistry::SYCL_MISC_PROP[];
202202
constexpr char PropertySetRegistry::SYCL_ASSERT_USED[];
203+
constexpr char PropertySetRegistry::SYCL_EXPORTED_SYMBOLS[];
203204

204205
} // namespace util
205206
} // namespace llvm
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
; This test checks that the post-link tool generates list of exported symbols.
2+
;
3+
; Global scope
4+
; RUN: sycl-post-link -symbols -emit-exported-symbols -S %s -o %t.global.files.table
5+
; RUN: FileCheck %s -input-file=%t.global.files_0.prop --implicit-check-not="NotExported" --check-prefix=CHECK-GLOBAL-PROP
6+
;
7+
; Per-module split
8+
; RUN: sycl-post-link -symbols -split=source -emit-exported-symbols -S %s -o %t.per_module.files.table
9+
; RUN: FileCheck %s -input-file=%t.per_module.files_0.prop -implicit-check-not="NotExported" --check-prefix=CHECK-PERMODULE-0-PROP
10+
; RUN: FileCheck %s -input-file=%t.per_module.files_1.prop -implicit-check-not="NotExported" --check-prefix=CHECK-PERMODULE-1-PROP
11+
; RUN: FileCheck %s -input-file=%t.per_module.files_2.prop -implicit-check-not="NotExported" --check-prefix=CHECK-KERNELONLY-PROP
12+
;
13+
; Per-kernel split
14+
; RUN: sycl-post-link -symbols -split=kernel -emit-exported-symbols -S %s -o %t.per_kernel.files.table
15+
; RUN: FileCheck %s -input-file=%t.per_kernel.files_0.prop --implicit-check-not="NotExported" --check-prefix=CHECK-PERKERNEL-0-PROP
16+
; RUN: FileCheck %s -input-file=%t.per_kernel.files_1.prop --implicit-check-not="NotExported" --check-prefix=CHECK-PERKERNEL-1-PROP
17+
; RUN: FileCheck %s -input-file=%t.per_kernel.files_2.prop --implicit-check-not="NotExported" --check-prefix=CHECK-PERKERNEL-2-PROP
18+
; RUN: FileCheck %s -input-file=%t.per_kernel.files_3.prop --implicit-check-not="NotExported" --check-prefix=CHECK-KERNELONLY-PROP
19+
; RUN: FileCheck %s -input-file=%t.per_kernel.files_4.prop --implicit-check-not="NotExported" --check-prefix=CHECK-KERNELONLY-PROP
20+
21+
target triple = "spir64-unknown-unknown"
22+
23+
define dso_local spir_kernel void @NotExportedSpirKernel1(float %arg1) #0 {
24+
entry:
25+
ret void
26+
}
27+
28+
define dso_local spir_kernel void @NotExportedSpirKernel2(float %arg1) #2 {
29+
entry:
30+
ret void
31+
}
32+
33+
define dso_local spir_func void @ExportedSpirFunc1(float %arg1) #0 {
34+
entry:
35+
ret void
36+
}
37+
38+
define dso_local spir_func void @ExportedSpirFunc2(i32 %arg1, i32 %arg2) #1 {
39+
entry:
40+
ret void
41+
}
42+
43+
define dso_local spir_func void @ExportedSpirFunc3(float %arg1) #0 {
44+
entry:
45+
ret void
46+
}
47+
48+
define dso_local spir_func void @NotExportedSpirFunc1(float %arg1) {
49+
entry:
50+
ret void
51+
}
52+
53+
attributes #0 = { "sycl-module-id"="a.cpp" }
54+
attributes #1 = { "sycl-module-id"="b.cpp" }
55+
attributes #2 = { "sycl-module-id"="c.cpp" }
56+
57+
; Global scope
58+
; CHECK-GLOBAL-PROP: [SYCL/exported symbols]
59+
; CHECK-GLOBAL-PROP-NEXT: ExportedSpirFunc1
60+
; CHECK-GLOBAL-PROP-NEXT: ExportedSpirFunc2
61+
; CHECK-GLOBAL-PROP-NEXT: ExportedSpirFunc3
62+
63+
; Per-module split
64+
; CHECK-PERMODULE-0-PROP: [SYCL/exported symbols]
65+
; CHECK-PERMODULE-0-PROP-NEXT: ExportedSpirFunc1
66+
; CHECK-PERMODULE-0-PROP-NEXT: ExportedSpirFunc3
67+
; CHECK-PERMODULE-0-PROP-NOT: ExportedSpirFunc2
68+
69+
; CHECK-PERMODULE-1-PROP: [SYCL/exported symbols]
70+
; CHECK-PERMODULE-1-PROP-NEXT: ExportedSpirFunc2
71+
; CHECK-PERMODULE-1-PROP-NOT: ExportedSpirFunc1
72+
; CHECK-PERMODULE-1-PROP-NOT: ExportedSpirFunc3
73+
74+
; Per-kernel split
75+
; CHECK-PERKERNEL-0-PROP: [SYCL/exported symbols]
76+
; CHECK-PERKERNEL-0-PROP-NEXT: ExportedSpirFunc1
77+
; CHECK-PERKERNEL-0-PROP-NOT: ExportedSpirFunc2
78+
; CHECK-PERKERNEL-0-PROP-NOT: ExportedSpirFunc3
79+
80+
; CHECK-PERKERNEL-1-PROP: [SYCL/exported symbols]
81+
; CHECK-PERKERNEL-1-PROP-NEXT: ExportedSpirFunc2
82+
; CHECK-PERKERNEL-1-PROP-NOT: ExportedSpirFunc1
83+
; CHECK-PERKERNEL-1-PROP-NOT: ExportedSpirFunc3
84+
85+
; CHECK-PERKERNEL-2-PROP: [SYCL/exported symbols]
86+
; CHECK-PERKERNEL-2-PROP-NEXT: ExportedSpirFunc3
87+
; CHECK-PERKERNEL-2-PROP-NOT: ExportedSpirFunc1
88+
; CHECK-PERKERNEL-2-PROP-NOT: ExportedSpirFunc2
89+
90+
; Kernel-only generated modules should have no exported Symbols
91+
; CHECK-KERNELONLY-PROP-NOT: [SYCL/exported symbols]
92+
; CHECK-KERNELONLY-PROP-NOT: ExportedSpirFunc3
93+
; CHECK-KERNELONLY-PROP-NOT: ExportedSpirFunc1
94+
; CHECK-KERNELONLY-PROP-NOT: ExportedSpirFunc2

0 commit comments

Comments
 (0)