Skip to content

Commit 467998d

Browse files
author
git apple-llvm automerger
committed
Merge commit '0b0d61101fa0' from llvm.org/main into next
2 parents b9e934a + 0b0d611 commit 467998d

File tree

20 files changed

+532
-26
lines changed

20 files changed

+532
-26
lines changed

clang/include/clang/Driver/Action.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class Action {
9595
OFK_Cuda = 0x02,
9696
OFK_OpenMP = 0x04,
9797
OFK_HIP = 0x08,
98+
OFK_SYCL = 0x10,
9899
};
99100

100101
static const char *getClassName(ActionClass AC);

clang/include/clang/Driver/Driver.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,10 @@ class Driver {
582582
/// @name Helper Methods
583583
/// @{
584584

585+
/// getSYCLDeviceTriple - Returns the SYCL device triple for the
586+
/// specified ArchType.
587+
llvm::Triple getSYCLDeviceTriple(StringRef TargetArch = "spir64") const;
588+
585589
/// PrintActions - Print the list of actions.
586590
void PrintActions(const Compilation &C) const;
587591

clang/include/clang/Driver/Options.td

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ def opencl_Group : OptionGroup<"<opencl group>">, Group<f_Group>,
182182
DocName<"OpenCL options">;
183183

184184
def sycl_Group : OptionGroup<"<SYCL group>">, Group<f_Group>,
185-
DocName<"SYCL options">;
185+
DocName<"SYCL options">,
186+
Visibility<[ClangOption, CLOption]>;
186187

187188
def cuda_Group : OptionGroup<"<CUDA group>">, Group<f_Group>,
188189
DocName<"CUDA options">,
@@ -6840,16 +6841,20 @@ defm : FlangIgnoredDiagOpt<"frontend-loop-interchange">;
68406841
defm : FlangIgnoredDiagOpt<"target-lifetime">;
68416842

68426843
// C++ SYCL options
6844+
let Group = sycl_Group in {
68436845
def fsycl : Flag<["-"], "fsycl">,
6844-
Visibility<[ClangOption, CLOption]>,
6845-
Group<sycl_Group>, HelpText<"Enables SYCL kernels compilation for device">;
6846+
HelpText<"Enables SYCL kernels compilation for device">;
68466847
def fno_sycl : Flag<["-"], "fno-sycl">,
6847-
Visibility<[ClangOption, CLOption]>,
6848-
Group<sycl_Group>, HelpText<"Disables SYCL kernels compilation for device">;
6848+
HelpText<"Disables SYCL kernels compilation for device">;
6849+
def fsycl_device_only : Flag<["-"], "fsycl-device-only">,
6850+
Alias<offload_device_only>, HelpText<"Compile SYCL kernels for device only">;
6851+
def fsycl_host_only : Flag<["-"], "fsycl-host-only">,
6852+
Alias<offload_host_only>, HelpText<"Compile SYCL kernels for host only">;
68496853
def sycl_link : Flag<["--"], "sycl-link">, Flags<[HelpHidden]>,
6850-
Visibility<[ClangOption, CLOption]>,
6851-
Group<sycl_Group>, HelpText<"Perform link through clang-sycl-linker via the target "
6854+
HelpText<"Perform link through clang-sycl-linker via the target "
68526855
"offloading toolchain.">;
6856+
} // let Group = sycl_Group
6857+
68536858
// OS-specific options
68546859
let Flags = [TargetSpecific] in {
68556860
defm android_pad_segment : BooleanFFlag<"android-pad-segment">, Group<f_Group>;

clang/include/clang/Driver/ToolChain.h

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

765+
/// Add arguments to use system-specific SYCL includes.
766+
virtual void AddSYCLIncludeArgs(const llvm::opt::ArgList &DriverArgs,
767+
llvm::opt::ArgStringList &CC1Args) const;
768+
765769
/// Add arguments to use MCU GCC toolchain includes.
766770
virtual void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs,
767771
llvm::opt::ArgStringList &CC1Args) const;

clang/lib/Driver/Action.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ std::string Action::getOffloadingKindPrefix() const {
112112
return "device-openmp";
113113
case OFK_HIP:
114114
return "device-hip";
115+
case OFK_SYCL:
116+
return "device-sycl";
115117

116118
// TODO: Add other programming models here.
117119
}
@@ -129,6 +131,8 @@ std::string Action::getOffloadingKindPrefix() const {
129131
Res += "-hip";
130132
if (ActiveOffloadKindMask & OFK_OpenMP)
131133
Res += "-openmp";
134+
if (ActiveOffloadKindMask & OFK_SYCL)
135+
Res += "-sycl";
132136

133137
// TODO: Add other programming models here.
134138

@@ -165,6 +169,8 @@ StringRef Action::GetOffloadKindName(OffloadKind Kind) {
165169
return "openmp";
166170
case OFK_HIP:
167171
return "hip";
172+
case OFK_SYCL:
173+
return "sycl";
168174

169175
// TODO: Add other programming models here.
170176
}
@@ -321,7 +327,7 @@ void OffloadAction::DeviceDependences::add(Action &A, const ToolChain &TC,
321327
DeviceBoundArchs.push_back(BoundArch);
322328

323329
// Add each active offloading kind from a mask.
324-
for (OffloadKind OKind : {OFK_OpenMP, OFK_Cuda, OFK_HIP})
330+
for (OffloadKind OKind : {OFK_OpenMP, OFK_Cuda, OFK_HIP, OFK_SYCL})
325331
if (OKind & OffloadKindMask)
326332
DeviceOffloadKinds.push_back(OKind);
327333
}

clang/lib/Driver/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ add_clang_library(clangDriver
7878
ToolChains/RISCVToolchain.cpp
7979
ToolChains/Solaris.cpp
8080
ToolChains/SPIRV.cpp
81+
ToolChains/SYCL.cpp
8182
ToolChains/TCE.cpp
8283
ToolChains/UEFI.cpp
8384
ToolChains/VEToolchain.cpp

clang/lib/Driver/Compilation.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,11 @@ static bool ActionFailed(const Action *A,
217217
if (FailingCommands.empty())
218218
return false;
219219

220-
// CUDA/HIP can have the same input source code compiled multiple times so do
221-
// not compiled again if there are already failures. It is OK to abort the
222-
// CUDA pipeline on errors.
223-
if (A->isOffloading(Action::OFK_Cuda) || A->isOffloading(Action::OFK_HIP))
220+
// CUDA/HIP/SYCL can have the same input source code compiled multiple times
221+
// so do not compile again if there are already failures. It is OK to abort
222+
// the CUDA/HIP/SYCL pipeline on errors.
223+
if (A->isOffloading(Action::OFK_Cuda) || A->isOffloading(Action::OFK_HIP) ||
224+
A->isOffloading(Action::OFK_SYCL))
224225
return true;
225226

226227
for (const auto &CI : FailingCommands)

clang/lib/Driver/Driver.cpp

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "ToolChains/PS4CPU.h"
4444
#include "ToolChains/RISCVToolchain.h"
4545
#include "ToolChains/SPIRV.h"
46+
#include "ToolChains/SYCL.h"
4647
#include "ToolChains/Solaris.h"
4748
#include "ToolChains/TCE.h"
4849
#include "ToolChains/UEFI.h"
@@ -781,6 +782,27 @@ Driver::OpenMPRuntimeKind Driver::getOpenMPRuntime(const ArgList &Args) const {
781782
return RT;
782783
}
783784

785+
static const char *getDefaultSYCLArch(Compilation &C) {
786+
// If -fsycl is supplied we will assume SPIR-V
787+
if (C.getDefaultToolChain().getTriple().isArch32Bit())
788+
return "spirv32";
789+
return "spirv64";
790+
}
791+
792+
static bool addSYCLDefaultTriple(Compilation &C,
793+
SmallVectorImpl<llvm::Triple> &SYCLTriples) {
794+
for (const auto &SYCLTriple : SYCLTriples) {
795+
if (SYCLTriple.getSubArch() == llvm::Triple::NoSubArch &&
796+
SYCLTriple.isSPIROrSPIRV())
797+
return false;
798+
}
799+
// Add the default triple as it was not found.
800+
llvm::Triple DefaultTriple =
801+
C.getDriver().getSYCLDeviceTriple(getDefaultSYCLArch(C));
802+
SYCLTriples.insert(SYCLTriples.begin(), DefaultTriple);
803+
return true;
804+
}
805+
784806
void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
785807
InputList &Inputs) {
786808

@@ -994,6 +1016,41 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
9941016
return;
9951017
}
9961018

1019+
//
1020+
// SYCL
1021+
//
1022+
// We need to generate a SYCL toolchain if the user specified -fsycl.
1023+
bool IsSYCL = C.getInputArgs().hasFlag(options::OPT_fsycl,
1024+
options::OPT_fno_sycl, false);
1025+
1026+
auto argSYCLIncompatible = [&](OptSpecifier OptId) {
1027+
if (!IsSYCL)
1028+
return;
1029+
if (Arg *IncompatArg = C.getInputArgs().getLastArg(OptId))
1030+
Diag(clang::diag::err_drv_argument_not_allowed_with)
1031+
<< IncompatArg->getSpelling() << "-fsycl";
1032+
};
1033+
// -static-libstdc++ is not compatible with -fsycl.
1034+
argSYCLIncompatible(options::OPT_static_libstdcxx);
1035+
// -ffreestanding cannot be used with -fsycl
1036+
argSYCLIncompatible(options::OPT_ffreestanding);
1037+
1038+
llvm::SmallVector<llvm::Triple, 4> UniqueSYCLTriplesVec;
1039+
1040+
if (IsSYCL) {
1041+
addSYCLDefaultTriple(C, UniqueSYCLTriplesVec);
1042+
1043+
// We'll need to use the SYCL and host triples as the key into
1044+
// getOffloadingDeviceToolChain, because the device toolchains we're
1045+
// going to create will depend on both.
1046+
const ToolChain *HostTC = C.getSingleOffloadToolChain<Action::OFK_Host>();
1047+
for (const auto &TT : UniqueSYCLTriplesVec) {
1048+
auto SYCLTC = &getOffloadingDeviceToolChain(C.getInputArgs(), TT, *HostTC,
1049+
Action::OFK_SYCL);
1050+
C.addOffloadDeviceToolChain(SYCLTC, Action::OFK_SYCL);
1051+
}
1052+
}
1053+
9971054
//
9981055
// TODO: Add support for other offloading programming models here.
9991056
//
@@ -2029,6 +2086,20 @@ void Driver::PrintHelp(bool ShowHidden) const {
20292086
VisibilityMask);
20302087
}
20312088

2089+
llvm::Triple Driver::getSYCLDeviceTriple(StringRef TargetArch) const {
2090+
SmallVector<StringRef, 5> SYCLAlias = {"spir", "spir64", "spirv32",
2091+
"spirv64"};
2092+
if (std::find(SYCLAlias.begin(), SYCLAlias.end(), TargetArch) !=
2093+
SYCLAlias.end()) {
2094+
llvm::Triple TT;
2095+
TT.setArchName(TargetArch);
2096+
TT.setVendor(llvm::Triple::UnknownVendor);
2097+
TT.setOS(llvm::Triple::UnknownOS);
2098+
return TT;
2099+
}
2100+
return llvm::Triple(TargetArch);
2101+
}
2102+
20322103
void Driver::PrintVersion(const Compilation &C, raw_ostream &OS) const {
20332104
if (IsFlangMode()) {
20342105
OS << getClangToolFullVersion("flang") << '\n';
@@ -4186,6 +4257,7 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
41864257

41874258
bool UseNewOffloadingDriver =
41884259
C.isOffloadingHostKind(Action::OFK_OpenMP) ||
4260+
C.isOffloadingHostKind(Action::OFK_SYCL) ||
41894261
Args.hasFlag(options::OPT_foffload_via_llvm,
41904262
options::OPT_fno_offload_via_llvm, false) ||
41914263
Args.hasFlag(options::OPT_offload_new_driver,
@@ -4604,6 +4676,8 @@ Driver::getOffloadArchs(Compilation &C, const llvm::opt::DerivedArgList &Args,
46044676
Archs.insert(OffloadArchToString(OffloadArch::HIPDefault));
46054677
else if (Kind == Action::OFK_OpenMP)
46064678
Archs.insert(StringRef());
4679+
else if (Kind == Action::OFK_SYCL)
4680+
Archs.insert(StringRef());
46074681
} else {
46084682
Args.ClaimAllArgs(options::OPT_offload_arch_EQ);
46094683
Args.ClaimAllArgs(options::OPT_no_offload_arch_EQ);
@@ -4628,7 +4702,7 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
46284702
OffloadAction::DeviceDependences DDeps;
46294703

46304704
const Action::OffloadKind OffloadKinds[] = {
4631-
Action::OFK_OpenMP, Action::OFK_Cuda, Action::OFK_HIP};
4705+
Action::OFK_OpenMP, Action::OFK_Cuda, Action::OFK_HIP, Action::OFK_SYCL};
46324706

46334707
for (Action::OffloadKind Kind : OffloadKinds) {
46344708
SmallVector<const ToolChain *, 2> ToolChains;
@@ -4673,6 +4747,11 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
46734747
break;
46744748
}
46754749

4750+
// Assemble actions are not used for the SYCL device side. Both compile
4751+
// and backend actions are used to generate IR and textual IR if needed.
4752+
if (Kind == Action::OFK_SYCL && Phase == phases::Assemble)
4753+
continue;
4754+
46764755
auto TCAndArch = TCAndArchs.begin();
46774756
for (Action *&A : DeviceActions) {
46784757
if (A->getType() == types::TY_Nothing)
@@ -4918,6 +4997,7 @@ Action *Driver::ConstructPhaseAction(
49184997
return C.MakeAction<BackendJobAction>(Input, Output);
49194998
}
49204999
if (Args.hasArg(options::OPT_emit_llvm) ||
5000+
TargetDeviceOffloadKind == Action::OFK_SYCL ||
49215001
(((Input->getOffloadingToolChain() &&
49225002
Input->getOffloadingToolChain()->getTriple().isAMDGPU()) ||
49235003
TargetDeviceOffloadKind == Action::OFK_HIP) &&
@@ -6628,6 +6708,19 @@ const ToolChain &Driver::getOffloadingDeviceToolChain(
66286708
HostTC, Args);
66296709
break;
66306710
}
6711+
case Action::OFK_SYCL:
6712+
switch (Target.getArch()) {
6713+
case llvm::Triple::spir:
6714+
case llvm::Triple::spir64:
6715+
case llvm::Triple::spirv32:
6716+
case llvm::Triple::spirv64:
6717+
TC = std::make_unique<toolchains::SYCLToolChain>(*this, Target, HostTC,
6718+
Args);
6719+
break;
6720+
default:
6721+
break;
6722+
}
6723+
break;
66316724
default:
66326725
break;
66336726
}

clang/lib/Driver/ToolChain.cpp

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

1492+
void ToolChain::AddSYCLIncludeArgs(const ArgList &DriverArgs,
1493+
ArgStringList &CC1Args) const {}
1494+
14921495
llvm::SmallVector<ToolChain::BitCodeLibraryInfo, 12>
14931496
ToolChain::getDeviceLibs(const ArgList &DriverArgs) const {
14941497
return {};

0 commit comments

Comments
 (0)