Skip to content

Commit 7ff06d5

Browse files
Merge branch 'sycl' into private/udit/adapter_refac3
2 parents be139e9 + 50212fd commit 7ff06d5

File tree

116 files changed

+2007
-1492
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+2007
-1492
lines changed

.github/workflows/release-binaries.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ jobs:
301301

302302
- name: Attest Build Provenance
303303
id: provenance
304-
uses: actions/attest-build-provenance@db473fddc028af60658334401dc6fa3ffd8669fd # v2.3.0
304+
uses: actions/attest-build-provenance@e8998f949152b193b063cb0ec769d69d929409be # v2.4.0
305305
with:
306306
subject-path: ${{ needs.prepare.outputs.release-binary-filename }}
307307

.github/workflows/release-sources.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ jobs:
9292
- name: Attest Build Provenance
9393
if: github.event_name != 'pull_request'
9494
id: provenance
95-
uses: actions/attest-build-provenance@db473fddc028af60658334401dc6fa3ffd8669fd # v2.3.0
95+
uses: actions/attest-build-provenance@e8998f949152b193b063cb0ec769d69d929409be # v2.4.0
9696
with:
9797
subject-path: "*.xz"
9898
- if: github.event_name != 'pull_request'

clang/include/clang/Sema/SemaSYCL.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ class SemaSYCL : public SemaBase {
265265

266266
llvm::DenseSet<const FunctionDecl *> SYCLKernelFunctions;
267267

268+
llvm::DenseSet<const FunctionDecl *> FreeFunctionDeclarations;
269+
268270
public:
269271
SemaSYCL(Sema &S);
270272

@@ -357,7 +359,9 @@ class SemaSYCL : public SemaBase {
357359
void ConstructOpenCLKernel(FunctionDecl *KernelCallerFunc, MangleContext &MC);
358360
void SetSYCLKernelNames();
359361
void MarkDevices();
362+
void processFreeFunctionDeclaration(const FunctionDecl *FD);
360363
void ProcessFreeFunction(FunctionDecl *FD);
364+
void finalizeFreeFunctionKernels();
361365

362366
/// Get the number of fields or captures within the parsed type.
363367
ExprResult ActOnSYCLBuiltinNumFieldsExpr(ParsedType PT);

clang/lib/Basic/Targets.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,6 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
119119
return nullptr;
120120

121121
case llvm::Triple::UnknownArch:
122-
// native_cpu is only known to Clang, not to LLVM.
123-
if (Triple.str() == "native_cpu")
124-
return std::make_unique<NativeCPUTargetInfo>(Triple, Opts);
125-
126122
return nullptr;
127123

128124
case llvm::Triple::arc:
@@ -843,6 +839,9 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
843839

844840
case llvm::Triple::xtensa:
845841
return std::make_unique<XtensaTargetInfo>(Triple, Opts);
842+
843+
case llvm::Triple::native_cpu:
844+
return std::make_unique<NativeCPUTargetInfo>(Triple, Opts);
846845
}
847846
}
848847
} // namespace targets

clang/lib/Driver/Driver.cpp

Lines changed: 16 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
#include "ToolChains/PS4CPU.h"
4444
#include "ToolChains/RISCVToolchain.h"
4545
#include "ToolChains/SPIRV.h"
46-
#include "ToolChains/SYCL.h"
4746
#include "ToolChains/SPIRVOpenMP.h"
4847
#include "ToolChains/SYCL.h"
4948
#include "ToolChains/Solaris.h"
@@ -976,7 +975,10 @@ static bool isValidSYCLTriple(llvm::Triple T) {
976975
return true;
977976

978977
// 'native_cpu' is valid for Native CPU.
979-
if (isSYCLNativeCPU(T))
978+
// TODO This checks for the exact spelling of the triple because other
979+
// spellings would fail confusingly, trying to find nonexistent builtins. This
980+
// should probably be done for NVidia and AMD too.
981+
if (T.isNativeCPU() && T.str() == "native_cpu")
980982
return true;
981983

982984
// Check for invalid SYCL device triple values.
@@ -5566,7 +5568,7 @@ class OffloadingActionBuilder final {
55665568
auto IsAMDGCN = TargetTriple.isAMDGCN();
55675569
auto IsSPIR = TargetTriple.isSPIROrSPIRV();
55685570
bool IsSpirvAOT = TargetTriple.isSPIRAOT();
5569-
bool IsSYCLNativeCPU = isSYCLNativeCPU(TargetTriple);
5571+
bool IsNativeCPU = TargetTriple.isNativeCPU();
55705572
for (const auto &Input : ListIndex) {
55715573
// No need for any conversion if we are coming in from the
55725574
// clang-offload-deps or regular compilation path.
@@ -5706,7 +5708,7 @@ class OffloadingActionBuilder final {
57065708
// AOT compilation.
57075709
bool SYCLDeviceLibLinked = false;
57085710
Action *NativeCPULib = nullptr;
5709-
if (IsSPIR || IsNVPTX || IsAMDGCN || IsSYCLNativeCPU) {
5711+
if (IsSPIR || IsNVPTX || IsAMDGCN || IsNativeCPU) {
57105712
bool UseJitLink =
57115713
IsSPIR &&
57125714
Args.hasFlag(options::OPT_fsycl_device_lib_jit_link,
@@ -5715,7 +5717,7 @@ class OffloadingActionBuilder final {
57155717
SYCLDeviceLibLinked = addSYCLDeviceLibs(
57165718
TC, SYCLDeviceLibs, UseAOTLink,
57175719
C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment(),
5718-
IsSYCLNativeCPU, NativeCPULib, BoundArch);
5720+
IsNativeCPU, NativeCPULib, BoundArch);
57195721
}
57205722
JobAction *LinkSYCLLibs =
57215723
C.MakeAction<LinkJobAction>(SYCLDeviceLibs, types::TY_LLVM_BC);
@@ -5782,11 +5784,11 @@ class OffloadingActionBuilder final {
57825784

57835785
// reflects whether current target is ahead-of-time and can't
57845786
// support runtime setting of specialization constants
5785-
bool IsAOT = IsNVPTX || IsAMDGCN || IsSpirvAOT || IsSYCLNativeCPU;
5787+
bool IsAOT = IsNVPTX || IsAMDGCN || IsSpirvAOT || IsNativeCPU;
57865788

57875789
// post link is not optional - even if not splitting, always need to
57885790
// process specialization constants
5789-
types::ID PostLinkOutType = IsSPIR || IsSYCLNativeCPU
5791+
types::ID PostLinkOutType = IsSPIR || IsNativeCPU
57905792
? types::TY_Tempfiletable
57915793
: types::TY_LLVM_BC;
57925794
auto createPostLinkAction = [&]() {
@@ -5797,7 +5799,7 @@ class OffloadingActionBuilder final {
57975799
return TypedPostLinkAction;
57985800
};
57995801
Action *PostLinkAction = createPostLinkAction();
5800-
if (IsSYCLNativeCPU) {
5802+
if (IsNativeCPU) {
58015803
if (NativeCPULib) {
58025804
// The native cpu device lib is linked without --only-needed
58035805
// as it contains builtins not referenced in source code but
@@ -5993,46 +5995,10 @@ class OffloadingActionBuilder final {
59935995
// For NVPTX and NativeCPU we need to also link libclc at the same stage
59945996
// that we link all of the unbundled SYCL libdevice objects together.
59955997
if (TC->getTriple().isNVPTX() || isNativeCPU) {
5996-
std::string LibSpirvFile;
5997-
if (Args.hasArg(options::OPT_fsycl_libspirv_path_EQ)) {
5998-
auto ProvidedPath =
5999-
Args.getLastArgValue(options::OPT_fsycl_libspirv_path_EQ).str();
6000-
if (llvm::sys::fs::exists(ProvidedPath))
6001-
LibSpirvFile = ProvidedPath;
6002-
} else {
6003-
SmallVector<StringRef, 2> LibraryPaths;
6004-
6005-
// Expected path w/out install.
6006-
SmallString<256> WithoutInstallPath(C.getDriver().ResourceDir);
6007-
llvm::sys::path::append(WithoutInstallPath, Twine("../../clc"));
6008-
LibraryPaths.emplace_back(WithoutInstallPath.c_str());
6009-
6010-
// Expected path w/ install.
6011-
SmallString<256> WithInstallPath(C.getDriver().ResourceDir);
6012-
llvm::sys::path::append(WithInstallPath, Twine("../../../share/clc"));
6013-
LibraryPaths.emplace_back(WithInstallPath.c_str());
6014-
6015-
// Select remangled libclc variant
6016-
StringRef LibSpirvTargetNamePref =
6017-
TC->getAuxTriple()->isOSWindows()
6018-
? "remangled-l32-signed_char.libspirv-"
6019-
: "remangled-l64-signed_char.libspirv-";
6020-
6021-
for (StringRef LibraryPath : LibraryPaths) {
6022-
SmallString<128> LibSpirvTargetFile(LibraryPath);
6023-
llvm::sys::path::append(LibSpirvTargetFile,
6024-
LibSpirvTargetNamePref +
6025-
TC->getTripleString() + ".bc");
6026-
if (llvm::sys::fs::exists(LibSpirvTargetFile) ||
6027-
Args.hasArg(options::OPT__HASH_HASH_HASH)) {
6028-
LibSpirvFile = std::string(LibSpirvTargetFile.str());
6029-
break;
6030-
}
6031-
}
6032-
}
6033-
if (!LibSpirvFile.empty()) {
6034-
Arg *LibClcInputArg = MakeInputArg(Args, C.getDriver().getOpts(),
6035-
Args.MakeArgString(LibSpirvFile));
5998+
if (const char *LibSpirvFile = SYCLInstallation.findLibspirvPath(
5999+
TC->getTriple(), Args, *TC->getAuxTriple())) {
6000+
Arg *LibClcInputArg =
6001+
MakeInputArg(Args, C.getDriver().getOpts(), LibSpirvFile);
60366002
auto *SYCLLibClcInputAction =
60376003
C.MakeAction<InputAction>(*LibClcInputArg, types::TY_LLVM_BC);
60386004
DeviceLinkObjects.push_back(SYCLLibClcInputAction);
@@ -9140,7 +9106,7 @@ InputInfoList Driver::BuildJobsForActionNoCache(
91409106
Action::OffloadKind DependentOffloadKind;
91419107
if (UI.DependentOffloadKind == Action::OFK_SYCL &&
91429108
TargetDeviceOffloadKind == Action::OFK_None &&
9143-
!(isSYCLNativeCPU(C.getDefaultToolChain().getTriple()) &&
9109+
!(C.getDefaultToolChain().getTriple().isNativeCPU() &&
91449110
UA->getDependentActionsInfo().size() > 1))
91459111
DependentOffloadKind = Action::OFK_Host;
91469112
else
@@ -10037,7 +10003,7 @@ const ToolChain &Driver::getOffloadToolChain(
1003710003
*HostTC, Args, Kind);
1003810004
break;
1003910005
default:
10040-
if (Kind == Action::OFK_SYCL && isSYCLNativeCPU(Target))
10006+
if (Kind == Action::OFK_SYCL && Target.isNativeCPU())
1004110007
TC = std::make_unique<toolchains::SYCLToolChain>(*this, Target, *HostTC,
1004210008
Args);
1004310009
break;

clang/lib/Driver/OffloadBundler.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,7 @@ bool OffloadTargetInfo::isOffloadKindCompatible(
178178
}
179179

180180
bool OffloadTargetInfo::isTripleValid() const {
181-
return !Triple.str().empty() && (Triple.getArch() != Triple::UnknownArch ||
182-
Triple.str() == "native_cpu---");
181+
return !Triple.str().empty() && Triple.getArch() != Triple::UnknownArch;
183182
}
184183

185184
bool OffloadTargetInfo::operator==(const OffloadTargetInfo &Target) const {

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5560,8 +5560,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
55605560
// Adjust for SYCL NativeCPU compilations. When compiling in device mode, the
55615561
// first compilation uses the NativeCPU target for LLVM IR generation, the
55625562
// second compilation uses the host target for machine code generation.
5563-
const bool IsSYCLNativeCPU = isSYCLNativeCPU(Triple);
5564-
if (IsSYCL && IsSYCLDevice && IsSYCLNativeCPU && AuxTriple &&
5563+
if (IsSYCL && IsSYCLDevice && Triple.isNativeCPU() && AuxTriple &&
55655564
isa<AssembleJobAction>(JA)) {
55665565
Triple = *AuxTriple;
55675566
TripleStr = Triple.getTriple();
@@ -5696,7 +5695,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
56965695
CmdArgs.push_back("-mllvm");
56975696
CmdArgs.push_back("-sycl-opt");
56985697
}
5699-
if (IsSYCLNativeCPU) {
5698+
if (RawTriple.isNativeCPU()) {
57005699
CmdArgs.push_back("-fsycl-is-native-cpu");
57015700
CmdArgs.push_back("-D");
57025701
CmdArgs.push_back("__SYCL_NATIVE_CPU__");
@@ -6077,14 +6076,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
60776076
CmdArgs.push_back("-fdirectives-only");
60786077
}
60796078
} else if (isa<AssembleJobAction>(JA)) {
6080-
if (IsSYCLDevice && !IsSYCLNativeCPU) {
6079+
if (IsSYCLDevice && !RawTriple.isNativeCPU()) {
60816080
CmdArgs.push_back("-emit-llvm-bc");
60826081
} else {
60836082
CmdArgs.push_back("-emit-obj");
60846083
CollectArgsForIntegratedAssembler(C, Args, CmdArgs, D);
60856084
}
6086-
if (IsSYCLDevice && IsSYCLNativeCPU) {
6087-
// NativeCPU generates an initial LLVM module for an unknown target, then
6085+
if (IsSYCLDevice && RawTriple.isNativeCPU()) {
6086+
// NativeCPU generates an initial LLVM module for a dummy target, then
60886087
// compiles that for host. Avoid generating a warning for that.
60896088
CmdArgs.push_back("-Wno-override-module");
60906089
CmdArgs.push_back("-mllvm");
@@ -10886,7 +10885,7 @@ static bool shouldEmitOnlyKernelsAsEntryPoints(const ToolChain &TC,
1088610885
if (TCArgs.hasFlag(options::OPT_fno_sycl_remove_unused_external_funcs,
1088710886
options::OPT_fsycl_remove_unused_external_funcs, false))
1088810887
return false;
10889-
if (isSYCLNativeCPU(Triple))
10888+
if (Triple.isNativeCPU())
1089010889
return true;
1089110890
// When supporting dynamic linking, non-kernels in a device image can be
1089210891
// called.
@@ -10944,7 +10943,7 @@ static void getTripleBasedSYCLPostLinkOpts(const ToolChain &TC,
1094410943
if (!Triple.isAMDGCN())
1094510944
addArgs(PostLinkArgs, TCArgs, {"-emit-param-info"});
1094610945
// Enable program metadata
10947-
if (Triple.isNVPTX() || Triple.isAMDGCN() || isSYCLNativeCPU(Triple))
10946+
if (Triple.isNVPTX() || Triple.isAMDGCN() || Triple.isNativeCPU())
1094810947
addArgs(PostLinkArgs, TCArgs, {"-emit-program-metadata"});
1094910948
if (OutputType != types::TY_LLVM_BC) {
1095010949
assert(OutputType == types::TY_Tempfiletable);

clang/lib/Driver/ToolChains/Cuda.cpp

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -861,14 +861,6 @@ NVPTXToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
861861
return DAL;
862862
}
863863

864-
// Select remangled libclc variant. 64-bit longs default, 32-bit longs on
865-
// Windows
866-
static const char *getLibSpirvTargetName(const ToolChain &HostTC) {
867-
if (HostTC.getTriple().isOSWindows())
868-
return "remangled-l32-signed_char.libspirv-nvptx64-nvidia-cuda.bc";
869-
return "remangled-l64-signed_char.libspirv-nvptx64-nvidia-cuda.bc";
870-
}
871-
872864
void NVPTXToolChain::addClangTargetOptions(
873865
const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
874866
Action::OffloadKind DeviceOffloadingKind) const {}
@@ -970,6 +962,9 @@ void CudaToolChain::addClangTargetOptions(
970962
options::OPT_fno_sycl_id_queries_fit_in_int, false))
971963
CC1Args.append(
972964
{"-mllvm", "-nvvm-reflect-add=__CUDA_ID_QUERIES_FIT_IN_INT=1"});
965+
966+
SYCLInstallation.addLibspirvLinkArgs(getEffectiveTriple(), DriverArgs,
967+
HostTC.getTriple(), CC1Args);
973968
} else {
974969
CC1Args.append({"-fcuda-is-device", "-mllvm",
975970
"-enable-memcpyopt-without-libcalls",
@@ -988,53 +983,6 @@ void CudaToolChain::addClangTargetOptions(
988983
CC1Args.append({"-std=c++17", "-fsycl-is-host"});
989984
}
990985

991-
auto NoLibSpirv = DriverArgs.hasArg(options::OPT_fno_sycl_libspirv) ||
992-
getDriver().offloadDeviceOnly();
993-
if (DeviceOffloadingKind == Action::OFK_SYCL && !NoLibSpirv) {
994-
std::string LibSpirvFile;
995-
996-
if (DriverArgs.hasArg(clang::driver::options::OPT_fsycl_libspirv_path_EQ)) {
997-
auto ProvidedPath =
998-
DriverArgs.getLastArgValue(clang::driver::options::OPT_fsycl_libspirv_path_EQ).str();
999-
if (llvm::sys::fs::exists(ProvidedPath))
1000-
LibSpirvFile = ProvidedPath;
1001-
} else {
1002-
SmallVector<StringRef, 8> LibraryPaths;
1003-
1004-
// Expected path w/out install.
1005-
SmallString<256> WithoutInstallPath(getDriver().ResourceDir);
1006-
llvm::sys::path::append(WithoutInstallPath, Twine("../../clc"));
1007-
LibraryPaths.emplace_back(WithoutInstallPath.c_str());
1008-
1009-
// Expected path w/ install.
1010-
SmallString<256> WithInstallPath(getDriver().ResourceDir);
1011-
llvm::sys::path::append(WithInstallPath, Twine("../../../share/clc"));
1012-
LibraryPaths.emplace_back(WithInstallPath.c_str());
1013-
1014-
// Select remangled libclc variant
1015-
std::string LibSpirvTargetName = getLibSpirvTargetName(HostTC);
1016-
1017-
for (StringRef LibraryPath : LibraryPaths) {
1018-
SmallString<128> LibSpirvTargetFile(LibraryPath);
1019-
llvm::sys::path::append(LibSpirvTargetFile, LibSpirvTargetName);
1020-
if (llvm::sys::fs::exists(LibSpirvTargetFile) ||
1021-
DriverArgs.hasArg(options::OPT__HASH_HASH_HASH)) {
1022-
LibSpirvFile = std::string(LibSpirvTargetFile.str());
1023-
break;
1024-
}
1025-
}
1026-
}
1027-
1028-
if (LibSpirvFile.empty()) {
1029-
getDriver().Diag(diag::err_drv_no_sycl_libspirv)
1030-
<< getLibSpirvTargetName(HostTC);
1031-
return;
1032-
}
1033-
1034-
CC1Args.push_back("-mlink-builtin-bitcode");
1035-
CC1Args.push_back(DriverArgs.MakeArgString(LibSpirvFile));
1036-
}
1037-
1038986
if (DriverArgs.hasFlag(options::OPT_fcuda_short_ptr,
1039987
options::OPT_fno_cuda_short_ptr, false))
1040988
CC1Args.append({"-mllvm", "--nvptx-short-ptr"});

0 commit comments

Comments
 (0)