Skip to content

Commit

Permalink
[SYCL] [NATIVECPU] Driver fix to stop defining NativeCPU macro for ot…
Browse files Browse the repository at this point in the history
…her SYCL targets (#12783)

This PR fixes an issue in the driver where the compiler option to define
the Native CPU macros is incorrectly passed to device compiler
invocations for other sycl targets.
  • Loading branch information
uwedolinsky authored Feb 29, 2024
1 parent 0a2e5ad commit 7a71960
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5096,7 +5096,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
bool IsFPGASYCLOffloadDevice =
IsSYCLOffloadDevice &&
Triple.getSubArch() == llvm::Triple::SPIRSubArch_fpga;
const bool IsSYCLNativeCPU = isSYCLNativeCPU(TC, C.getDefaultToolChain());
const bool IsSYCLNativeCPU = isSYCLNativeCPU(TC);

// Perform the SYCL host compilation using an external compiler if the user
// requested.
Expand Down Expand Up @@ -9851,7 +9851,7 @@ void OffloadWrapper::ConstructJob(Compilation &C, const JobAction &JA,
TargetTripleOpt = ("llvm_" + TargetTripleOpt).str();
}

const bool IsSYCLNativeCPU = isSYCLNativeCPU(TC, C.getDefaultToolChain());
const bool IsSYCLNativeCPU = isSYCLNativeCPU(TC);
if (IsSYCLNativeCPU) {
TargetTripleOpt = "native_cpu";
}
Expand Down Expand Up @@ -10384,7 +10384,7 @@ void SYCLPostLink::ConstructJob(Compilation &C, const JobAction &JA,
if (!TCArgs.hasFlag(options::OPT_fno_sycl_remove_unused_external_funcs,
options::OPT_fsycl_remove_unused_external_funcs, false) &&
!T.isNVPTX() && !T.isAMDGPU() &&
!isSYCLNativeCPU(getToolChain(), C.getDefaultToolChain()))
!isSYCLNativeCPU(getToolChain()))
addArgs(CmdArgs, TCArgs, {"-emit-only-kernels-as-entry-points"});

// OPT_fsycl_device_code_split is not checked as it is an alias to
Expand Down
3 changes: 1 addition & 2 deletions clang/lib/Driver/ToolChains/SYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,7 @@ const char *SYCL::Linker::constructLLVMLinkCommand(
// instead of the original object.
if (JA.isDeviceOffloading(Action::OFK_SYCL)) {
bool IsRDC = !shouldDoPerObjectFileLinking(C);
const bool IsSYCLNativeCPU = isSYCLNativeCPU(
this->getToolChain(), *C.getSingleOffloadToolChain<Action::OFK_Host>());
const bool IsSYCLNativeCPU = isSYCLNativeCPU(this->getToolChain());
auto isNoRDCDeviceCodeLink = [&](const InputInfo &II) {
if (IsRDC)
return false;
Expand Down
9 changes: 5 additions & 4 deletions clang/lib/Driver/ToolChains/SYCL.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,20 +232,21 @@ class LLVM_LIBRARY_VISIBILITY SYCLToolChain : public ToolChain {

} // end namespace toolchains

template <typename ArgListT> bool isSYCLNativeCPU(const ArgListT &Args) {
inline bool isSYCLNativeCPU(const llvm::opt::ArgList &Args) {
if (auto SYCLTargets = Args.getLastArg(options::OPT_fsycl_targets_EQ)) {
if (SYCLTargets->containsValue("native_cpu"))
return true;
}
return false;
}

inline bool isSYCLNativeCPU(const llvm::Triple HostT, const llvm::Triple DevT) {
inline bool isSYCLNativeCPU(const llvm::Triple &HostT, const llvm::Triple &DevT) {
return HostT == DevT;
}

inline bool isSYCLNativeCPU(const ToolChain &TC1, const ToolChain &TC2) {
return isSYCLNativeCPU(TC1.getTriple(), TC2.getTriple());
inline bool isSYCLNativeCPU(const ToolChain &TC) {
const llvm::Triple *const AuxTriple = TC.getAuxTriple();
return AuxTriple && isSYCLNativeCPU(TC.getTriple(), *AuxTriple);
}
} // end namespace driver
} // end namespace clang
Expand Down
2 changes: 2 additions & 0 deletions clang/test/Driver/sycl-native-cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@
// RUN: %clang -fsycl -fsycl-targets=native_cpu -### %s 2>&1 | FileCheck -check-prefix=CHECK-OPTS %s
// CHECK-OPTS-NOT: -sycl-opt

// RUN: %clangxx -fsycl -fsycl-targets=spir64 %s -### 2>&1 | FileCheck -check-prefix=CHECK-NONATIVECPU %s
// CHECK-NONATIVECPU-NOT: "-D" "__SYCL_NATIVE_CPU__"

0 comments on commit 7a71960

Please sign in to comment.