Skip to content

Commit f4d01cd

Browse files
authored
[Driver][SYCL] Update default SPIR device arch to correlate with host (#4936)
The default target arch for the device compilation when using -fsycl should match the target arch of the host compilation. x86_64 (64-bit) -> spir64 i686 (32-bit) -> spir Adjust locations where this is set (offload and device-only compiles) and modify the corresponding tests.
1 parent 3e8ed13 commit f4d01cd

File tree

4 files changed

+54
-39
lines changed

4 files changed

+54
-39
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,12 @@ static bool isValidSYCLTriple(llvm::Triple T) {
688688
return true;
689689
}
690690

691+
static const char *getDefaultSYCLArch(Compilation &C) {
692+
if (C.getDefaultToolChain().getTriple().getArch() == llvm::Triple::x86)
693+
return "spir";
694+
return "spir64";
695+
}
696+
691697
static bool addSYCLDefaultTriple(Compilation &C,
692698
SmallVectorImpl<llvm::Triple> &SYCLTriples) {
693699
/// Returns true if a triple is added to SYCLTriples, false otherwise
@@ -702,7 +708,8 @@ static bool addSYCLDefaultTriple(Compilation &C,
702708
return false;
703709
}
704710
// Add the default triple as it was not found.
705-
llvm::Triple DefaultTriple = C.getDriver().MakeSYCLDeviceTriple("spir64");
711+
llvm::Triple DefaultTriple =
712+
C.getDriver().MakeSYCLDeviceTriple(getDefaultSYCLArch(C));
706713
SYCLTriples.insert(SYCLTriples.begin(), DefaultTriple);
707714
return true;
708715
}
@@ -1018,16 +1025,11 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
10181025
// If -fsycl is supplied without -fsycl-*targets we will assume SPIR-V
10191026
// unless -fintelfpga is supplied, which uses SPIR-V with fpga AOT.
10201027
// For -fsycl-device-only, we also setup the implied triple as needed.
1021-
StringRef SYCLTargetArch;
1022-
if (C.getInputArgs().hasArg(options::OPT_fsycl_device_only))
1023-
if (C.getDefaultToolChain().getTriple().getArch() == llvm::Triple::x86)
1024-
SYCLTargetArch = "spir";
1025-
else
1026-
SYCLTargetArch = "spir64";
1027-
else if (HasValidSYCLRuntime)
1028-
// Triple for -fintelfpga is spir64_fpga.
1029-
SYCLTargetArch = SYCLfpga ? "spir64_fpga" : "spir64";
1030-
if (!SYCLTargetArch.empty()) {
1028+
if (HasValidSYCLRuntime) {
1029+
StringRef SYCLTargetArch = getDefaultSYCLArch(C);
1030+
if (SYCLfpga)
1031+
// Triple for -fintelfpga is spir64_fpga.
1032+
SYCLTargetArch = "spir64_fpga";
10311033
UniqueSYCLTriplesVec.push_back(MakeSYCLDeviceTriple(SYCLTargetArch));
10321034
addSYCLDefaultTriple(C, UniqueSYCLTriplesVec);
10331035
}
@@ -2861,7 +2863,7 @@ static bool hasSYCLDefaultSection(Compilation &C, const StringRef &File) {
28612863
if (!(IsArchive || isObjectFile(File.str())))
28622864
return false;
28632865

2864-
llvm::Triple TT(C.getDriver().MakeSYCLDeviceTriple("spir64"));
2866+
llvm::Triple TT(C.getDriver().MakeSYCLDeviceTriple(getDefaultSYCLArch(C)));
28652867
// Checking uses -check-section option with the input file, no output
28662868
// file and the target triple being looked for.
28672869
const char *Targets =
@@ -4949,7 +4951,8 @@ class OffloadingActionBuilder final {
49494951
// -fsycl is provided without -fsycl-*targets.
49504952
bool SYCLfpga = C.getInputArgs().hasArg(options::OPT_fintelfpga);
49514953
// -fsycl -fintelfpga implies spir64_fpga
4952-
const char *SYCLTargetArch = SYCLfpga ? "spir64_fpga" : "spir64";
4954+
const char *SYCLTargetArch =
4955+
SYCLfpga ? "spir64_fpga" : getDefaultSYCLArch(C);
49534956
llvm::Triple TT = C.getDriver().MakeSYCLDeviceTriple(SYCLTargetArch);
49544957
auto TCIt = llvm::find_if(
49554958
ToolChains, [&](auto &TC) { return TT == TC->getTriple(); });

clang/test/Driver/sycl-offload.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@
412412
// RUN: touch %t.o
413413
// RUN: %clang -### -ccc-print-phases -target x86_64-unknown-linux-gnu -fsycl -o %t.out -fsycl-link-targets=spir64-unknown-unknown %t.o 2>&1 \
414414
// RUN: | FileCheck -check-prefix=CHK-LINK-TARGETS-UB %s
415-
// RUN: %clang_cl -### -ccc-print-phases -fsycl -o %t.out -fsycl-link-targets=spir64-unknown-unknown %t.o 2>&1 \
415+
// RUN: %clang_cl -### -ccc-print-phases --target=x86_64-pc-windows-msvc -fsycl -o %t.out -fsycl-link-targets=spir64-unknown-unknown %t.o 2>&1 \
416416
// RUN: | FileCheck -check-prefix=CHK-LINK-TARGETS-UB %s
417417
// CHK-LINK-TARGETS-UB: 0: input, "[[INPUT:.+\.o]]", object
418418
// CHK-LINK-TARGETS-UB: 1: clang-offload-unbundler, {0}, object
@@ -428,7 +428,7 @@
428428
// RUN: touch %t-c.o
429429
// RUN: %clang -### -ccc-print-phases -target x86_64-unknown-linux-gnu -fsycl -o %t.out -fsycl-link-targets=spir64-unknown-unknown %t-a.o %t-b.o %t-c.o 2>&1 \
430430
// RUN: | FileCheck -check-prefix=CHK-LINK-TARGETS-UB2 %s
431-
// RUN: %clang_cl -### -ccc-print-phases -fsycl -o %t.out -fsycl-link-targets=spir64-unknown-unknown %t-a.o %t-b.o %t-c.o 2>&1 \
431+
// RUN: %clang_cl -### -ccc-print-phases --target=x86_64-pc-windws-msvc -fsycl -o %t.out -fsycl-link-targets=spir64-unknown-unknown %t-a.o %t-b.o %t-c.o 2>&1 \
432432
// RUN: | FileCheck -check-prefix=CHK-LINK-TARGETS-UB2 %s
433433
// CHK-LINK-TARGETS-UB2: 0: input, "[[INPUT:.+\a.o]]", object
434434
// CHK-LINK-TARGETS-UB2: 1: clang-offload-unbundler, {0}, object
@@ -445,7 +445,7 @@
445445
/// Check -fsycl-link-targets=<triple> behaviors from source
446446
// RUN: %clang -### -ccc-print-phases -target x86_64-unknown-linux-gnu -fsycl -o %t.out -fsycl-link-targets=spir64-unknown-unknown %s 2>&1 \
447447
// RUN: | FileCheck -check-prefix=CHK-LINK-TARGETS %s -DSUBARCH=
448-
// RUN: %clang_cl -### -ccc-print-phases -fsycl -o %t.out -fsycl-link-targets=spir64-unknown-unknown %s 2>&1 \
448+
// RUN: %clang_cl -### -ccc-print-phases --target=x86_64-pc-windows-msvc -fsycl -o %t.out -fsycl-link-targets=spir64-unknown-unknown %s 2>&1 \
449449
// RUN: | FileCheck -check-prefix=CHK-LINK-TARGETS %s -DSUBARCH=
450450
// RUN: %clang -### -ccc-print-phases -target x86_64-unknown-linux-gnu -fsycl -o %t.out -fsycl-link-targets=spir64_gen-unknown-unknown %s 2>&1 \
451451
// RUN: | FileCheck -check-prefix=CHK-LINK-TARGETS %s -DSUBARCH=_gen
@@ -466,7 +466,7 @@
466466
// RUN: touch %t.o
467467
// RUN: %clang -### -ccc-print-phases -target x86_64-unknown-linux-gnu -fsycl -o %t.out -fsycl-link -fno-sycl-device-lib=all %t.o 2>&1 \
468468
// RUN: | FileCheck -check-prefix=CHK-LINK-UB %s
469-
// RUN: %clang_cl -### -ccc-print-phases -fsycl -o %t.out -fsycl-link -fno-sycl-device-lib=all %t.o 2>&1 \
469+
// RUN: %clang_cl -### -ccc-print-phases --target=x86_64-pc-windows-msvc -fsycl -o %t.out -fsycl-link -fno-sycl-device-lib=all %t.o 2>&1 \
470470
// RUN: | FileCheck -check-prefix=CHK-LINK-UB %s
471471
// CHK-LINK-UB: 0: input, "[[INPUT:.+\.o]]", object
472472
// CHK-LINK-UB: 1: clang-offload-unbundler, {0}, object
@@ -481,7 +481,7 @@
481481
/// Check -fsycl-link behaviors from source
482482
// RUN: %clang -### -ccc-print-phases -target x86_64-unknown-linux-gnu -fsycl -o %t.out -fsycl-link -fno-sycl-device-lib=all %s 2>&1 \
483483
// RUN: | FileCheck -check-prefix=CHK-LINK %s
484-
// RUN: %clang_cl -### -ccc-print-phases -fsycl -o %t.out -fsycl-link -fno-sycl-device-lib=all %s 2>&1 \
484+
// RUN: %clang_cl -### -ccc-print-phases --target=x86_64-pc-windows-msvc -fsycl -o %t.out -fsycl-link -fno-sycl-device-lib=all %s 2>&1 \
485485
// RUN: | FileCheck -check-prefix=CHK-LINK %s
486486
// CHK-LINK: 0: input, "[[INPUT:.+\.c]]", c++, (device-sycl)
487487
// CHK-LINK: 1: preprocessor, {0}, c++-cpp-output, (device-sycl)

clang/test/Driver/sycl-offload.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@
9595
// NO_IMPLIED_DEVICE_OPT-NOT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown"{{.*}} "-check-section"
9696
// NO_IMPLIED_DEVICE_OPT-NOT: clang-offload-bundler{{.*}} "-targets={{.*}}spir64-unknown-unknown{{.*}}" "-unbundle"
9797

98-
// RUN: %clangxx -### -fsycl -fsycl-targets=spir64_x86_64 %t_empty.o %s 2>&1 \
98+
// RUN: %clangxx -### -fsycl -target x86_64-unknown-linux-gnu -fsycl-targets=spir64_x86_64 %t_empty.o %s 2>&1 \
9999
// RUN: | FileCheck -check-prefix NO_IMPLIED_DEVICE %s
100-
// RUN: %clangxx -### -fsycl -fsycl-targets=spir64_fpga %t_empty.o %s 2>&1 \
100+
// RUN: %clangxx -### -fsycl -target x86_64-unknown-linux-gnu -fsycl-targets=spir64_fpga %t_empty.o %s 2>&1 \
101101
// RUN: | FileCheck -check-prefix NO_IMPLIED_DEVICE %s
102-
// RUN: %clangxx -### -fsycl -fsycl-targets=spir64_gen %t_empty.o %s 2>&1 \
102+
// RUN: %clangxx -### -fsycl -target x86_64-unknown-linux-gnu -fsycl-targets=spir64_gen %t_empty.o %s 2>&1 \
103103
// RUN: | FileCheck -check-prefix NO_IMPLIED_DEVICE %s
104-
// RUN: %clangxx -### -fsycl -fintelfpga %t_empty.o %s 2>&1 \
104+
// RUN: %clangxx -### -fsycl -target x86_64-unknown-linux-gnu -fintelfpga %t_empty.o %s 2>&1 \
105105
// RUN: | FileCheck -check-prefix NO_IMPLIED_DEVICE %s
106106
// NO_IMPLIED_DEVICE: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown"{{.*}} "-check-section"
107107
// NO_IMPLIED_DEVICE-NOT: clang-offload-bundler{{.*}} "-targets={{.*}}spir64-unknown-unknown{{.*}}" "-unbundle"

clang/test/Driver/sycl.c

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,46 @@
2828
// DISABLED-NOT: "-sycl-std={{.*}}"
2929
// DISABLED-NOT: "-fsycl-std-layout-kernel-params"
3030

31-
// RUN: %clangxx -fsycl -fsycl-targets=spir64-unknown-unknown-sycldevice,nvptx64-nvidia-cuda-sycldevice -fno-sycl-libspirv -nocudalib -c %s 2>&1 | FileCheck %s --check-prefix=CHECK_WARNING
31+
// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl -fsycl-targets=spir64-unknown-unknown-sycldevice,nvptx64-nvidia-cuda-sycldevice -fno-sycl-libspirv -nocudalib -c %s 2>&1 | FileCheck %s --check-prefix=CHECK_WARNING
3232
// CHECK_WARNING: argument 'spir64-unknown-unknown-sycldevice' is deprecated, use 'spir64' instead
3333
// CHECK_WARNING: argument 'nvptx64-nvidia-cuda-sycldevice' is deprecated, use 'nvptx64-nvidia-cuda' instead
3434

35-
// RUN: %clang -### -fsycl-device-only -c %s 2>&1 | FileCheck %s --check-prefix=DEFAULT
36-
// RUN: %clang -### -fsycl-device-only %s 2>&1 | FileCheck %s --check-prefix=DEFAULT
37-
// RUN: %clang -### -fsycl-device-only -S %s 2>&1 | FileCheck %s --check-prefix=TEXTUAL
38-
// RUN: %clang -### -fsycl-device-only -fsycl %s 2>&1 | FileCheck %s --check-prefix=DEFAULT
39-
// RUN: %clang -### -fsycl-device-only -fno-sycl-use-bitcode -c %s 2>&1 | FileCheck %s --check-prefix=NO-BITCODE
40-
// RUN: %clang -### -target spir64-unknown-linux -c -emit-llvm %s 2>&1 | FileCheck %s --check-prefix=TARGET
41-
// RUN: %clang -### -fsycl-device-only -c -emit-llvm %s 2>&1 | FileCheck %s --check-prefix=COMBINED
42-
// RUN: %clangxx -### -fsycl-device-only %s 2>&1 | FileCheck %s --check-prefix=DEFAULT
43-
// RUN: %clang_cl -### -fsycl-device-only %s 2>&1 | FileCheck %s --check-prefix=DEFAULT
44-
// RUN: %clangxx -### -fsycl-device-only -fno-sycl-unnamed-lambda %s 2>&1 | FileCheck %s --check-prefix=CHECK-NOT-LAMBDA
45-
// RUN: %clang_cl -### -fsycl-device-only -fno-sycl-unnamed-lambda %s 2>&1 | FileCheck %s --check-prefix=CHECK-NOT-LAMBDA
35+
// RUN: %clang -### -target x86_64-unknown-linux-gnu -fsycl-device-only -c %s 2>&1 | FileCheck %s --check-prefix=DEFAULT -DSPIRARCH=spir64
36+
// RUN: %clang -### -target x86_64-unknown-linux-gnu -fsycl-device-only %s 2>&1 | FileCheck %s --check-prefix=DEFAULT -DSPIRARCH=spir64
37+
// RUN: %clang -### -target x86_64-unknown-linux-gnu -fsycl-device-only -S %s 2>&1 | FileCheck %s --check-prefix=TEXTUAL -DSPIRARCH=spir64
38+
// RUN: %clang -### -target x86_64-unknown-linux-gnu -fsycl-device-only -fsycl %s 2>&1 | FileCheck %s --check-prefix=DEFAULT -DSPIRARCH=spir64
39+
// RUN: %clang -### -target x86_64-unknown-linux-gnu -fsycl-device-only -fno-sycl-use-bitcode -c %s 2>&1 | FileCheck %s --check-prefix=NO-BITCODE -DSPIRARCH=spir64
40+
// RUN: %clang -### -target spir64-unknown-linux -c -emit-llvm %s 2>&1 | FileCheck %s --check-prefix=TARGET -DSPIRARCH=spir64
41+
// RUN: %clang -### -target x86_64-unknown-linux-gnu -fsycl-device-only -c -emit-llvm %s 2>&1 | FileCheck %s --check-prefix=COMBINED -DSPIRARCH=spir64
42+
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl-device-only %s 2>&1 | FileCheck %s --check-prefix=DEFAULT -DSPIRARCH=spir64
43+
// RUN: %clang_cl -### --target=x86_64-pc-windows-msvc -fsycl-device-only %s 2>&1 | FileCheck %s --check-prefix=DEFAULT -DSPIRARCH=spir64
44+
45+
/// 32-bit target checks
46+
// RUN: %clang -### -target i386-unknown-linux-gnu -fsycl-device-only -c %s 2>&1 | FileCheck %s --check-prefix=DEFAULT -DSPIRARCH=spir
47+
// RUN: %clang -### -target i386-unknown-linux-gnu -fsycl-device-only %s 2>&1 | FileCheck %s --check-prefix=DEFAULT -DSPIRARCH=spir
48+
// RUN: %clang -### -target i386-unknown-linux-gnu -fsycl-device-only -S %s 2>&1 | FileCheck %s --check-prefix=TEXTUAL -DSPIRARCH=spir
49+
// RUN: %clang -### -target i386-unknown-linux-gnu -fsycl-device-only -fsycl %s 2>&1 | FileCheck %s --check-prefix=DEFAULT -DSPIRARCH=spir
50+
// RUN: %clang -### -target i386-unknown-linux-gnu -fsycl-device-only -fno-sycl-use-bitcode -c %s 2>&1 | FileCheck %s --check-prefix=NO-BITCODE -DSPIRARCH=spir
51+
// RUN: %clang -### -target spir-unknown-linux -c -emit-llvm %s 2>&1 | FileCheck %s --check-prefix=TARGET -DSPIRARCH=spir
52+
// RUN: %clang -### -target i386-unknown-linux-gnu -fsycl-device-only -c -emit-llvm %s 2>&1 | FileCheck %s --check-prefix=COMBINED -DSPIRARCH=spir
53+
// RUN: %clangxx -### -target i386-unknown-linux-gnu -fsycl-device-only %s 2>&1 | FileCheck %s --check-prefix=DEFAULT -DSPIRARCH=spir
54+
// RUN: %clang_cl -### --target=i386-pc-windows-msvc -fsycl-device-only %s 2>&1 | FileCheck %s --check-prefix=DEFAULT -DSPIRARCH=spir
4655

47-
// DEFAULT: "-triple" "spir64-unknown-{{.*}}"{{.*}} "-fsycl-is-device"{{.*}} "-sycl-std=2020"{{.*}} "-emit-llvm-bc"
56+
// DEFAULT: "-triple" "[[SPIRARCH]]-unknown-{{.*}}"{{.*}} "-fsycl-is-device"{{.*}} "-sycl-std=2020"{{.*}} "-emit-llvm-bc"
4857
// DEFAULT: "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl"
4958
// DEFAULT: "-internal-isystem" "{{.*lib.*clang.*include}}"
5059
// DEFAULT: "-std=c++17"
5160
// DEFAULT-NOT: "{{.*}}llvm-spirv"{{.*}}
5261
// DEFAULT-NOT: "-std=c++11"
5362
// DEFAULT-NOT: "-std=c++14"
54-
// NO-BITCODE: "-triple" "spir64-unknown-{{.*}}"{{.*}} "-fsycl-is-device"{{.*}} "-emit-llvm-bc"
63+
// NO-BITCODE: "-triple" "[[SPIRARCH]]-unknown-{{.*}}"{{.*}} "-fsycl-is-device"{{.*}} "-emit-llvm-bc"
5564
// NO-BITCODE: "{{.*}}llvm-spirv"{{.*}}
56-
// TARGET: "-triple" "spir64-unknown-linux"{{.*}} "-emit-llvm-bc"
57-
// COMBINED: "-triple" "spir64-unknown-{{.*}}" "-fsycl-is-device"{{.*}} "-emit-llvm-bc"
58-
// TEXTUAL: "-triple" "spir64-unknown-{{.*}}" "-fsycl-is-device"{{.*}} "-emit-llvm"
65+
// TARGET: "-triple" "[[SPIRARCH]]-unknown-linux"{{.*}} "-emit-llvm-bc"
66+
// COMBINED: "-triple" "[[SPIRARCH]]-unknown-{{.*}}" "-fsycl-is-device"{{.*}} "-emit-llvm-bc"
67+
// TEXTUAL: "-triple" "[[SPIRARCH]]-unknown-{{.*}}" "-fsycl-is-device"{{.*}} "-emit-llvm"
68+
69+
// RUN: %clangxx -### -fsycl-device-only -fno-sycl-unnamed-lambda %s 2>&1 | FileCheck %s --check-prefix=CHECK-NOT-LAMBDA
70+
// RUN: %clang_cl -### -fsycl-device-only -fno-sycl-unnamed-lambda %s 2>&1 | FileCheck %s --check-prefix=CHECK-NOT-LAMBDA
5971
// CHECK-NOT-LAMBDA: "-fno-sycl-unnamed-lambda"
6072

6173
/// -fsycl-device-only triple checks

0 commit comments

Comments
 (0)