1 // REQUIRES: x86-registered-target
2 // UNSUPPORTED: target={{.*}}-macosx{{.*}}, target={{.*}}-darwin{{.*}}, target={{.*}}-aix{{.*}}, target={{.*}}-zos{{.*}}
3
4 //
5 // Generate all the types of files we can bundle.
6 //
7 // RUN: %clang -O0 -target %itanium_abi_triple %s -E -o %t.i
8 // RUN: %clangxx -O0 -target %itanium_abi_triple -x c++ %s -E -o %t.ii
9 // RUN: %clang -O0 -target %itanium_abi_triple %s -S -emit-llvm -o %t.ll
10 // RUN: %clang -O0 -target %itanium_abi_triple %s -c -emit-llvm -o %t.bc
11 // RUN: %clang -O0 -target %itanium_abi_triple %s -S -o %t.s
12 // RUN: %clang -O0 -target %itanium_abi_triple %s -c -o %t.o
13 // RUN: obj2yaml %t.o > %t.o.yaml
14 // RUN: %clang -O0 -target %itanium_abi_triple %s -emit-ast -o %t.ast
15
16 // RUN: echo 'void a() {}' >%t.a.cpp
17 // RUN: echo 'void b() {}' >%t.b.cpp
18 // RUN: %clang -target %itanium_abi_triple %t.a.cpp -c -o %t.a.o
19 // RUN: %clang -target %itanium_abi_triple %t.b.cpp -c -o %t.b.o
20 //
21 // Remove .llvm_addrsig section since its offset changes after llvm-objcopy
22 // removes clang-offload-bundler sections, therefore not good for comparison.
23 //
24 // RUN: llvm-objcopy --remove-section=.llvm_addrsig %t.a.o
25 // RUN: llvm-objcopy --remove-section=.llvm_addrsig %t.b.o
26 // RUN: obj2yaml %t.a.o > %t.a.yaml
27 // RUN: obj2yaml %t.b.o > %t.b.yaml
28
29 //
30 // Generate an empty file to help with the checks of empty files.
31 //
32 // RUN: touch %t.empty
33
34 //
35 // Generate a couple of files to bundle with.
36 //
37 // RUN: echo 'Content of device file 1' > %t.tgt1
38 // RUN: echo 'Content of device file 2' > %t.tgt2
39
40 //
41 // Check help message.
42 //
43 // RUN: clang-offload-bundler --help | FileCheck %s --check-prefix CK-HELP
44 // CK-HELP: {{.*}}OVERVIEW: A tool to bundle several input files of the specified type <type>
45 // CK-HELP: {{.*}}referring to the same source file but different targets into a single
46 // CK-HELP: {{.*}}one. The resulting file can also be unbundled into different files by
47 // CK-HELP: {{.*}}this tool if -unbundle is provided.
48 // CK-HELP: {{.*}}USAGE: clang-offload-bundler [options]
49 // CK-HELP: {{.*}}-### {{.*}}- Print any external commands that are to be executed instead of actually executing them - for testing purposes.
50 // CK-HELP: {{.*}}-allow-missing-bundles {{.*}}- Create empty files if bundles are missing when unbundling.
51 // CK-HELP: {{.*}}-bundle-align=<uint> {{.*}}- Alignment of bundle for binary files
52 // CK-HELP: {{.*}}-hip-openmp-compatible {{.*}}- Treat hip and hipv4 offload kinds as compatible with openmp kind, and vice versa.
53 // CK-HELP: {{.*}}-input=<string> - Input file. Can be specified multiple times for multiple input files.
54 // CK-HELP: {{.*}}-inputs=<string> - [<input file>,...] (deprecated)
55 // CK-HELP: {{.*}}-list {{.*}}- List bundle IDs in the bundled file.
56 // CK-HELP: {{.*}}-output=<string> - Output file. Can be specified multiple times for multiple output files.
57 // CK-HELP: {{.*}}-outputs=<string> - [<output file>,...] (deprecated)
58 // CK-HELP: {{.*}}-targets=<string> - [<offload kind>-<target triple>,...]
59 // CK-HELP: {{.*}}-type=<string> - Type of the files to be bundled/unbundled.
60 // CK-HELP: {{.*}}Current supported types are:
61 // CK-HELP: {{.*}}i {{.*}}- cpp-output
62 // CK-HELP: {{.*}}ii {{.*}}- c++-cpp-output
63 // CK-HELP: {{.*}}ll {{.*}}- llvm
64 // CK-HELP: {{.*}}bc {{.*}}- llvm-bc
65 // CK-HELP: {{.*}}s {{.*}}- assembler
66 // CK-HELP: {{.*}}o {{.*}}- object
67 // CK-HELP: {{.*}}a {{.*}}- archive of objects
68 // CK-HELP: {{.*}}gch {{.*}}- precompiled-header
69 // CK-HELP: {{.*}}ast {{.*}}- clang AST file
70 // CK-HELP: {{.*}}-unbundle {{.*}}- Unbundle bundled file into several output files.
71
72 //
73 // Check errors.
74 //
75 // RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -input=%t.i -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle.i -unbundle 2>&1 | FileCheck %s --check-prefix CK-ERR1
76 // CK-ERR1: error: only one input file supported in unbundling mode
77
78 // RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -input=%t.i -output=%t.bundle.i -unbundle 2>&1 | FileCheck %s --check-prefix CK-ERR1A
79 // CK-ERR1A: error: number of output files and targets should match in unbundling mode
80
81 // RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu -input=%t.i -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR2
82 // RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -input=%t.i -input=%t.tgt1 -output=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR2
83 // CK-ERR2: error: number of input files and targets should match in bundling mode
84
85 // RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -output=%t.i -output=%t.tgt1 -output=%t.tgt2 -input=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR3
86 // CK-ERR3: error: only one output file supported in bundling mode
87
88 // RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu -output=%t.i -output=%t.tgt1 -output=%t.tgt2 -input=%t.bundle.i -unbundle 2>&1 | FileCheck %s --check-prefix CK-ERR4
89 // RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -output=%t.i -output=%t.tgt1 -input=%t.bundle.i -unbundle 2>&1 | FileCheck %s --check-prefix CK-ERR4
90 // CK-ERR4: error: number of output files and targets should match in unbundling mode
91
92 // RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -input=%t.i -input=%t.tgt1 -input=%t.tgt2.notexist -output=%t.bundle.i 2>&1 | \
93 // RUN: FileCheck %s -DFILE=%t.tgt2.notexist -DMSG=%errc_ENOENT --check-prefix CK-ERR5
94 // RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -output=%t.i -output=%t.tgt1 -output=%t.tgt2 -input=%t.bundle.i.notexist -unbundle 2>&1 | \
95 // RUN: FileCheck %s -DFILE=%t.bundle.i.notexist -DMSG=%errc_ENOENT --check-prefix CK-ERR5
96 // CK-ERR5: error: '[[FILE]]': [[MSG]]
97
98 // RUN: not clang-offload-bundler -type=invalid -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -input=%t.i -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle.i 2>&1 | FileCheck %s -DTYPE=invalid --check-prefix CK-ERR6
99 // CK-ERR6: error: '[[TYPE]]': invalid file type specified
100
101 // RUN: not clang-offload-bundler 2>&1 | FileCheck %s --check-prefix CK-ERR7
102 // CK-ERR7: clang-offload-bundler: for the --type option: must be specified at least once!
103
104 // RUN: not clang-offload-bundler -type=i -input=%t.i -input=%t.tgt1 -input=%t.tgt2 2>&1 | FileCheck %s -check-prefix=CK-ERR7A
105 // CK-ERR7A: error: no output file specified!
106
107 // RUN: not clang-offload-bundler -type=i -input=%t.i -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle.i 2>&1 | FileCheck %s -check-prefix=CK-ERR7B
108 // CK-ERR7B: error: for the --targets option: must be specified at least once!
109
110 // RUN: not clang-offload-bundler -type=i -targets=hxst-powerpcxxle-ibm-linux-gnu,openxp-pxxerpc64le-ibm-linux-gnu,xpenmp-x86_xx-pc-linux-gnu -input=%t.i -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR8
111 // CK-ERR8: error: invalid target 'hxst-powerpcxxle-ibm-linux-gnu', unknown offloading kind 'hxst', unknown target triple 'powerpcxxle-ibm-linux-gnu'
112
113 // RUN: not clang-offload-bundler -type=i -targets=host-powerpc64le-ibm-linux-gnu,openxp-pxxerpc64le-ibm-linux-gnu,xpenmp-x86_xx-pc-linux-gnu -input=%t.i -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR8A
114 // CK-ERR8A: error: invalid target 'openxp-pxxerpc64le-ibm-linux-gnu', unknown offloading kind 'openxp', unknown target triple 'pxxerpc64le-ibm-linux-gnu'
115
116 // RUN: not clang-offload-bundler -type=i -targets=host-powerpc64le-ibm-linux-gnu,openmp-powerpc64le-ibm-linux-gnu,xpenmp-x86_xx-pc-linux-gnu -input=%t.i -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR8B
117 // CK-ERR8B: error: invalid target 'xpenmp-x86_xx-pc-linux-gnu', unknown offloading kind 'xpenmp', unknown target triple 'x86_xx-pc-linux-gnu'
118
119 // RUN: not clang-offload-bundler -type=i -targets=openmp-powerpc64le-linux,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -input=%t.i -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR9A
120 // CK-ERR9A: error: expecting exactly one host target but got 0
121
122 // RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,host-%itanium_abi_triple,openmp-x86_64-pc-linux-gnu -input=%t.i -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR9B
123 // CK-ERR9B: error: Duplicate targets are not allowed
124
125 // RUN: not clang-offload-bundler -type=a -targets=hxst-powerpcxxle-ibm-linux-gnu,openxp-pxxerpc64le-ibm-linux-gnu,xpenmp-x86_xx-pc-linux-gnu -input=%t.i -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR10A
126 // CK-ERR10A: error: Archive files are only supported for unbundling
127
128 // RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -input=%t.i -inputs=%t.tgt1,%t.tgt2 -output=%t.bundle.i -unbundle 2>&1 | FileCheck %s --check-prefix CK-ERR11A
129 // CK-ERR11A: error: -inputs and -input cannot be used together, use only -input instead
130
131 // RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu -output=%t.i -outputs=%t.tgt1,%t.tgt2 -input=%t.bundle.i -unbundle 2>&1 | FileCheck %s --check-prefix CK-ERR11B
132 // CK-ERR11B: error: -outputs and -output cannot be used together, use only -output instead
133
134 //
135 // Check text bundle. This is a readable format, so we check for the format we expect to find.
136 //
137 // RUN: clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -input=%t.i -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle3.i
138 // RUN: clang-offload-bundler -type=ii -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -input=%t.ii -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle3.ii
139 // RUN: clang-offload-bundler -type=ll -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -input=%t.ll -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle3.ll
140 // RUN: clang-offload-bundler -type=s -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -input=%t.s -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle3.s
141 // RUN: clang-offload-bundler -type=s -targets=openmp-powerpc64le-ibm-linux-gnu,host-%itanium_abi_triple,openmp-x86_64-pc-linux-gnu -input=%t.tgt1 -input=%t.s -input=%t.tgt2 -output=%t.bundle3.unordered.s
142 // RUN: FileCheck %s --input-file %t.bundle3.i --check-prefix CK-TEXTI
143 // RUN: FileCheck %s --input-file %t.bundle3.ii --check-prefix CK-TEXTI
144 // RUN: FileCheck %s --input-file %t.bundle3.ll --check-prefix CK-TEXTLL
145 // RUN: FileCheck %s --input-file %t.bundle3.s --check-prefix CK-TEXTS
146 // RUN: FileCheck %s --input-file %t.bundle3.unordered.s --check-prefix CK-TEXTS-UNORDERED
147
148 // CK-TEXTI: // __CLANG_OFFLOAD_BUNDLE____START__ host-[[HOST:.+]]
149 // CK-TEXTI: int A = 0;
150 // CK-TEXTI: test_func(void)
151 // CK-TEXTI: // __CLANG_OFFLOAD_BUNDLE____END__ host-[[HOST]]
152 // CK-TEXTI: // __CLANG_OFFLOAD_BUNDLE____START__ openmp-powerpc64le-ibm-linux-gnu
153 // CK-TEXTI: Content of device file 1
154 // CK-TEXTI: // __CLANG_OFFLOAD_BUNDLE____END__ openmp-powerpc64le-ibm-linux-gnu
155 // CK-TEXTI: // __CLANG_OFFLOAD_BUNDLE____START__ openmp-x86_64-pc-linux-gnu
156 // CK-TEXTI: Content of device file 2
157 // CK-TEXTI: // __CLANG_OFFLOAD_BUNDLE____END__ openmp-x86_64-pc-linux-gnu
158
159 // CK-TEXTLL: ; __CLANG_OFFLOAD_BUNDLE____START__ host-[[HOST:.+]]
160 // CK-TEXTLL: @A = {{.*}}global i32 0
161 // CK-TEXTLL: define {{.*}}@test_func()
162 // CK-TEXTLL: ; __CLANG_OFFLOAD_BUNDLE____END__ host-[[HOST]]
163 // CK-TEXTLL: ; __CLANG_OFFLOAD_BUNDLE____START__ openmp-powerpc64le-ibm-linux-gnu
164 // CK-TEXTLL: Content of device file 1
165 // CK-TEXTLL: ; __CLANG_OFFLOAD_BUNDLE____END__ openmp-powerpc64le-ibm-linux-gnu
166 // CK-TEXTLL: ; __CLANG_OFFLOAD_BUNDLE____START__ openmp-x86_64-pc-linux-gnu
167 // CK-TEXTLL: Content of device file 2
168 // CK-TEXTLL: ; __CLANG_OFFLOAD_BUNDLE____END__ openmp-x86_64-pc-linux-gnu
169
170 // CK-TEXTS: # __CLANG_OFFLOAD_BUNDLE____START__ host-[[HOST:.+]]
171 // CK-TEXTS: .globl {{.*}}test_func
172 // CK-TEXTS: .globl {{.*}}A
173 // CK-TEXTS: # __CLANG_OFFLOAD_BUNDLE____END__ host-[[HOST]]
174 // CK-TEXTS: # __CLANG_OFFLOAD_BUNDLE____START__ openmp-powerpc64le-ibm-linux-gnu
175 // CK-TEXTS: Content of device file 1
176 // CK-TEXTS: # __CLANG_OFFLOAD_BUNDLE____END__ openmp-powerpc64le-ibm-linux-gnu
177 // CK-TEXTS: # __CLANG_OFFLOAD_BUNDLE____START__ openmp-x86_64-pc-linux-gnu
178 // CK-TEXTS: Content of device file 2
179 // CK-TEXTS: # __CLANG_OFFLOAD_BUNDLE____END__ openmp-x86_64-pc-linux-gnu
180
181 // CK-TEXTS-UNORDERED: # __CLANG_OFFLOAD_BUNDLE____START__ openmp-powerpc64le-ibm-linux-gnu
182 // CK-TEXTS-UNORDERED: Content of device file 1
183 // CK-TEXTS-UNORDERED: # __CLANG_OFFLOAD_BUNDLE____END__ openmp-powerpc64le-ibm-linux-gnu
184 // CK-TEXTS-UNORDERED: # __CLANG_OFFLOAD_BUNDLE____START__ host-[[HOST:.+]]
185 // CK-TEXTS-UNORDERED: .globl {{.*}}test_func
186 // CK-TEXTS-UNORDERED: .globl {{.*}}A
187 // CK-TEXTS-UNORDERED: # __CLANG_OFFLOAD_BUNDLE____END__ host-[[HOST]]
188 // CK-TEXTS-UNORDERED: # __CLANG_OFFLOAD_BUNDLE____START__ openmp-x86_64-pc-linux-gnu
189 // CK-TEXTS-UNORDERED: Content of device file 2
190 // CK-TEXTS-UNORDERED: # __CLANG_OFFLOAD_BUNDLE____END__ openmp-x86_64-pc-linux-gnu
191
192 //
193 // Check text unbundle. Check if we get the exact same content that we bundled before for each file.
194 //
195 // RUN: clang-offload-bundler -type=i -input=%t.bundle3.i -list | FileCheck -check-prefix=CKLST %s
196 // RUN: clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -output=%t.res.i -output=%t.res.tgt1 -output=%t.res.tgt2 -input=%t.bundle3.i -unbundle
197 // RUN: diff %t.i %t.res.i
198 // RUN: diff %t.tgt1 %t.res.tgt1
199 // RUN: diff %t.tgt2 %t.res.tgt2
200 // RUN: clang-offload-bundler -type=i -targets=openmp-powerpc64le-ibm-linux-gnu -output=%t.res.tgt1 -input=%t.bundle3.i -unbundle
201 // RUN: diff %t.tgt1 %t.res.tgt1
202 // RUN: clang-offload-bundler -type=ii -input=%t.bundle3.ii -list | FileCheck -check-prefix=CKLST %s
203 // RUN: clang-offload-bundler -type=ii -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -output=%t.res.ii -output=%t.res.tgt1 -output=%t.res.tgt2 -input=%t.bundle3.ii -unbundle
204 // RUN: diff %t.ii %t.res.ii
205 // RUN: diff %t.tgt1 %t.res.tgt1
206 // RUN: diff %t.tgt2 %t.res.tgt2
207 // RUN: clang-offload-bundler -type=ii -targets=openmp-x86_64-pc-linux-gnu -output=%t.res.tgt2 -input=%t.bundle3.ii -unbundle
208 // RUN: diff %t.tgt2 %t.res.tgt2
209 // RUN: clang-offload-bundler -type=ll -input=%t.bundle3.ll -list | FileCheck -check-prefix=CKLST %s
210 // RUN: clang-offload-bundler -type=ll -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -output=%t.res.ll -output=%t.res.tgt1 -output=%t.res.tgt2 -input=%t.bundle3.ll -unbundle
211 // RUN: diff %t.ll %t.res.ll
212 // RUN: diff %t.tgt1 %t.res.tgt1
213 // RUN: diff %t.tgt2 %t.res.tgt2
214 // RUN: clang-offload-bundler -type=ll -targets=openmp-powerpc64le-ibm-linux-gnu -output=%t.res.tgt1 -input=%t.bundle3.ll -unbundle
215 // RUN: diff %t.tgt1 %t.res.tgt1
216 // RUN: clang-offload-bundler -type=s -input=%t.bundle3.s -list | FileCheck -check-prefix=CKLST %s
217 // RUN: clang-offload-bundler -type=s -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -output=%t.res.s -output=%t.res.tgt1 -output=%t.res.tgt2 -input=%t.bundle3.s -unbundle
218 // RUN: diff %t.s %t.res.s
219 // RUN: diff %t.tgt1 %t.res.tgt1
220 // RUN: diff %t.tgt2 %t.res.tgt2
221 // RUN: clang-offload-bundler -type=s -targets=openmp-powerpc64le-ibm-linux-gnu,host-%itanium_abi_triple,openmp-x86_64-pc-linux-gnu -output=%t.res.tgt1 -output=%t.res.s -output=%t.res.tgt2 -input=%t.bundle3.s -unbundle
222 // RUN: diff %t.s %t.res.s
223 // RUN: diff %t.tgt1 %t.res.tgt1
224 // RUN: diff %t.tgt2 %t.res.tgt2
225 // RUN: clang-offload-bundler -type=s -targets=openmp-x86_64-pc-linux-gnu -output=%t.res.tgt2 -input=%t.bundle3.s -unbundle
226 // RUN: diff %t.tgt2 %t.res.tgt2
227
228 // Check if we can unbundle a file with no magic strings.
229 // RUN: clang-offload-bundler -type=s -input=%t.s -list | FileCheck -check-prefix=CKLST2 --allow-empty %s
230 // RUN: clang-offload-bundler -type=s -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -output=%t.res.s -output=%t.res.tgt1 -output=%t.res.tgt2 -input=%t.s -unbundle -allow-missing-bundles
231 // RUN: diff %t.s %t.res.s
232 // RUN: diff %t.empty %t.res.tgt1
233 // RUN: diff %t.empty %t.res.tgt2
234 // RUN: clang-offload-bundler -type=s -targets=openmp-powerpc64le-ibm-linux-gnu,host-%itanium_abi_triple,openmp-x86_64-pc-linux-gnu -output=%t.res.tgt1 -output=%t.res.s -output=%t.res.tgt2 -input=%t.s -unbundle -allow-missing-bundles
235 // RUN: diff %t.s %t.res.s
236 // RUN: diff %t.empty %t.res.tgt1
237 // RUN: diff %t.empty %t.res.tgt2
238
239 // Check that bindler prints an error if given host bundle does not exist in the fat binary.
240 // RUN: not clang-offload-bundler -type=s -targets=host-amdgcn-xxx-linux-gnu,openmp-powerpc64le-ibm-linux-gnu -output=%t.res.s -output=%t.res.tgt1 -input=%t.bundle3.s -unbundle 2>&1 | FileCheck %s --check-prefix CK-NO-HOST-BUNDLE
241 // CK-NO-HOST-BUNDLE: error: Can't find bundles for host-amdgcn-xxx-linux-gnu
242
243 // Check missing host entry is allowed with -allow-missing-bundles
244 // RUN: clang-offload-bundler -type=s -targets=host-amdgcn-xxx-linux-gnu,openmp-powerpc64le-ibm-linux-gnu -output=%t.res.s -output=%t.res.tgt1 -input=%t.bundle3.s -unbundle -allow-missing-bundles
245
246 //
247 // Check binary bundle/unbundle. The content that we have before bundling must be the same we have after unbundling.
248 //
249 // RUN: clang-offload-bundler -type=bc -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -input=%t.bc -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle3.bc
250 // RUN: clang-offload-bundler -type=gch -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -input=%t.ast -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle3.gch
251 // RUN: clang-offload-bundler -type=ast -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -input=%t.ast -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle3.ast
252 // RUN: clang-offload-bundler -type=ast -targets=openmp-powerpc64le-ibm-linux-gnu,host-%itanium_abi_triple,openmp-x86_64-pc-linux-gnu -input=%t.tgt1 -input=%t.ast -input=%t.tgt2 -output=%t.bundle3.unordered.ast
253 // RUN: clang-offload-bundler -type=bc -input=%t.bundle3.bc -list | FileCheck -check-prefix=CKLST %s
254 // RUN: clang-offload-bundler -type=bc -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -output=%t.res.bc -output=%t.res.tgt1 -output=%t.res.tgt2 -input=%t.bundle3.bc -unbundle
255 // RUN: diff %t.bc %t.res.bc
256 // RUN: diff %t.tgt1 %t.res.tgt1
257 // RUN: diff %t.tgt2 %t.res.tgt2
258 // RUN: clang-offload-bundler -type=bc -targets=openmp-powerpc64le-ibm-linux-gnu -output=%t.res.tgt1 -input=%t.bundle3.bc -unbundle
259 // RUN: diff %t.tgt1 %t.res.tgt1
260 // RUN: clang-offload-bundler -type=gch -input=%t.bundle3.gch -list | FileCheck -check-prefix=CKLST %s
261 // RUN: clang-offload-bundler -type=gch -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -output=%t.res.gch -output=%t.res.tgt1 -output=%t.res.tgt2 -input=%t.bundle3.gch -unbundle
262 // RUN: diff %t.ast %t.res.gch
263 // RUN: diff %t.tgt1 %t.res.tgt1
264 // RUN: diff %t.tgt2 %t.res.tgt2
265 // RUN: clang-offload-bundler -type=gch -targets=openmp-x86_64-pc-linux-gnu -output=%t.res.tgt2 -input=%t.bundle3.gch -unbundle
266 // RUN: diff %t.tgt2 %t.res.tgt2
267 // RUN: clang-offload-bundler -type=ast -input=%t.bundle3.ast -list | FileCheck -check-prefix=CKLST %s
268 // RUN: clang-offload-bundler -type=ast -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -output=%t.res.ast -output=%t.res.tgt1 -output=%t.res.tgt2 -input=%t.bundle3.ast -unbundle
269 // RUN: diff %t.ast %t.res.ast
270 // RUN: diff %t.tgt1 %t.res.tgt1
271 // RUN: diff %t.tgt2 %t.res.tgt2
272 // RUN: clang-offload-bundler -type=ast -targets=openmp-powerpc64le-ibm-linux-gnu,host-%itanium_abi_triple,openmp-x86_64-pc-linux-gnu -output=%t.res.tgt1 -output=%t.res.ast -output=%t.res.tgt2 -input=%t.bundle3.ast -unbundle
273 // RUN: diff %t.ast %t.res.ast
274 // RUN: diff %t.tgt1 %t.res.tgt1
275 // RUN: diff %t.tgt2 %t.res.tgt2
276 // RUN: clang-offload-bundler -type=ast -targets=openmp-powerpc64le-ibm-linux-gnu,host-%itanium_abi_triple,openmp-x86_64-pc-linux-gnu -output=%t.res.tgt1 -output=%t.res.ast -output=%t.res.tgt2 -input=%t.bundle3.unordered.ast -unbundle
277 // RUN: diff %t.ast %t.res.ast
278 // RUN: diff %t.tgt1 %t.res.tgt1
279 // RUN: diff %t.tgt2 %t.res.tgt2
280 // RUN: clang-offload-bundler -type=ast -targets=openmp-powerpc64le-ibm-linux-gnu -output=%t.res.tgt1 -input=%t.bundle3.ast -unbundle
281 // RUN: diff %t.tgt1 %t.res.tgt1
282
283 // Check if we can unbundle a file with no magic strings.
284 // RUN: clang-offload-bundler -type=bc -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -output=%t.res.bc -output=%t.res.tgt1 -output=%t.res.tgt2 -input=%t.bc -unbundle -allow-missing-bundles
285 // RUN: diff %t.bc %t.res.bc
286 // RUN: diff %t.empty %t.res.tgt1
287 // RUN: diff %t.empty %t.res.tgt2
288 // RUN: clang-offload-bundler -type=bc -targets=openmp-powerpc64le-ibm-linux-gnu,host-%itanium_abi_triple,openmp-x86_64-pc-linux-gnu -output=%t.res.tgt1 -output=%t.res.bc -output=%t.res.tgt2 -input=%t.bc -unbundle -allow-missing-bundles
289 // RUN: diff %t.bc %t.res.bc
290 // RUN: diff %t.empty %t.res.tgt1
291 // RUN: diff %t.empty %t.res.tgt2
292
293 // Check that we do not have to unbundle all available bundles from the fat binary.
294 // RUN: clang-offload-bundler -type=ast -targets=host-%itanium_abi_triple,openmp-x86_64-pc-linux-gnu -output=%t.res.ast -output=%t.res.tgt2 -input=%t.bundle3.unordered.ast -unbundle
295 // RUN: diff %t.ast %t.res.ast
296 // RUN: diff %t.tgt2 %t.res.tgt2
297
298 // Check that we do not have to unbundle all available bundles from the fat binary.
299 // RUN: clang-offload-bundler -type=ast -targets=host-%itanium_abi_triple,openmp-x86_64-pc-linux-gnu -output=%t.res.ast -output=%t.res.tgt2 -input=%t.bundle3.unordered.ast -unbundle
300 // RUN: diff %t.ast %t.res.ast
301 // RUN: diff %t.tgt2 %t.res.tgt2
302
303 //
304 // Check object bundle/unbundle. The content should be bundled into an ELF
305 // section (we are using a PowerPC little-endian host which uses ELF). We
306 // have an already bundled file to check the unbundle and do a dry run on the
307 // bundling as it cannot be tested in all host platforms that will run these
308 // tests.
309 //
310
311 // RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -input=%t.o -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle3.o -### 2>&1 \
312 // RUN: | FileCheck %s -DHOST=%itanium_abi_triple -DINOBJ1=%t.o -DINOBJ2=%t.tgt1 -DINOBJ3=%t.tgt2 -DOUTOBJ=%t.bundle3.o --check-prefix CK-OBJ-CMD
313 // CK-OBJ-CMD: llvm-objcopy{{(.exe)?}}" "--add-section=__CLANG_OFFLOAD_BUNDLE__host-[[HOST:.+]]={{.*}}" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]=readonly,exclude" "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu-=[[INOBJ2]]" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu-=readonly,exclude" "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu-=[[INOBJ3]]" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu-=readonly,exclude" "--" "[[INOBJ1]]" "[[OUTOBJ]]"
314
315 // RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -input=%t.o -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle3.o -### 2>&1 \
316 // RUN: | FileCheck %s -DHOST=%itanium_abi_triple -DINOBJ1=%t.o -DINOBJ2=%t.tgt1 -DINOBJ3=%t.tgt2 -DOUTOBJ=%t.bundle3.o --check-prefix CK-OBJ-CMD-INPUTS
317 // CK-OBJ-CMD-INPUTS: llvm-objcopy{{(.exe)?}}" "--add-section=__CLANG_OFFLOAD_BUNDLE__host-[[HOST:.+]]={{.*}}" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]=readonly,exclude" "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu-=[[INOBJ2]]" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu-=readonly,exclude" "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu-=[[INOBJ3]]" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu-=readonly,exclude" "--" "[[INOBJ1]]" "[[OUTOBJ]]"
318
319 // RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -input=%t.o -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle3.o
320 // RUN: clang-offload-bundler -type=o -input=%t.bundle3.o -list | FileCheck -check-prefix=CKLST %s
321 // RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -output=%t.res.o -output=%t.res.tgt1 -output=%t.res.tgt2 -input=%t.bundle3.o -unbundle
322 // RUN: obj2yaml %t.res.o > %t.res.o.yaml
323 // RUN: diff %t.o.yaml %t.res.o.yaml
324 // RUN: diff %t.tgt1 %t.res.tgt1
325 // RUN: diff %t.tgt2 %t.res.tgt2
326 // RUN: clang-offload-bundler -type=o -targets=openmp-powerpc64le-ibm-linux-gnu,host-%itanium_abi_triple,openmp-x86_64-pc-linux-gnu -output=%t.res.tgt1 -output=%t.res.o -output=%t.res.tgt2 -input=%t.bundle3.o -unbundle
327 // RUN: obj2yaml %t.res.o > %t.res.o.yaml
328 // RUN: diff %t.o.yaml %t.res.o.yaml
329 // RUN: diff %t.tgt1 %t.res.tgt1
330 // RUN: diff %t.tgt2 %t.res.tgt2
331 // RUN: clang-offload-bundler -type=o -targets=openmp-powerpc64le-ibm-linux-gnu -output=%t.res.tgt1 -input=%t.bundle3.o -unbundle
332 // RUN: diff %t.tgt1 %t.res.tgt1
333
334 // Check if we can unbundle a file with no magic strings.
335 // RUN: clang-offload-bundler -type=o -input=%t.o -list | FileCheck -check-prefix=CKLST2 --allow-empty %s
336 // RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -output=%t.res.o -output=%t.res.tgt1 -output=%t.res.tgt2 -input=%t.o -unbundle -allow-missing-bundles
337 // RUN: obj2yaml %t.res.o > %t.res.o.yaml
338 // RUN: diff %t.o.yaml %t.res.o.yaml
339 // RUN: diff %t.empty %t.res.tgt1
340 // RUN: diff %t.empty %t.res.tgt2
341 // RUN: clang-offload-bundler -type=o -targets=openmp-powerpc64le-ibm-linux-gnu,host-%itanium_abi_triple,openmp-x86_64-pc-linux-gnu -output=%t.res.tgt1 -output=%t.res.o -output=%t.res.tgt2 -input=%t.o -unbundle -allow-missing-bundles
342 // RUN: obj2yaml %t.res.o > %t.res.o.yaml
343 // RUN: diff %t.o.yaml %t.res.o.yaml
344 // RUN: diff %t.empty %t.res.tgt1
345 // RUN: diff %t.empty %t.res.tgt2
346
347 //
348 // Check -bundle-align option
349 //
350
351 // RUN: clang-offload-bundler -bundle-align=4096 -type=bc -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -input=%t.bc -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle3.bc
352 // RUN: clang-offload-bundler -type=bc -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -output=%t.res.bc -output=%t.res.tgt1 -output=%t.res.tgt2 -input=%t.bundle3.bc -unbundle
353 // RUN: diff %t.bc %t.res.bc
354 // RUN: diff %t.tgt1 %t.res.tgt1
355 // RUN: diff %t.tgt2 %t.res.tgt2
356
357 //
358 // Check error due to missing bundles
359 //
360 // RUN: clang-offload-bundler -type=bc -targets=host-%itanium_abi_triple,hip-amdgcn-amd-amdhsa--gfx900 -input=%t.bc -input=%t.tgt1 -output=%t.hip.bundle.bc
361 // RUN: not clang-offload-bundler -type=bc -input=%t.hip.bundle.bc -output=%t.tmp.bc -unbundle \
362 // RUN: -targets=hip-amdgcn-amd-amdhsa--gfx906 \
363 // RUN: 2>&1 | FileCheck -check-prefix=MISS1 %s
364 // RUN: not clang-offload-bundler -type=bc -input=%t.hip.bundle.bc -output=%t.tmp.bc -output=%t.tmp2.bc -unbundle \
365 // RUN: -targets=hip-amdgcn-amd-amdhsa--gfx906,hip-amdgcn-amd-amdhsa--gfx900 \
366 // RUN: 2>&1 | FileCheck -check-prefix=MISS1 %s
367 // MISS1: error: Can't find bundles for hip-amdgcn-amd-amdhsa--gfx906
368 // RUN: not clang-offload-bundler -type=bc -input=%t.hip.bundle.bc -output=%t.tmp.bc -output=%t.tmp2.bc -unbundle \
369 // RUN: -targets=hip-amdgcn-amd-amdhsa--gfx906,hip-amdgcn-amd-amdhsa--gfx803 \
370 // RUN: 2>&1 | FileCheck -check-prefix=MISS2 %s
371 // MISS2: error: Can't find bundles for hip-amdgcn-amd-amdhsa--gfx803 and hip-amdgcn-amd-amdhsa--gfx906
372 // RUN: not clang-offload-bundler -type=bc -input=%t.hip.bundle.bc -output=%t.tmp.bc -output=%t.tmp2.bc -output=%t.tmp3.bc -unbundle \
373 // RUN: -targets=hip-amdgcn-amd-amdhsa--gfx906,hip-amdgcn-amd-amdhsa--gfx803,hip-amdgcn-amd-amdhsa--gfx1010 \
374 // RUN: 2>&1 | FileCheck -check-prefix=MISS3 %s
375 // MISS3: error: Can't find bundles for hip-amdgcn-amd-amdhsa--gfx1010, hip-amdgcn-amd-amdhsa--gfx803, and hip-amdgcn-amd-amdhsa--gfx906
376
377 //
378 // Check error due to duplicate targets
379 //
380 // RUN: not clang-offload-bundler -type=bc -targets=host-%itanium_abi_triple,hip-amdgcn-amd-amdhsa--gfx900,hip-amdgcn-amd-amdhsa--gfx900 \
381 // RUN: -input=%t.bc -input=%t.tgt1 -input=%t.tgt1 -output=%t.hip.bundle.bc 2>&1 | FileCheck -check-prefix=DUP %s
382 // RUN: not clang-offload-bundler -type=bc -input=%t.hip.bundle.bc -output=%t.tmp.bc -output=%t.tmp2.bc -unbundle \
383 // RUN: -targets=hip-amdgcn-amd-amdhsa--gfx906,hip-amdgcn-amd-amdhsa--gfx906 \
384 // RUN: 2>&1 | FileCheck -check-prefix=DUP %s
385 // DUP: error: Duplicate targets are not allowed
386 //
387 // Check -list option
388 //
389
390 // RUN: clang-offload-bundler -bundle-align=4096 -type=bc -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -input=%t.bc -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle3.bc
391 // RUN: not clang-offload-bundler -type=bc -input=%t.bundle3.bc -unbundle -list 2>&1 | FileCheck -check-prefix=CKLST-ERR %s
392 // CKLST-ERR: error: -unbundle and -list cannot be used together
393 // RUN: not clang-offload-bundler -type=bc -input=%t.bundle3.bc -targets=host-%itanium_abi_triple -list 2>&1 | FileCheck -check-prefix=CKLST-ERR2 %s
394 // CKLST-ERR2: error: -targets option is invalid for -list
395 // RUN: not clang-offload-bundler -type=bc -input=%t.bundle3.bc -output=out.txt -list 2>&1 | FileCheck -check-prefix=CKLST-ERR3 %s
396 // CKLST-ERR3: error: -outputs option is invalid for -list
397 // RUN: not clang-offload-bundler -type=bc -input=%t.bundle3.bc -input=%t.bc -list 2>&1 | FileCheck -check-prefix=CKLST-ERR4 %s
398 // CKLST-ERR4: error: only one input file supported for -list
399
400 // CKLST-DAG: host-
401 // CKLST-DAG: openmp-powerpc64le-ibm-linux-gnu
402 // CKLST-DAG: openmp-x86_64-pc-linux-gnu
403
404 // CKLST2-NOT: host-
405 // CKLST2-NOT: openmp-powerpc64le-ibm-linux-gnu
406 // CKLST2-NOT: openmp-x86_64-pc-linux-gnu
407
408 //
409 // Check unbundling archive for HIP.
410 //
411 // When the input to clang-offload-bundler is an archive of bundled bitcodes,
412 // for each target, clang-offload-bundler extracts the bitcode from each
413 // bundle and archives them. Therefore for each target, the output is an
414 // archive of unbundled bitcodes.
415 //
416 // RUN: clang-offload-bundler -type=bc -targets=hip-amdgcn-amd-amdhsa--gfx900,hip-amdgcn-amd-amdhsa--gfx906 \
417 // RUN: -input=%t.tgt1 -input=%t.tgt2 -output=%T/hip_bundle1.bc
418 // RUN: clang-offload-bundler -type=bc -targets=hip-amdgcn-amd-amdhsa--gfx900,hip-amdgcn-amd-amdhsa--gfx906 \
419 // RUN: -input=%t.tgt1 -input=%t.tgt2 -output=%T/hip_bundle2.bc
420 // RUN: llvm-ar cr %T/hip_archive.a %T/hip_bundle1.bc %T/hip_bundle2.bc
421 // RUN: clang-offload-bundler -unbundle -type=a -targets=hip-amdgcn-amd-amdhsa--gfx900,hip-amdgcn-amd-amdhsa--gfx906 \
422 // RUN: -output=%T/hip_900.a -output=%T/hip_906.a -input=%T/hip_archive.a
423 // RUN: llvm-ar t %T/hip_900.a | FileCheck -check-prefix=HIP-AR-900 %s
424 // RUN: llvm-ar t %T/hip_906.a | FileCheck -check-prefix=HIP-AR-906 %s
425 // HIP-AR-900-DAG: hip_bundle1-hip-amdgcn-amd-amdhsa--gfx900
426 // HIP-AR-900-DAG: hip_bundle2-hip-amdgcn-amd-amdhsa--gfx900
427 // HIP-AR-906-DAG: hip_bundle1-hip-amdgcn-amd-amdhsa--gfx906
428 // HIP-AR-906-DAG: hip_bundle2-hip-amdgcn-amd-amdhsa--gfx906
429
430 //
431 // Check unbundling archive for host target
432 //
433 // RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,hip-amdgcn-amd-amdhsa--gfx900 \
434 // RUN: -input=%t.a.o -input=%t.tgt1 -output=%t.a.bundled.o
435 // RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,hip-amdgcn-amd-amdhsa--gfx900 \
436 // RUN: -input=%t.b.o -input=%t.tgt1 -output=%t.b.bundled.o
437 // RUN: rm -f %t.bundled.a
438 // RUN: llvm-ar cr %t.bundled.a %t.a.bundled.o %t.b.bundled.o
439 // RUN: cp %t.bundled.a %t.bundled.a.bak
440 // RUN: clang-offload-bundler -unbundle --targets=host-%itanium_abi_triple -type=a -input=%t.bundled.a -output=%t.host.a
441 // RUN: rm -f *%itanium_abi_triple*.a.bundled.o *%itanium_abi_triple*.b.bundled.o
442 // RUN: llvm-ar -x %t.host.a
443 // RUN: diff %t.bundled.a %t.bundled.a.bak
444 // RUN: obj2yaml *%itanium_abi_triple*.a.bundled.o > %t.a.unbundled.yaml
445 // RUN: diff %t.a.unbundled.yaml %t.a.yaml
446 // RUN: obj2yaml *%itanium_abi_triple*.b.bundled.o > %t.b.unbundled.yaml
447 // RUN: diff %t.b.unbundled.yaml %t.b.yaml
448 //
449 // Check clang-offload-bundler reporting an error when trying to unbundle an archive but
450 // the input file is not an archive.
451 //
452 // RUN: echo 'This is not an archive file.' > %t.non-archive
453 // RUN: not clang-offload-bundler -unbundle -type=a -targets=hip-amdgcn-amd-amdhsa--gfx900 \
454 // RUN: -output=%t.res.a -input=%t.non-archive --allow-missing-bundles 2>&1 \
455 // RUN: | FileCheck %s -check-prefix=INVARCHIVE
456 // RUN: not clang-offload-bundler -unbundle -type=a -targets=hip-amdgcn-amd-amdhsa--gfx900 \
457 // RUN: -output=%t.res.a -input=%t.non-archive 2>&1 | FileCheck %s -check-prefix=INVARCHIVE
458 // INVARCHIVE: error: file too small to be an archive
459
460 //
461 // Check bundling without host target is allowed for HIP.
462 //
463 // RUN: clang-offload-bundler -type=bc -targets=hip-amdgcn-amd-amdhsa--gfx900,hip-amdgcn-amd-amdhsa--gfx906 \
464 // RUN: -input=%t.tgt1 -input=%t.tgt2 -output=%t.hip.bundle.bc
465 // RUN: clang-offload-bundler -type=bc -list -input=%t.hip.bundle.bc | FileCheck -check-prefix=NOHOST %s
466 // RUN: clang-offload-bundler -type=bc -targets=hip-amdgcn-amd-amdhsa--gfx900,hip-amdgcn-amd-amdhsa--gfx906 \
467 // RUN: -output=%t.res.tgt1 -output=%t.res.tgt2 -input=%t.hip.bundle.bc -unbundle
468 // RUN: diff %t.tgt1 %t.res.tgt1
469 // RUN: diff %t.tgt2 %t.res.tgt2
470 //
471 // NOHOST-NOT: host-
472 // NOHOST-DAG: hip-amdgcn-amd-amdhsa--gfx900
473 // NOHOST-DAG: hip-amdgcn-amd-amdhsa--gfx906
474
475 //
476 // Check bundling ID compatibility for HIP.
477 //
478 // RUN: clang-offload-bundler -type=bc -targets=hip-amdgcn-amd-amdhsa--gfx906:xnack- \
479 // RUN: -targets=hip-amdgcn-amd-amdhsa--gfx906:xnack+ \
480 // RUN: -input=%t.tgt1 -input=%t.tgt2 -output=%t.hip.bundle.bc
481 // RUN: not clang-offload-bundler -type=bc -targets=hip-amdgcn-amd-amdhsa--gfx906 \
482 // RUN: -targets=hip-amdgcn-amd-amdhsa--gfx906:xnack+ \
483 // RUN: -input=%t.tgt1 -input=%t.tgt2 -output=%t.hip.bundle.bc 2>&1 \
484 // RUN: | FileCheck %s -check-prefix=CONFLICT-TID
485 // CONFLICT-TID: error: Cannot bundle inputs with conflicting targets: 'hip-amdgcn-amd-amdhsa--gfx906' and 'hip-amdgcn-amd-amdhsa--gfx906:xnack+'
486
487 //
488 // Check extracting bundle entry with compatible target ID for HIP.
489 //
490 // RUN: clang-offload-bundler -type=bc -targets=hip-amdgcn-amd-amdhsa--gfx906 \
491 // RUN: -input=%t.tgt1 -output=%t.hip.bundle.bc
492 // RUN: clang-offload-bundler -type=bc -targets=hip-amdgcn-amd-amdhsa--gfx906:xnack- \
493 // RUN: -output=%t.res.tgt1 -input=%t.hip.bundle.bc -unbundle
494 // RUN: diff %t.tgt1 %t.res.tgt1
495 // RUN: clang-offload-bundler -type=bc -targets=hip-amdgcn-amd-amdhsa--gfx906:xnack+ \
496 // RUN: -output=%t.res.tgt1 -input=%t.hip.bundle.bc -unbundle
497 // RUN: diff %t.tgt1 %t.res.tgt1
498
499 // RUN: clang-offload-bundler -type=bc -targets=hip-amdgcn-amd-amdhsa--gfx906:xnack+ \
500 // RUN: -input=%t.tgt1 -output=%t.hip.bundle.bc
501 // RUN: not clang-offload-bundler -type=bc -targets=hip-amdgcn-amd-amdhsa--gfx906:xnack- \
502 // RUN: -output=%t.res.tgt1 -input=%t.hip.bundle.bc -unbundle 2>&1 | FileCheck %s -check-prefix=NOXNACK
503 // NOXNACK: error: Can't find bundles for hip-amdgcn-amd-amdhsa--gfx906:xnack-
504 // RUN: not clang-offload-bundler -type=bc -targets=hip-amdgcn-amd-amdhsa--gfx906 \
505 // RUN: -output=%t.res.tgt1 -input=%t.hip.bundle.bc -unbundle 2>&1 | FileCheck %s -check-prefix=NOGFX906
506 // NOGFX906: error: Can't find bundles for hip-amdgcn-amd-amdhsa--gfx906
507
508 //
509 // Check hip and hipv4 are compatible as offload kind.
510 //
511 // RUN: clang-offload-bundler -type=o -targets=hip-amdgcn-amd-amdhsa--gfx90a -input=%t.tgt1 -output=%t.bundle3.o
512 // RUN: clang-offload-bundler -type=o -targets=hipv4-amdgcn-amd-amdhsa--gfx90a:sramecc-:xnack+ -output=%t.res.tgt1 -input=%t.bundle3.o -unbundle
513 // RUN: diff %t.tgt1 %t.res.tgt1
514
515 // RUN: clang-offload-bundler -type=o -targets=hipv4-amdgcn-amd-amdhsa--gfx90a -input=%t.tgt1 -output=%t.bundle3.o
516 // RUN: clang-offload-bundler -type=o -targets=hip-amdgcn-amd-amdhsa--gfx90a:sramecc-:xnack+ -output=%t.res.tgt1 -input=%t.bundle3.o -unbundle
517 // RUN: diff %t.tgt1 %t.res.tgt1
518
519 //
520 // Check archive unbundling
521 //
522 // Create few code object bundles and archive them to create an input archive
523 // RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-amdgcn-amd-amdhsa-gfx906,openmp-amdgcn-amd-amdhsa--gfx908 -input=%t.o -input=%t.tgt1 -input=%t.tgt2 -output=%t.simple.bundle
524 // RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-amdgcn-amd-amdhsa--gfx903 -input=%t.o -input=%t.tgt1 -output=%t.simple1.bundle
525 // RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,hip-amdgcn-amd-amdhsa--gfx906 -input=%t.o -input=%t.tgt1 -output=%t.simple2.bundle
526 // RUN: llvm-ar cr %t.input-archive.a %t.simple.bundle %t.simple1.bundle %t.simple2.bundle
527
528 // RUN: clang-offload-bundler -unbundle -type=a -targets=openmp-amdgcn-amd-amdhsa-gfx906,openmp-amdgcn-amd-amdhsa-gfx908 -input=%t.input-archive.a -output=%t-archive-gfx906-simple.a -output=%t-archive-gfx908-simple.a
529 // RUN: llvm-ar t %t-archive-gfx906-simple.a | FileCheck %s -check-prefix=GFX906
530 // RUN: clang-offload-bundler -unbundle -type=a -targets=openmp-amdgcn-amd-amdhsa-gfx906:xnack+ -input=%t.input-archive.a -output=%t-archive-gfx906-simple.a
531 // RUN: llvm-ar t %t-archive-gfx906-simple.a | FileCheck %s -check-prefix=GFX906
532 // GFX906: simple-openmp-amdgcn-amd-amdhsa--gfx906
533 // RUN: llvm-ar t %t-archive-gfx908-simple.a | FileCheck %s -check-prefix=GFX908
534 // GFX908-NOT: {{gfx906}}
535 // RUN: not clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-amdgcn-amd-amdhsa-gfx906,openmp-amdgcn-amd-amdhsa-gfx906:sramecc+ -input=%t.o -input=%t.tgt1 -input=%t.tgt2 -output=%t.bad.bundle 2>&1 | FileCheck %s -check-prefix=BADTARGETS
536 // BADTARGETS: error: Cannot bundle inputs with conflicting targets: 'openmp-amdgcn-amd-amdhsa--gfx906' and 'openmp-amdgcn-amd-amdhsa--gfx906:sramecc+'
537
538 // Check for error if no compatible code object is found in the heterogeneous archive library
539 // RUN: not clang-offload-bundler -unbundle -type=a -targets=openmp-amdgcn-amd-amdhsa-gfx803 -input=%t.input-archive.a -output=%t-archive-gfx803-incompatible.a 2>&1 | FileCheck %s -check-prefix=INCOMPATIBLEARCHIVE
540 // INCOMPATIBLEARCHIVE: error: no compatible code object found for the target 'openmp-amdgcn-amd-amdhsa--gfx803' in heterogeneous archive library
541
542 // Check creation of empty archive if allow-missing-bundles is present and no compatible code object is found in the heterogeneous archive library
543 // RUN: clang-offload-bundler -unbundle -type=a -targets=openmp-amdgcn-amd-amdhsa-gfx803 -input=%t.input-archive.a -output=%t-archive-gfx803-empty.a -allow-missing-bundles
544 // RUN: cat %t-archive-gfx803-empty.a | FileCheck %s -check-prefix=EMPTYARCHIVE
545 // EMPTYARCHIVE: !<arch>
546
547 // Check compatibility of OpenMP code objects found in the heterogeneous archive library with HIP code objects of the target
548 // RUN: clang-offload-bundler -unbundle -type=a -targets=hip-amdgcn-amd-amdhsa-gfx906,hipv4-amdgcn-amd-amdhsa-gfx908 -input=%t.input-archive.a -output=%t-hip-archive-gfx906-simple.a -output=%t-hipv4-archive-gfx908-simple.a -hip-openmp-compatible
549 // RUN: llvm-ar t %t-hip-archive-gfx906-simple.a | FileCheck %s -check-prefix=HIPOPENMPCOMPAT
550 // HIPOPENMPCOMPAT: simple-openmp-amdgcn-amd-amdhsa--gfx906
551 // RUN: llvm-ar t %t-hipv4-archive-gfx908-simple.a | FileCheck %s -check-prefix=HIPv4OPENMPCOMPAT
552 // HIPv4OPENMPCOMPAT: simple-openmp-amdgcn-amd-amdhsa--gfx908
553
554 // Check compatibility of HIP code objects found in the heterogeneous archive library with OpenMP code objects of the target
555 // RUN: clang-offload-bundler -unbundle -type=a -targets=openmp-amdgcn-amd-amdhsa--gfx906 \
556 // RUN: -output=%T/hip-openmp_906.a -input=%T/hip_archive.a -hip-openmp-compatible
557 // RUN: llvm-ar t %T/hip-openmp_906.a | FileCheck -check-prefix=OPENMPHIPCOMPAT %s
558 // OPENMPHIPCOMPAT: hip_bundle1-hip-amdgcn-amd-amdhsa--gfx906
559
560 // Some code so that we can create a binary out of this file.
561 int A = 0;
test_func(void)562 void test_func(void) {
563 ++A;
564 }
565