Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions clang/include/clang/Driver/ToolChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,9 @@ class ToolChain {
return nullptr;
}

/// TranslateOffloadTargetArgs - Create a new derived argument list for
/// that contains the Offload target specific flags passed via
/// -Xopenmp-target -opt=val OR -Xopenmp-target=<triple> -opt=val
/// TranslateOffloadTargetArgs - Create a new derived argument list that
/// contains the Offload target specific flags passed via -Xopenmp-target
/// -opt=val OR -Xopenmp-target=<triple> -opt=val
/// Also handles -Xsycl-target OR -Xsycl-target=<triple>
virtual llvm::opt::DerivedArgList *TranslateOffloadTargetArgs(
const llvm::opt::DerivedArgList &Args, bool SameTripleAsHost,
Expand Down
23 changes: 13 additions & 10 deletions clang/lib/Driver/ToolChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1640,6 +1640,8 @@ llvm::opt::DerivedArgList *ToolChain::TranslateOffloadTargetArgs(
DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs());
const OptTable &Opts = getDriver().getOpts();
bool Modified = false;
auto &Triple = getTriple();
const bool IsSYCL = DeviceOffloadKind == Action::OFK_SYCL;

// Handle -Xopenmp-target and -Xsycl-target-frontend flags
for (auto *A : Args) {
Expand All @@ -1654,13 +1656,15 @@ llvm::opt::DerivedArgList *ToolChain::TranslateOffloadTargetArgs(
// to correctly set metadata in intermediate files.
if (SameTripleAsHost ||
A->getOption().matches(options::OPT_mcode_object_version_EQ) ||
(getTriple().getArch() == llvm::Triple::amdgcn &&
DeviceOffloadKind != Action::OFK_SYCL)) {
(Triple.getArch() == llvm::Triple::amdgcn && !IsSYCL)) {
DAL->append(A);
continue;
}
// SPIR/SPIR-V special case for -mlong-double
if (getTriple().isSPIROrSPIRV() &&
// SPIR/SPIR-V and SYCL GPU special case for -mlong-double. We have to
// make sure that if user requested 64bit long double it is honored on
// both host and device.
if ((Triple.isSPIROrSPIRV() ||
(IsSYCL && (Triple.isAMDGCN() || Triple.isNVPTX()))) &&
A->getOption().matches(options::OPT_LongDouble_Group)) {
DAL->append(A);
continue;
Expand All @@ -1683,7 +1687,7 @@ llvm::opt::DerivedArgList *ToolChain::TranslateOffloadTargetArgs(
// is similar, can be improved
if (DeviceOffloadKind == Action::OFK_OpenMP) {
XOffloadTargetNoTriple =
A->getOption().matches(options::OPT_Xopenmp_target);
A->getOption().matches(options::OPT_Xopenmp_target);
if (A->getOption().matches(options::OPT_Xopenmp_target_EQ)) {
llvm::Triple TT(getOpenMPTriple(A->getValue(0)));

Expand All @@ -1699,12 +1703,12 @@ llvm::opt::DerivedArgList *ToolChain::TranslateOffloadTargetArgs(
DAL->append(A);
continue;
}
} else if (DeviceOffloadKind == Action::OFK_SYCL) {
} else if (IsSYCL) {
XOffloadTargetNoTriple =
A->getOption().matches(options::OPT_Xsycl_frontend);
A->getOption().matches(options::OPT_Xsycl_frontend);
if (A->getOption().matches(options::OPT_Xsycl_frontend_EQ)) {
// Passing device args: -Xsycl-target-frontend=<triple> -opt=val.
if (getDriver().getSYCLDeviceTriple(A->getValue(0)) == getTriple())
if (getDriver().getSYCLDeviceTriple(A->getValue(0)) == Triple)
Index = Args.getBaseArgs().MakeIndex(A->getValue(1));
else
continue;
Expand Down Expand Up @@ -1744,8 +1748,7 @@ llvm::opt::DerivedArgList *ToolChain::TranslateOffloadTargetArgs(
getDriver().Diag(diag::err_drv_Xopenmp_target_missing_triple);
continue;
}
if (DeviceOffloadKind == Action::OFK_SYCL &&
!SingleTargetTripleCount(options::OPT_fsycl_targets_EQ)) {
if (IsSYCL && !SingleTargetTripleCount(options::OPT_fsycl_targets_EQ)) {
getDriver().Diag(diag::err_drv_Xsycl_target_missing_triple)
<< A->getSpelling();
continue;
Expand Down
5 changes: 5 additions & 0 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6751,6 +6751,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
(A->getOption().getID() == options::OPT_mlong_double_64))
// Only allow for -mlong-double-64 for SPIR/SPIR-V
A->render(Args, CmdArgs);
else if ((IsSYCL &&
(TC.getTriple().isAMDGCN() || TC.getTriple().isNVPTX())) &&
(A->getOption().getID() == options::OPT_mlong_double_64))
// similarly, allow 64bit long double for SYCL GPU targets
A->render(Args, CmdArgs);
else if (TC.getTriple().isPPC() &&
(A->getOption().getID() != options::OPT_mlong_double_80))
A->render(Args, CmdArgs);
Expand Down
8 changes: 8 additions & 0 deletions clang/test/Driver/mlong-double-128.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@
// RUN: not %clang --target=powerpc -c -### %s -mlong-double-80 2>&1 | FileCheck --check-prefix=ERR2 %s
// RUN: not %clang --target=spir64-unknown-unknown -c -### %s -mlong-double-128 2>&1 | FileCheck --check-prefix=ERR3 %s
// RUN: not %clang --target=spir64-unknown-unknown -c -### %s -mlong-double-80 2>&1 | FileCheck --check-prefix=ERR4 %s
// RUN: not %clang --target=nvptx64-nvidia-cuda -c -### %s -mlong-double-128 2>&1 | FileCheck --check-prefix=ERR5 %s
// RUN: not %clang --target=nvptx64-nvidia-cuda -c -### %s -mlong-double-80 2>&1 | FileCheck --check-prefix=ERR6 %s
// RUN: not %clang --target=amd_gpu_gfx1031 -c -### %s -mlong-double-128 2>&1 | FileCheck --check-prefix=ERR7 %s
// RUN: not %clang --target=amd_gpu_gfx1031 -c -### %s -mlong-double-80 2>&1 | FileCheck --check-prefix=ERR8 %s

// ERR: error: unsupported option '-mlong-double-128' for target 'aarch64'
// ERR2: error: unsupported option '-mlong-double-80' for target 'powerpc'
// ERR3: error: unsupported option '-mlong-double-128' for target 'spir64-unknown-unknown'
// ERR4: error: unsupported option '-mlong-double-80' for target 'spir64-unknown-unknown'
// ERR5: error: unsupported option '-mlong-double-128' for target 'nvptx64-nvidia-cuda'
// ERR6: error: unsupported option '-mlong-double-80' for target 'nvptx64-nvidia-cuda'
// ERR7: error: unsupported option '-mlong-double-128' for target 'amd_gpu_gfx1031'
// ERR8: error: unsupported option '-mlong-double-80' for target 'amd_gpu_gfx1031'
18 changes: 17 additions & 1 deletion clang/test/Driver/sycl-mlong-double.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,27 @@
// CHECK: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu"
// CHECK-SAME: "-mlong-double-64"

/// -mlong-double-128 and -mlong-double-80 are not supported for spir64.
/// -mlong-double-128 and -mlong-double-80 are not supported for spir64, or SYCL GPU targets.
// RUN: not %clangxx -c -fsycl -mlong-double-128 -target x86_64-unknown-linux-gnu %s -### 2>&1 | FileCheck --check-prefix=CHECK-128 %s
// CHECK-128: error: unsupported option '-mlong-double-128' for target 'spir64-unknown-unknown'
// CHECK-128-NOT: clang{{.*}} "-triple" "-spir64-unknown-unknown" {{.*}} "-mlong-double-128"

// RUN: not %clangxx -c -fsycl -mlong-double-80 -target x86_64-unknown-linux-gnu %s -### 2>&1 | FileCheck --check-prefix=CHECK-80 %s
// CHECK-80: error: unsupported option '-mlong-double-80' for target 'spir64-unknown-unknown'
// CHECK-80-NOT: clang{{.*}} "-triple" "-spir64-unknown-unknown" {{.*}} "-mlong-double-80"

// RUN: not %clangxx -c -fsycl -mlong-double-128 --target=x86_64-unknown-linux-gnu -fsycl-targets=amd_gpu_gfx1031 %s -### 2>&1 | FileCheck --check-prefix=CHECK-128-AMD %s
// CHECK-128-AMD: error: unsupported option '-mlong-double-128' for target 'amdgcn-amd-amdhsa'
// CHECK-128-AMD-NOT: clang{{.*}} "-triple" "-amd_gpu_gfx1031" {{.*}} "-mlong-double-128"

// RUN: not %clangxx -c -fsycl -mlong-double-80 --target=x86_64-unknown-linux-gnu -fsycl-targets=amd_gpu_gfx1031 %s -### 2>&1 | FileCheck --check-prefix=CHECK-80-AMD %s
// CHECK-80-AMD: error: unsupported option '-mlong-double-80' for target 'amdgcn-amd-amdhsa'
// CHECK-80-AMD-NOT: clang{{.*}} "-triple" "-amd_gpu_gfx1031" {{.*}} "-mlong-double-80"

// RUN: not %clangxx -c -fsycl -mlong-double-128 --target=x86_64-unknown-linux-gnu -fsycl-targets=nvptx64-nvidia-cuda %s -### 2>&1 | FileCheck --check-prefix=CHECK-128-NVPTX %s
// CHECK-128-NVPTX: error: unsupported option '-mlong-double-128' for target 'nvptx64-nvidia-cuda'
// CHECK-128-NVPTX-NOT: clang{{.*}} "-triple" "-nvptx64-nvidia-cuda" {{.*}} "-mlong-double-128"

// RUN: not %clangxx -c -fsycl -mlong-double-80 --target=x86_64-unknown-linux-gnu -fsycl-targets=nvptx64-nvidia-cuda %s -### 2>&1 | FileCheck --check-prefix=CHECK-80-NVPTX %s
// CHECK-80-NVPTX: error: unsupported option '-mlong-double-80' for target 'nvptx64-nvidia-cuda'
// CHECK-80-NVPTX-NOT: clang{{.*}} "-triple" "-nvptx64-nvidia-cuda" {{.*}} "-mlong-double-80"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all of these, I believe the expected option syntax is to use --target=x86_64-unknown-linux-gnu -fsycl-targets=nvptx64-nvidia-cuda. Use of --target=<triple> is preferred over -target <triple> moving forward.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I've only updated tests that I've added in this patch.

As a side note, it seems strange that sycl target triple option gets only one hyphen, both seem to be following the same pattern of:

hyphen[hyphen]target_name=triple

but end up spelled out differently:

--target=<triple>

vs:

-fsycl-targets=<triple>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use of --target=<triple> is a general option. There are some similar options for offloading that use the double hyphen syntax which are also general in nature for offloading. Consider -fsycl-targets=<target> to be in a similar usage family as -fopenmp-targets=<target>. Moving forward when looking at the new offloading model approach, use of --offload-arch=<arch> would be used to target other devices which better fits within the double hyphen syntax.

Loading