Skip to content

Commit 47a9411

Browse files
author
Andrew Savonichev
authored
[SYCL] Split build options into separate compile and link options (#1087)
Only the options described in s5.8.5 "Linker Options" of OpenCL 2.0 specification are supported by clLinkProgram. Since SYCL_PROGRAM_BUILD_OPTIONS environment variable and `pi_device_binary_struct.BuildOptions' may contain compile options (such as "-g"), we should not use it. Same applies for clCompileProgram and *link* options. This patch changes clang-offload-wrapper and SYCL runtime to maintain two distinct lists of options: one for compile (to use with clCompileProgram), and one for link (to use with clLinkProgram). It also replaces SYCL_PROGRAM_BUILD_OPTIONS environment variable with two separate variables: SYCL_PROGRAM_COMPILE_OPTIONS and SYCL_PROGRAM_LINK_OPTIONS. Signed-off-by: Andrew Savonichev <[email protected]>
1 parent c855520 commit 47a9411

File tree

7 files changed

+247
-116
lines changed

7 files changed

+247
-116
lines changed

clang/test/Driver/clang-offload-wrapper.c

Lines changed: 69 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,64 @@
55
//
66

77
// RUN: clang-offload-wrapper --help | FileCheck %s --check-prefix CHECK-HELP
8-
// CHECK-HELP: {{.*}}OVERVIEW: A tool to create a wrapper bitcode for offload target binaries.
9-
// CHECK-HELP: {{.*}}Takes offload target binaries and optional manifest files as input
10-
// CHECK-HELP: {{.*}}and produces bitcode file containing target binaries packaged as data
11-
// CHECK-HELP: {{.*}}and initialization code which registers target binaries in the offload
12-
// CHECK-HELP: {{.*}}runtime. Manifest files format and contents are not restricted and are
13-
// CHECK-HELP: {{.*}}a subject of agreement between the device compiler and the native
14-
// CHECK-HELP: {{.*}}runtime for that device. When present, manifest file name should
15-
// CHECK-HELP: {{.*}}immediately follow the corresponding device image filename on the
16-
// CHECK-HELP: {{.*}}command line. Options annotating a device binary have effect on all
17-
// CHECK-HELP: {{.*}}subsequent input, until redefined. For example:
18-
// CHECK-HELP: {{.*}}$clang-offload-wrapper -host x86_64-pc-linux-gnu \
19-
// CHECK-HELP: {{.*}} -kind=sycl -target=spir64 -format=spirv -build-opts=-g \
20-
// CHECK-HELP: {{.*}} a.spv a_mf.txt \
21-
// CHECK-HELP: {{.*}} -target=xxx -format=native -build-opts="" \
22-
// CHECK-HELP: {{.*}} b.bin b_mf.txt \
23-
// CHECK-HELP: {{.*}} -kind=openmp \
24-
// CHECK-HELP: {{.*}} c.bin
25-
// CHECK-HELP: {{.*}}will generate an x86 wrapper object (.bc) enclosing the following
26-
// CHECK-HELP: {{.*}}tuples describing a single device binary each ('-' means 'none')
27-
// CHECK-HELP: {{.*}}offload kind | target | data format | data | manifest | build options:
28-
// CHECK-HELP: {{.*}}----------------------------------------------------------------------
29-
// CHECK-HELP: {{.*}} sycl | spir64 | spirv | a.spv| a_mf.txt | -g
30-
// CHECK-HELP: {{.*}} sycl | xxx | native | b.bin| b_mf.txt | -
31-
// CHECK-HELP: {{.*}} openmp | xxx | native | c.bin| - | -
32-
// CHECK-HELP: {{.*}}USAGE: clang-offload-wrapper [options] <input files>
33-
// CHECK-HELP: {{.*}}OPTIONS:
34-
// CHECK-HELP: {{.*}}clang-offload-wrapper options:
35-
// CHECK-HELP: {{.*}} --build-opts=<string> - build options passed to the offload runtime
36-
// CHECK-HELP: {{.*}} --desc-name=<name> - Specifies offload descriptor symbol name: '.<offload kind>.<name>', and makes it globally visible
37-
// CHECK-HELP: {{.*}} --emit-reg-funcs - Emit [un-]registration functions
38-
// CHECK-HELP: {{.*}} --entries=<filename> - File listing all offload function entries, SYCL offload only
39-
// CHECK-HELP: {{.*}} --format=<value> - device binary image formats:
40-
// CHECK-HELP: {{.*}} =none - not set
41-
// CHECK-HELP: {{.*}} =native - unknown or native
42-
// CHECK-HELP: {{.*}} =spirv - SPIRV binary
43-
// CHECK-HELP: {{.*}} =llvmbc - LLVMIR bitcode
44-
// CHECK-HELP: {{.*}} --host=<triple> - Target triple for the output module
45-
// CHECK-HELP: {{.*}} --kind=<value> - offload kind:
46-
// CHECK-HELP: {{.*}} =unknown - unknown
47-
// CHECK-HELP: {{.*}} =host - host
48-
// CHECK-HELP: {{.*}} =openmp - OpenMP
49-
// CHECK-HELP: {{.*}} =hip - HIP
50-
// CHECK-HELP: {{.*}} =sycl - SYCL
51-
// CHECK-HELP: {{.*}} -o=<filename> - Output filename
52-
// CHECK-HELP: {{.*}} --target=<string> - offload target triple
53-
// CHECK-HELP: {{.*}} -v - verbose output
8+
// CHECK-HELP: A tool to create a wrapper bitcode for offload target binaries.
9+
// CHECK-HELP: Takes offload target binaries and optional manifest files as input
10+
// CHECK-HELP: and produces bitcode file containing target binaries packaged as data
11+
// CHECK-HELP: and initialization code which registers target binaries in the offload
12+
// CHECK-HELP: runtime. Manifest files format and contents are not restricted and are
13+
// CHECK-HELP: a subject of agreement between the device compiler and the native
14+
// CHECK-HELP: runtime for that device. When present, manifest file name should
15+
// CHECK-HELP: immediately follow the corresponding device image filename on the
16+
// CHECK-HELP: command line. Options annotating a device binary have effect on all
17+
// CHECK-HELP: subsequent input, until redefined.
18+
// CHECK-HELP: For example:
19+
// CHECK-HELP: clang-offload-wrapper
20+
// CHECK-HELP: -host x86_64-pc-linux-gnu
21+
// CHECK-HELP: -kind=sycl
22+
// CHECK-HELP: -target=spir64
23+
// CHECK-HELP: -format=spirv
24+
// CHECK-HELP: -compile-opts=-g
25+
// CHECK-HELP: -link-opts=-cl-denorms-are-zero
26+
// CHECK-HELP: a.spv
27+
// CHECK-HELP: a_mf.txt
28+
// CHECK-HELP: -target=xxx
29+
// CHECK-HELP: -format=native
30+
// CHECK-HELP: -compile-opts=""
31+
// CHECK-HELP: -link-opts=""
32+
// CHECK-HELP: b.bin
33+
// CHECK-HELP: b_mf.txt
34+
// CHECK-HELP: -kind=openmp
35+
// CHECK-HELP: c.bin
36+
// CHECK-HELP: This command generates an x86 wrapper object (.bc) enclosing the
37+
// CHECK-HELP: following tuples describing a single device binary each:
38+
// CHECK-HELP: offload kind | target | data format | data | manifest | build options:
39+
// CHECK-HELP: ----------------------------------------------------------------------
40+
// CHECK-HELP: sycl | spir64 | spirv | a.spv| a_mf.txt | -g
41+
// CHECK-HELP: sycl | xxx | native | b.bin| b_mf.txt | -
42+
// CHECK-HELP: openmp | xxx | native | c.bin| n/a | -
43+
// CHECK-HELP: USAGE: clang-offload-wrapper [options] <input files>
44+
// CHECK-HELP: OPTIONS:
45+
// CHECK-HELP: clang-offload-wrapper options:
46+
// CHECK-HELP: --compile-opts=<string> - compile options passed to the offload runtime
47+
// CHECK-HELP: --desc-name=<name> - Specifies offload descriptor symbol name: '.<offload kind>.<name>', and makes it globally visible
48+
// CHECK-HELP: --emit-reg-funcs - Emit [un-]registration functions
49+
// CHECK-HELP: --entries=<filename> - File listing all offload function entries, SYCL offload only
50+
// CHECK-HELP: --format=<value> - device binary image formats:
51+
// CHECK-HELP: =none - not set
52+
// CHECK-HELP: =native - unknown or native
53+
// CHECK-HELP: =spirv - SPIRV binary
54+
// CHECK-HELP: =llvmbc - LLVMIR bitcode
55+
// CHECK-HELP: --host=<triple> - Target triple for the output module
56+
// CHECK-HELP: --kind=<value> - offload kind:
57+
// CHECK-HELP: =unknown - unknown
58+
// CHECK-HELP: =host - host
59+
// CHECK-HELP: =openmp - OpenMP
60+
// CHECK-HELP: =hip - HIP
61+
// CHECK-HELP: =sycl - SYCL
62+
// CHECK-HELP: --link-opts=<string> - link options passed to the offload runtime
63+
// CHECK-HELP: -o=<filename> - Output filename
64+
// CHECK-HELP: --target=<string> - offload target triple
65+
// CHECK-HELP: -v - verbose output
5466

5567
// -------
5668
// Generate files to wrap.
@@ -66,8 +78,10 @@
6678
// RUN: clang-offload-wrapper \
6779
// RUN: -host=x86_64-pc-linux-gnu \
6880
// RUN: -kind=openmp -target=tg2 -format=native %t3.tgt %t1_mf.txt \
69-
// RUN: -kind=sycl -target=tg1 -build-opts=-g -format spirv %t1.tgt \
70-
// RUN: -target=tg2 -build-opts= -format native %t2.tgt \
81+
// RUN: -kind=sycl -target=tg1 -compile-opts=-g -link-opts=-cl-denorms-are-zero \
82+
// RUN: -format spirv %t1.tgt \
83+
// RUN: -target=tg2 -compile-opts= -link-opts= \
84+
// RUN: -format native %t2.tgt \
7185
// RUN: -o %t.wrapper.bc
7286
// RUN: llvm-dis %t.wrapper.bc -o - | FileCheck %s --check-prefix CHECK-IR
7387

@@ -77,7 +91,7 @@
7791
// CHECK-IR-DAG: [[IMAGETY:%.+]] = type { i8*, i8*, [[ENTTY]]*, [[ENTTY]]* }
7892
// CHECK-IR-DAG: [[DESCTY:%.+]] = type { i32, [[IMAGETY]]*, [[ENTTY]]*, [[ENTTY]]* }
7993

80-
// CHECK-IR-DAG: [[SYCL_IMAGETY:%.+]] = type { i16, i8, i8, i8*, i8*, i8*, i8*, i8*, i8*, [[ENTTY]]*, [[ENTTY]]* }
94+
// CHECK-IR-DAG: [[SYCL_IMAGETY:%.+]] = type { i16, i8, i8, i8*, i8*, i8*, i8*, i8*, i8*, i8*, [[ENTTY]]*, [[ENTTY]]* }
8195
// CHECK-IR-DAG: [[SYCL_DESCTY:%.+]] = type { i16, i16, [[SYCL_IMAGETY]]*, [[ENTTY]]*, [[ENTTY]]* }
8296

8397
// CHECK-IR: [[ENTBEGIN:@.+]] = external hidden constant [[ENTTY]]
@@ -92,14 +106,16 @@
92106
// CHECK-IR: [[OMP_DESC:@.+]] = internal constant [[DESCTY]] { i32 1, [[IMAGETY]]* getelementptr inbounds ([1 x [[IMAGETY]]], [1 x [[IMAGETY]]]* [[OMP_IMAGES]], i64 0, i64 0), [[ENTTY]]* [[ENTBEGIN]], [[ENTTY]]* [[ENTEND]] }
93107

94108
// CHECK-IR: [[SYCL_TGT0:@.+]] = internal unnamed_addr constant [4 x i8] c"tg1\00"
95-
// CHECK-IR: [[SYCL_OPTS0:@.+]] = internal unnamed_addr constant [3 x i8] c"-g\00"
109+
// CHECK-IR: [[SYCL_COMPILE_OPTS0:@.+]] = internal unnamed_addr constant [3 x i8] c"-g\00"
110+
// CHECK-IR: [[SYCL_LINK_OPTS0:@.+]] = internal unnamed_addr constant [21 x i8] c"-cl-denorms-are-zero\00"
96111
// CHECK-IR: [[SYCL_BIN0:@.+]] = internal unnamed_addr constant [[SYCL_BIN0TY:\[[0-9]+ x i8\]]] c"Content of device file1{{.+}}"
97112

98113
// CHECK-IR: [[SYCL_TGT1:@.+]] = internal unnamed_addr constant [4 x i8] c"tg2\00"
99-
// CHECK-IR: [[SYCL_OPTS1:@.+]] = internal unnamed_addr constant [1 x i8] zeroinitializer
114+
// CHECK-IR: [[SYCL_COMPILE_OPTS1:@.+]] = internal unnamed_addr constant [1 x i8] zeroinitializer
115+
// CHECK-IR: [[SYCL_LINK_OPTS1:@.+]] = internal unnamed_addr constant [1 x i8] zeroinitializer
100116
// CHECK-IR: [[SYCL_BIN1:@.+]] = internal unnamed_addr constant [[SYCL_BIN1TY:\[[0-9]+ x i8\]]] c"Content of device file2{{.+}}"
101117

102-
// CHECK-IR: [[SYCL_IMAGES:@.+]] = internal unnamed_addr constant [2 x [[SYCL_IMAGETY]]] [{{.+}} { i16 1, i8 4, i8 2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* [[SYCL_TGT0]], i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* [[SYCL_OPTS0]], i64 0, i64 0), i8* null, i8* null, i8* getelementptr inbounds ([[SYCL_BIN0TY]], [[SYCL_BIN0TY]]* [[SYCL_BIN0]], i64 0, i64 0), i8* getelementptr inbounds ([[SYCL_BIN0TY]], [[SYCL_BIN0TY]]* [[SYCL_BIN0]], i64 1, i64 0), [[ENTTY]]* null, [[ENTTY]]* null }, [[SYCL_IMAGETY]] { i16 1, i8 4, i8 1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* [[SYCL_TGT1]], i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* [[SYCL_OPTS1]], i64 0, i64 0), i8* null, i8* null, i8* getelementptr inbounds ([[SYCL_BIN1TY]], [[SYCL_BIN1TY]]* [[SYCL_BIN1]], i64 0, i64 0), i8* getelementptr inbounds ([[SYCL_BIN1TY]], [[SYCL_BIN1TY]]* [[SYCL_BIN1]], i64 1, i64 0), [[ENTTY]]* null, [[ENTTY]]* null }]
118+
// CHECK-IR: [[SYCL_IMAGES:@.+]] = internal unnamed_addr constant [2 x [[SYCL_IMAGETY]]] [{{.+}} { i16 1, i8 4, i8 2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* [[SYCL_TGT0]], i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* [[SYCL_COMPILE_OPTS0]], i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* [[SYCL_LINK_OPTS0]], i64 0, i64 0), i8* null, i8* null, i8* getelementptr inbounds ([[SYCL_BIN0TY]], [[SYCL_BIN0TY]]* [[SYCL_BIN0]], i64 0, i64 0), i8* getelementptr inbounds ([[SYCL_BIN0TY]], [[SYCL_BIN0TY]]* [[SYCL_BIN0]], i64 1, i64 0), [[ENTTY]]* null, [[ENTTY]]* null }, [[SYCL_IMAGETY]] { i16 1, i8 4, i8 1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* [[SYCL_TGT1]], i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* [[SYCL_COMPILE_OPTS1]], i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* [[SYCL_LINK_OPTS1]], i64 0, i64 0), i8* null, i8* null, i8* getelementptr inbounds ([[SYCL_BIN1TY]], [[SYCL_BIN1TY]]* [[SYCL_BIN1]], i64 0, i64 0), i8* getelementptr inbounds ([[SYCL_BIN1TY]], [[SYCL_BIN1TY]]* [[SYCL_BIN1]], i64 1, i64 0), [[ENTTY]]* null, [[ENTTY]]* null }]
103119

104120
// CHECK-IR: [[SYCL_DESC:@.+]] = internal constant [[SYCL_DESCTY]] { i16 1, i16 2, [[SYCL_IMAGETY]]* getelementptr inbounds ([2 x [[SYCL_IMAGETY]]], [2 x [[SYCL_IMAGETY]]]* [[SYCL_IMAGES]], i64 0, i64 0), [[ENTTY]]* null, [[ENTTY]]* null }
105121

@@ -138,7 +154,7 @@
138154
//
139155
// RUN: clang-offload-wrapper -kind sycl -host=x86_64-pc-linux-gnu -emit-reg-funcs=0 -desc-name=lalala -o - %t.tgt | llvm-dis | FileCheck %s --check-prefix CHECK-IR1
140156
// CHECK-IR1: source_filename = "offload.wrapper.object"
141-
// CHECK-IR1: [[IMAGETY:%.+]] = type { i16, i8, i8, i8*, i8*, i8*, i8*, i8*, i8*, %__tgt_offload_entry*, %__tgt_offload_entry* }
157+
// CHECK-IR1: [[IMAGETY:%.+]] = type { i16, i8, i8, i8*, i8*, i8*, i8*, i8*, i8*, i8*, %__tgt_offload_entry*, %__tgt_offload_entry* }
142158
// CHECK-IR1: [[ENTTY:%.+]] = type { i8*, i8*, i64, i32, i32 }
143159
// CHECK-IR1: [[DESCTY:%.+]] = type { i16, i16, [[IMAGETY]]*, [[ENTTY]]*, [[ENTTY]]* }
144160
// CHECK-IR1-NOT: @llvm.global_ctors

0 commit comments

Comments
 (0)