Skip to content

Commit fd229c2

Browse files
authored
[Driver][SYCL][NFC] Update interface to access SYCL header additions (#15302)
Move the ability to add the SYCL headers into the SYCLInstallation class to better conform to existing usage for other toolchains. Also improve the toolchain access for adding the headers using a virtual function.
1 parent 81844bf commit fd229c2

File tree

15 files changed

+68
-34
lines changed

15 files changed

+68
-34
lines changed

clang/include/clang/Driver/ToolChain.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,10 @@ class ToolChain {
781781
virtual void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs,
782782
llvm::opt::ArgStringList &CC1Args) const;
783783

784+
/// Add arguments to use SYCL specific includes.
785+
virtual void AddSYCLIncludeArgs(const llvm::opt::ArgList &DriverArgs,
786+
llvm::opt::ArgStringList &CC1Args) const;
787+
784788
/// Add arguments to use MCU GCC toolchain includes.
785789
virtual void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs,
786790
llvm::opt::ArgStringList &CC1Args) const;

clang/lib/Driver/ToolChain.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,6 +1519,9 @@ void ToolChain::AddCudaIncludeArgs(const ArgList &DriverArgs,
15191519
void ToolChain::AddHIPIncludeArgs(const ArgList &DriverArgs,
15201520
ArgStringList &CC1Args) const {}
15211521

1522+
void ToolChain::AddSYCLIncludeArgs(const ArgList &DriverArgs,
1523+
ArgStringList &CC1Args) const {}
1524+
15221525
llvm::SmallVector<ToolChain::BitCodeLibraryInfo, 12>
15231526
ToolChain::getDeviceLibs(
15241527
const ArgList &DriverArgs,

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
11601160
getToolChain().AddHIPIncludeArgs(Args, CmdArgs);
11611161

11621162
if (JA.isOffloading(Action::OFK_SYCL)) {
1163-
toolchains::SYCLToolChain::AddSYCLIncludeArgs(D, Args, CmdArgs);
1163+
getToolChain().AddSYCLIncludeArgs(Args, CmdArgs);
11641164
if (Inputs[0].getType() == types::TY_CUDA) {
11651165
// Include __clang_cuda_runtime_wrapper.h in .cu SYCL compilation.
11661166
getToolChain().AddCudaIncludeArgs(Args, CmdArgs);

clang/lib/Driver/ToolChains/Cuda.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ CudaToolChain::CudaToolChain(const Driver &D, const llvm::Triple &Triple,
924924
const ToolChain &HostTC, const ArgList &Args,
925925
const Action::OffloadKind OK)
926926
: NVPTXToolChain(D, Triple, HostTC.getTriple(), Args), HostTC(HostTC),
927-
OK(OK) {}
927+
SYCLInstallation(D), OK(OK) {}
928928

929929
void CudaToolChain::addClangTargetOptions(
930930
const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
@@ -941,8 +941,7 @@ void CudaToolChain::addClangTargetOptions(
941941
// If we are compiling SYCL kernels for Nvidia GPUs, we do not support Cuda
942942
// device code compatability, hence we do not set Cuda mode in that instance.
943943
if (DeviceOffloadingKind == Action::OFK_SYCL) {
944-
toolchains::SYCLToolChain::AddSYCLIncludeArgs(getDriver(), DriverArgs,
945-
CC1Args);
944+
SYCLInstallation.AddSYCLIncludeArgs(DriverArgs, CC1Args);
946945

947946
if (DriverArgs.hasArg(options::OPT_fsycl_fp32_prec_sqrt))
948947
CC1Args.push_back("-fcuda-prec-sqrt");
@@ -1205,8 +1204,7 @@ CudaToolChain::GetCXXStdlibType(const ArgList &Args) const {
12051204
void CudaToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
12061205
ArgStringList &CC1Args) const {
12071206
if (DriverArgs.hasArg(options::OPT_fsycl)) {
1208-
toolchains::SYCLToolChain::AddSYCLIncludeArgs(getDriver(), DriverArgs,
1209-
CC1Args);
1207+
SYCLInstallation.AddSYCLIncludeArgs(DriverArgs, CC1Args);
12101208
}
12111209
HostTC.AddClangSystemIncludeArgs(DriverArgs, CC1Args);
12121210

clang/lib/Driver/ToolChains/Cuda.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ class LLVM_LIBRARY_VISIBILITY CudaToolChain : public NVPTXToolChain {
260260
Tool *SelectTool(const JobAction &JA) const override;
261261
const ToolChain &HostTC;
262262

263+
SYCLInstallationDetector SYCLInstallation;
264+
263265
protected:
264266
Tool *buildAssembler() const override; // ptxas
265267
Tool *buildLinker() const override; // fatbinary (ok, not really a linker)

clang/lib/Driver/ToolChains/Gnu.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3190,7 +3190,8 @@ bool Generic_GCC::GCCInstallationDetector::ScanGentooGccConfig(
31903190
Generic_GCC::Generic_GCC(const Driver &D, const llvm::Triple &Triple,
31913191
const ArgList &Args)
31923192
: ToolChain(D, Triple, Args), GCCInstallation(D),
3193-
CudaInstallation(D, Triple, Args), RocmInstallation(D, Triple, Args) {
3193+
CudaInstallation(D, Triple, Args), RocmInstallation(D, Triple, Args),
3194+
SYCLInstallation(D) {
31943195
getProgramPaths().push_back(getDriver().Dir);
31953196
}
31963197

clang/lib/Driver/ToolChains/Gnu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ class LLVM_LIBRARY_VISIBILITY Generic_GCC : public ToolChain {
294294
GCCInstallationDetector GCCInstallation;
295295
LazyDetector<CudaInstallationDetector> CudaInstallation;
296296
LazyDetector<RocmInstallationDetector> RocmInstallation;
297+
SYCLInstallationDetector SYCLInstallation;
297298

298299
public:
299300
Generic_GCC(const Driver &D, const llvm::Triple &Triple,

clang/lib/Driver/ToolChains/HIPAMD.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ void AMDGCN::Linker::ConstructJob(Compilation &C, const JobAction &JA,
253253
HIPAMDToolChain::HIPAMDToolChain(const Driver &D, const llvm::Triple &Triple,
254254
const ToolChain &HostTC, const ArgList &Args,
255255
const Action::OffloadKind OK)
256-
: ROCMToolChain(D, Triple, Args), HostTC(HostTC), OK(OK) {
256+
: ROCMToolChain(D, Triple, Args), HostTC(HostTC), SYCLInstallation(D),
257+
OK(OK) {
257258
// Lookup binaries into the driver directory, this is used to
258259
// discover the clang-offload-bundler executable.
259260
getProgramPaths().push_back(getDriver().Dir);
@@ -318,8 +319,7 @@ void HIPAMDToolChain::addClangTargetOptions(
318319
CC1Args.push_back("-fembed-bitcode=marker");
319320

320321
if (DeviceOffloadingKind == Action::OFK_SYCL) {
321-
toolchains::SYCLToolChain::AddSYCLIncludeArgs(getDriver(), DriverArgs,
322-
CC1Args);
322+
SYCLInstallation.AddSYCLIncludeArgs(DriverArgs, CC1Args);
323323
}
324324

325325
auto NoLibSpirv = DriverArgs.hasArg(options::OPT_fno_sycl_libspirv) ||

clang/lib/Driver/ToolChains/HIPAMD.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ class LLVM_LIBRARY_VISIBILITY HIPAMDToolChain final : public ROCMToolChain {
110110
void checkTargetID(const llvm::opt::ArgList &DriverArgs) const override;
111111
Tool *SelectTool(const JobAction &JA) const override;
112112

113+
SYCLInstallationDetector SYCLInstallation;
114+
113115
protected:
114116
Tool *buildLinker() const override;
115117

clang/lib/Driver/ToolChains/Linux.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,11 @@ void Linux::AddIAMCUIncludeArgs(const ArgList &DriverArgs,
768768
}
769769
}
770770

771+
void Linux::AddSYCLIncludeArgs(const ArgList &DriverArgs,
772+
ArgStringList &CC1Args) const {
773+
SYCLInstallation.AddSYCLIncludeArgs(DriverArgs, CC1Args);
774+
}
775+
771776
bool Linux::isPIEDefault(const llvm::opt::ArgList &Args) const {
772777
return CLANG_DEFAULT_PIE_ON_LINUX || getTriple().isAndroid() ||
773778
getTriple().isMusl() || getSanitizerArgs(Args).requiresPIE();

0 commit comments

Comments
 (0)