2 /// Perform several driver tests for OpenMP offloading
5 // REQUIRES: x86-registered-target
6 // REQUIRES: powerpc-registered-target
7 // REQUIRES: nvptx-registered-target
9 /// ###########################################################################
11 /// Check whether an invalid OpenMP target is specified:
12 // RUN: %clang -### -fopenmp=libomp -fopenmp-targets=aaa-bbb-ccc-ddd %s 2>&1 \
13 // RUN: | FileCheck -check-prefix=CHK-INVALID-TARGET %s
14 // CHK-INVALID-TARGET: error: OpenMP target is invalid: 'aaa-bbb-ccc-ddd'
16 /// ###########################################################################
18 /// Check warning for empty -fopenmp-targets
19 // RUN: %clang -### -fopenmp=libomp -fopenmp-targets= %s 2>&1 \
20 // RUN: | FileCheck -check-prefix=CHK-EMPTY-OMPTARGETS %s
21 // CHK-EMPTY-OMPTARGETS: warning: joined argument expects additional value: '-fopenmp-targets='
23 /// ###########################################################################
25 /// Check error for no -fopenmp option
26 // RUN: %clang -### -fopenmp-targets=powerpc64le-ibm-linux-gnu %s 2>&1 \
27 // RUN: | FileCheck -check-prefix=CHK-NO-FOPENMP %s
28 // RUN: %clang -### -fopenmp=libgomp -fopenmp-targets=powerpc64le-ibm-linux-gnu %s 2>&1 \
29 // RUN: | FileCheck -check-prefix=CHK-NO-FOPENMP %s
30 // CHK-NO-FOPENMP: error: '-fopenmp-targets' must be used in conjunction with a '-fopenmp' option compatible with offloading; e.g., '-fopenmp=libomp' or '-fopenmp=libiomp5'
32 /// ###########################################################################
34 /// Check warning for duplicate offloading targets.
35 // RUN: %clang -### -ccc-print-phases -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu,powerpc64le-ibm-linux-gnu %s 2>&1 \
36 // RUN: | FileCheck -check-prefix=CHK-DUPLICATES %s
37 // CHK-DUPLICATES: warning: OpenMP offloading target 'powerpc64le-ibm-linux-gnu' is similar to target 'powerpc64le-ibm-linux-gnu' already specified; will be ignored
39 /// ###########################################################################
41 /// Check -Xopenmp-target=powerpc64le-ibm-linux-gnu -mcpu=pwr7 is passed when compiling for the device.
42 // RUN: %clang -### -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu -Xopenmp-target=powerpc64le-ibm-linux-gnu -mcpu=pwr7 %s 2>&1 \
43 // RUN: | FileCheck -check-prefix=CHK-FOPENMP-EQ-TARGET %s
45 // CHK-FOPENMP-EQ-TARGET: clang{{.*}} "-target-cpu" "pwr7" {{.*}}"-fopenmp-is-device"
47 /// ###########################################################################
49 /// Check -Xopenmp-target -mcpu=pwr7 is passed when compiling for the device.
50 // RUN: %clang -### -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu -Xopenmp-target -mcpu=pwr7 %s 2>&1 \
51 // RUN: | FileCheck -check-prefix=CHK-FOPENMP-TARGET %s
53 // CHK-FOPENMP-TARGET: clang{{.*}} "-target-cpu" "pwr7" {{.*}}"-fopenmp-is-device"
55 /// ##########################################################################
57 /// Check -mcpu=pwr7 is passed to the same triple.
58 // RUN: %clang -### -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu --target=powerpc64le-ibm-linux-gnu -mcpu=pwr7 %s 2>&1 \
59 // RUN: | FileCheck -check-prefix=CHK-FOPENMP-MCPU-TO-SAME-TRIPLE %s
61 // CHK-FOPENMP-MCPU-TO-SAME-TRIPLE: clang{{.*}} "-target-cpu" "pwr7" {{.*}}"-fopenmp-is-device"
63 /// ##########################################################################
65 /// Check -march=pwr7 is NOT passed to nvptx64-nvidia-cuda.
66 // RUN: %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda --target=powerpc64le-ibm-linux-gnu -march=pwr7 %s 2>&1 \
67 // RUN: | FileCheck -check-prefix=CHK-FOPENMP-MARCH-TO-GPU %s
69 // CHK-FOPENMP-MARCH-TO-GPU-NOT: clang{{.*}} "-target-cpu" "pwr7" {{.*}}"-fopenmp-is-device"
71 /// ###########################################################################
73 /// Check -march=pwr7 is NOT passed to x86_64-unknown-linux-gnu.
74 // RUN: %clang -### -fopenmp=libomp -fopenmp-targets=x86_64-unknown-linux-gnu --target=powerpc64le-ibm-linux-gnu -march=pwr7 %s 2>&1 \
75 // RUN: | FileCheck -check-prefix=CHK-FOPENMP-MARCH-TO-X86 %s
77 // CHK-FOPENMP-MARCH-TO-X86-NOT: clang{{.*}} "-target-cpu" "pwr7" {{.*}}"-fopenmp-is-device"
79 /// ###########################################################################
81 /// Check -Xopenmp-target triggers error when multiple triples are used.
82 // RUN: %clang -### -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu,powerpc64le-unknown-linux-gnu -Xopenmp-target -mcpu=pwr8 %s 2>&1 \
83 // RUN: | FileCheck -check-prefix=CHK-FOPENMP-TARGET-AMBIGUOUS-ERROR %s
85 // CHK-FOPENMP-TARGET-AMBIGUOUS-ERROR: clang{{.*}} error: cannot deduce implicit triple value for -Xopenmp-target, specify triple using -Xopenmp-target=<triple>
87 /// ###########################################################################
89 /// Check -Xopenmp-target triggers error when an option requiring arguments is passed to it.
90 // RUN: %clang -### -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu -Xopenmp-target -Xopenmp-target -mcpu=pwr8 %s 2>&1 \
91 // RUN: | FileCheck -check-prefix=CHK-FOPENMP-TARGET-NESTED-ERROR %s
93 // CHK-FOPENMP-TARGET-NESTED-ERROR: clang{{.*}} error: invalid -Xopenmp-target argument: '-Xopenmp-target -Xopenmp-target', options requiring arguments are unsupported
95 /// ###########################################################################
97 /// Check the phases graph when using a single target, different from the host.
98 /// We should have an offload action joining the host compile and device
99 /// preprocessor and another one joining the device linking outputs to the host
101 // RUN: %clang -ccc-print-phases -fopenmp=libomp --target=powerpc64-ibm-linux-gnu \
102 // RUN: -fopenmp-targets=powerpc64-ibm-linux-gnu %s 2>&1 | FileCheck -check-prefix=CHK-PHASES %s
103 // CHK-PHASES: 0: input, "[[INPUT:.+]]", c, (host-openmp)
104 // CHK-PHASES-NEXT: 1: preprocessor, {0}, cpp-output, (host-openmp)
105 // CHK-PHASES-NEXT: 2: compiler, {1}, ir, (host-openmp)
106 // CHK-PHASES-NEXT: 3: input, "[[INPUT]]", c, (device-openmp)
107 // CHK-PHASES-NEXT: 4: preprocessor, {3}, cpp-output, (device-openmp)
108 // CHK-PHASES-NEXT: 5: compiler, {4}, ir, (device-openmp)
109 // CHK-PHASES-NEXT: 6: offload, "host-openmp (powerpc64-ibm-linux-gnu)" {2}, "device-openmp (powerpc64-ibm-linux-gnu)" {5}, ir
110 // CHK-PHASES-NEXT: 7: backend, {6}, assembler, (device-openmp)
111 // CHK-PHASES-NEXT: 8: assembler, {7}, object, (device-openmp)
112 // CHK-PHASES-NEXT: 9: offload, "device-openmp (powerpc64-ibm-linux-gnu)" {8}, object
113 // CHK-PHASES-NEXT: 10: clang-offload-packager, {9}, image, (device-openmp)
114 // CHK-PHASES-NEXT: 11: offload, "host-openmp (powerpc64-ibm-linux-gnu)" {2}, "device-openmp (powerpc64-ibm-linux-gnu)" {10}, ir
115 // CHK-PHASES-NEXT: 12: backend, {11}, assembler, (host-openmp)
116 // CHK-PHASES-NEXT: 13: assembler, {12}, object, (host-openmp)
117 // CHK-PHASES-NEXT: 14: clang-linker-wrapper, {13}, image, (host-openmp)
119 /// ###########################################################################
121 /// Check the phases when using multiple targets and multiple source files
122 // RUN: %clang -ccc-print-phases -lsomelib -fopenmp=libomp --target=powerpc64-ibm-linux-gnu \
123 // RUN: -fopenmp-targets=x86_64-pc-linux-gnu,powerpc64-ibm-linux-gnu %s %s 2>&1 | FileCheck -check-prefix=CHK-PHASES-FILES %s
124 // CHK-PHASES-FILES: 0: input, "somelib", object, (host-openmp)
125 // CHK-PHASES-FILES-NEXT: 1: input, "[[INPUT:.+]]", c, (host-openmp)
126 // CHK-PHASES-FILES-NEXT: 2: preprocessor, {1}, cpp-output, (host-openmp)
127 // CHK-PHASES-FILES-NEXT: 3: compiler, {2}, ir, (host-openmp)
128 // CHK-PHASES-FILES-NEXT: 4: input, "[[INPUT]]", c, (device-openmp)
129 // CHK-PHASES-FILES-NEXT: 5: preprocessor, {4}, cpp-output, (device-openmp)
130 // CHK-PHASES-FILES-NEXT: 6: compiler, {5}, ir, (device-openmp)
131 // CHK-PHASES-FILES-NEXT: 7: offload, "host-openmp (powerpc64-ibm-linux-gnu)" {3}, "device-openmp (x86_64-pc-linux-gnu)" {6}, ir
132 // CHK-PHASES-FILES-NEXT: 8: backend, {7}, assembler, (device-openmp)
133 // CHK-PHASES-FILES-NEXT: 9: assembler, {8}, object, (device-openmp)
134 // CHK-PHASES-FILES-NEXT: 10: offload, "device-openmp (x86_64-pc-linux-gnu)" {9}, object
135 // CHK-PHASES-FILES-NEXT: 11: input, "[[INPUT]]", c, (device-openmp)
136 // CHK-PHASES-FILES-NEXT: 12: preprocessor, {11}, cpp-output, (device-openmp)
137 // CHK-PHASES-FILES-NEXT: 13: compiler, {12}, ir, (device-openmp)
138 // CHK-PHASES-FILES-NEXT: 14: offload, "host-openmp (powerpc64-ibm-linux-gnu)" {3}, "device-openmp (powerpc64-ibm-linux-gnu)" {13}, ir
139 // CHK-PHASES-FILES-NEXT: 15: backend, {14}, assembler, (device-openmp)
140 // CHK-PHASES-FILES-NEXT: 16: assembler, {15}, object, (device-openmp)
141 // CHK-PHASES-FILES-NEXT: 17: offload, "device-openmp (powerpc64-ibm-linux-gnu)" {16}, object
142 // CHK-PHASES-FILES-NEXT: 18: clang-offload-packager, {10, 17}, image, (device-openmp)
143 // CHK-PHASES-FILES-NEXT: 19: offload, "host-openmp (powerpc64-ibm-linux-gnu)" {3}, "device-openmp (powerpc64-ibm-linux-gnu)" {18}, ir
144 // CHK-PHASES-FILES-NEXT: 20: backend, {19}, assembler, (host-openmp)
145 // CHK-PHASES-FILES-NEXT: 21: assembler, {20}, object, (host-openmp)
146 // CHK-PHASES-FILES-NEXT: 22: input, "[[INPUT]]", c, (host-openmp)
147 // CHK-PHASES-FILES-NEXT: 23: preprocessor, {22}, cpp-output, (host-openmp)
148 // CHK-PHASES-FILES-NEXT: 24: compiler, {23}, ir, (host-openmp)
149 // CHK-PHASES-FILES-NEXT: 25: input, "[[INPUT]]", c, (device-openmp)
150 // CHK-PHASES-FILES-NEXT: 26: preprocessor, {25}, cpp-output, (device-openmp)
151 // CHK-PHASES-FILES-NEXT: 27: compiler, {26}, ir, (device-openmp)
152 // CHK-PHASES-FILES-NEXT: 28: offload, "host-openmp (powerpc64-ibm-linux-gnu)" {24}, "device-openmp (x86_64-pc-linux-gnu)" {27}, ir
153 // CHK-PHASES-FILES-NEXT: 29: backend, {28}, assembler, (device-openmp)
154 // CHK-PHASES-FILES-NEXT: 30: assembler, {29}, object, (device-openmp)
155 // CHK-PHASES-FILES-NEXT: 31: offload, "device-openmp (x86_64-pc-linux-gnu)" {30}, object
156 // CHK-PHASES-FILES-NEXT: 32: input, "[[INPUT]]", c, (device-openmp)
157 // CHK-PHASES-FILES-NEXT: 33: preprocessor, {32}, cpp-output, (device-openmp)
158 // CHK-PHASES-FILES-NEXT: 34: compiler, {33}, ir, (device-openmp)
159 // CHK-PHASES-FILES-NEXT: 35: offload, "host-openmp (powerpc64-ibm-linux-gnu)" {24}, "device-openmp (powerpc64-ibm-linux-gnu)" {34}, ir
160 // CHK-PHASES-FILES-NEXT: 36: backend, {35}, assembler, (device-openmp)
161 // CHK-PHASES-FILES-NEXT: 37: assembler, {36}, object, (device-openmp)
162 // CHK-PHASES-FILES-NEXT: 38: offload, "device-openmp (powerpc64-ibm-linux-gnu)" {37}, object
163 // CHK-PHASES-FILES-NEXT: 39: clang-offload-packager, {31, 38}, image, (device-openmp)
164 // CHK-PHASES-FILES-NEXT: 40: offload, "host-openmp (powerpc64-ibm-linux-gnu)" {24}, "device-openmp (powerpc64-ibm-linux-gnu)" {39}, ir
165 // CHK-PHASES-FILES-NEXT: 41: backend, {40}, assembler, (host-openmp)
166 // CHK-PHASES-FILES-NEXT: 42: assembler, {41}, object, (host-openmp)
167 // CHK-PHASES-FILES-NEXT: 43: clang-linker-wrapper, {0, 21, 42}, image, (host-openmp)
169 /// Check -fopenmp-is-device is passed when compiling for the device.
170 // RUN: %clang -### --target=powerpc64le-linux -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu %s 2>&1 \
171 // RUN: | FileCheck -check-prefix=CHK-FOPENMP-IS-DEVICE %s
173 // CHK-FOPENMP-IS-DEVICE: "-cc1"{{.*}} "-aux-triple" "powerpc64le-unknown-linux" {{.*}}"-fopenmp-is-device" "-fopenmp-host-ir-file-path" {{.*}}.c"
175 /// Check arguments to the linker wrapper
176 // RUN: %clang -### --target=powerpc64le-linux -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu %s 2>&1 \
177 // RUN: | FileCheck -check-prefix=CHK-NEW-DRIVER %s
179 // CHK-NEW-DRIVER: clang-linker-wrapper{{.*}}"--host-triple=powerpc64le-unknown-linux"{{.*}}--{{.*}}"-lomp"{{.*}}"-lomptarget"
181 /// Check arguments to the linker wrapper
182 // RUN: %clang -### --target=powerpc64le-linux -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu -g %s 2>&1 \
183 // RUN: | FileCheck -check-prefix=CHK-NEW-DRIVER-DEBUG %s
185 // CHK-NEW-DRIVER-DEBUG: clang-linker-wrapper{{.*}} "--device-debug"
187 /// Check arguments to the linker wrapper
188 // RUN: %clang -### --target=powerpc64le-linux -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu \
189 // RUN: -mllvm -abc %s 2>&1 | FileCheck -check-prefix=CHK-NEW-DRIVER-MLLVM %s
191 // CHK-NEW-DRIVER-MLLVM: clang-linker-wrapper{{.*}} "-abc"
194 // Ensure that we generate the correct bindings for '-fsyntax-only' for OpenMP.
196 // RUN: %clang -### --target=powerpc64le-linux -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu \
197 // RUN: -fsyntax-only -ccc-print-bindings %s 2>&1 | FileCheck -check-prefix=CHK-SYNTAX-ONLY %s
198 // CHK-SYNTAX-ONLY: # "powerpc64le-ibm-linux-gnu" - "clang", inputs: ["[[INPUT:.+]]"], output: (nothing)
199 // CHK-SYNTAX-ONLY: # "powerpc64le-unknown-linux" - "clang", inputs: ["[[INPUT]]", (nothing)], output: (nothing)
202 // Ensure that we can generate the correct arguments for '-fsyntax-only' for
205 // RUN: %clang -### --target=powerpc64le-linux -fopenmp=libomp -fopenmp-targets=powerpc64le-ibm-linux-gnu \
206 // RUN: -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHK-SYNTAX-ONLY-ARGS %s
207 // CHK-SYNTAX-ONLY-ARGS: "-cc1" "-triple" "powerpc64le-ibm-linux-gnu"{{.*}}"-fsyntax-only"
208 // CHK-SYNTAX-ONLY-ARGS: "-cc1" "-triple" "powerpc64le-unknown-linux"{{.*}}"-fsyntax-only"