Skip to content

[SYCL] [NATIVECPU] Driver fix to stop defining NativeCPU macro for other SYCL targets #12783

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 29, 2024
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__"