Skip to content

Commit 778314d

Browse files
Merge branch 'sycl' into sycl-free-function-illegal-types
2 parents 54d198e + 8cdb923 commit 778314d

File tree

87 files changed

+1260
-471
lines changed

Some content is hidden

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

87 files changed

+1260
-471
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: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,10 @@ static bool isValidSYCLTriple(llvm::Triple T) {
975975
return true;
976976

977977
// 'native_cpu' is valid for Native CPU.
978-
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")
979982
return true;
980983

981984
// Check for invalid SYCL device triple values.
@@ -5565,7 +5568,7 @@ class OffloadingActionBuilder final {
55655568
auto IsAMDGCN = TargetTriple.isAMDGCN();
55665569
auto IsSPIR = TargetTriple.isSPIROrSPIRV();
55675570
bool IsSpirvAOT = TargetTriple.isSPIRAOT();
5568-
bool IsSYCLNativeCPU = isSYCLNativeCPU(TargetTriple);
5571+
bool IsNativeCPU = TargetTriple.isNativeCPU();
55695572
for (const auto &Input : ListIndex) {
55705573
// No need for any conversion if we are coming in from the
55715574
// clang-offload-deps or regular compilation path.
@@ -5705,7 +5708,7 @@ class OffloadingActionBuilder final {
57055708
// AOT compilation.
57065709
bool SYCLDeviceLibLinked = false;
57075710
Action *NativeCPULib = nullptr;
5708-
if (IsSPIR || IsNVPTX || IsAMDGCN || IsSYCLNativeCPU) {
5711+
if (IsSPIR || IsNVPTX || IsAMDGCN || IsNativeCPU) {
57095712
bool UseJitLink =
57105713
IsSPIR &&
57115714
Args.hasFlag(options::OPT_fsycl_device_lib_jit_link,
@@ -5714,7 +5717,7 @@ class OffloadingActionBuilder final {
57145717
SYCLDeviceLibLinked = addSYCLDeviceLibs(
57155718
TC, SYCLDeviceLibs, UseAOTLink,
57165719
C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment(),
5717-
IsSYCLNativeCPU, NativeCPULib, BoundArch);
5720+
IsNativeCPU, NativeCPULib, BoundArch);
57185721
}
57195722
JobAction *LinkSYCLLibs =
57205723
C.MakeAction<LinkJobAction>(SYCLDeviceLibs, types::TY_LLVM_BC);
@@ -5781,11 +5784,11 @@ class OffloadingActionBuilder final {
57815784

57825785
// reflects whether current target is ahead-of-time and can't
57835786
// support runtime setting of specialization constants
5784-
bool IsAOT = IsNVPTX || IsAMDGCN || IsSpirvAOT || IsSYCLNativeCPU;
5787+
bool IsAOT = IsNVPTX || IsAMDGCN || IsSpirvAOT || IsNativeCPU;
57855788

57865789
// post link is not optional - even if not splitting, always need to
57875790
// process specialization constants
5788-
types::ID PostLinkOutType = IsSPIR || IsSYCLNativeCPU
5791+
types::ID PostLinkOutType = IsSPIR || IsNativeCPU
57895792
? types::TY_Tempfiletable
57905793
: types::TY_LLVM_BC;
57915794
auto createPostLinkAction = [&]() {
@@ -5796,7 +5799,7 @@ class OffloadingActionBuilder final {
57965799
return TypedPostLinkAction;
57975800
};
57985801
Action *PostLinkAction = createPostLinkAction();
5799-
if (IsSYCLNativeCPU) {
5802+
if (IsNativeCPU) {
58005803
if (NativeCPULib) {
58015804
// The native cpu device lib is linked without --only-needed
58025805
// as it contains builtins not referenced in source code but
@@ -9103,7 +9106,7 @@ InputInfoList Driver::BuildJobsForActionNoCache(
91039106
Action::OffloadKind DependentOffloadKind;
91049107
if (UI.DependentOffloadKind == Action::OFK_SYCL &&
91059108
TargetDeviceOffloadKind == Action::OFK_None &&
9106-
!(isSYCLNativeCPU(C.getDefaultToolChain().getTriple()) &&
9109+
!(C.getDefaultToolChain().getTriple().isNativeCPU() &&
91079110
UA->getDependentActionsInfo().size() > 1))
91089111
DependentOffloadKind = Action::OFK_Host;
91099112
else
@@ -10000,7 +10003,7 @@ const ToolChain &Driver::getOffloadToolChain(
1000010003
*HostTC, Args, Kind);
1000110004
break;
1000210005
default:
10003-
if (Kind == Action::OFK_SYCL && isSYCLNativeCPU(Target))
10006+
if (Kind == Action::OFK_SYCL && Target.isNativeCPU())
1000410007
TC = std::make_unique<toolchains::SYCLToolChain>(*this, Target, *HostTC,
1000510008
Args);
1000610009
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/SYCL.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,9 @@ const char *SYCLInstallationDetector::findLibspirvPath(
182182
const SmallString<64> Basename =
183183
getLibSpirvBasename(DeviceTriple, HostTriple);
184184
auto searchAt = [&](StringRef Path, const Twine &a = "", const Twine &b = "",
185-
const Twine &c = "", const Twine &d = "",
186-
const Twine &e = "") -> const char * {
185+
const Twine &c = "") -> const char * {
187186
SmallString<128> LibraryPath(Path);
188-
llvm::sys::path::append(LibraryPath, a, b, c, d);
189-
llvm::sys::path::append(LibraryPath, e, Basename);
187+
llvm::sys::path::append(LibraryPath, a, b, c, Basename);
190188

191189
if (Args.hasArgNoClaim(options::OPT__HASH_HASH_HASH) ||
192190
llvm::sys::fs::exists(LibraryPath))
@@ -195,14 +193,15 @@ const char *SYCLInstallationDetector::findLibspirvPath(
195193
return nullptr;
196194
};
197195

198-
// Otherwise, assume libclc is installed at the same prefix as clang
199-
// Expected path w/out install.
200-
if (const char *R = searchAt(D.ResourceDir, "..", "..", "clc"))
201-
return R;
196+
for (const auto &IC : InstallationCandidates) {
197+
// Expected path w/out install.
198+
if (const char *R = searchAt(IC, "lib", "clc"))
199+
return R;
202200

203-
// Expected path w/ install.
204-
if (const char *R = searchAt(D.ResourceDir, "..", "..", "..", "share", "clc"))
205-
return R;
201+
// Expected path w/ install.
202+
if (const char *R = searchAt(IC, "share", "clc"))
203+
return R;
204+
}
206205

207206
return nullptr;
208207
}
@@ -838,7 +837,7 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple,
838837
addSingleLibrary(SYCLDeviceTsanLibs[sanitizer_lib_idx]);
839838
#endif
840839

841-
if (isSYCLNativeCPU(TargetTriple))
840+
if (TargetTriple.isNativeCPU())
842841
addLibraries(SYCLNativeCpuDeviceLibs);
843842

844843
return LibraryList;
@@ -1016,7 +1015,7 @@ const char *SYCL::Linker::constructLLVMLinkCommand(
10161015
const bool IsNVPTX = this->getToolChain().getTriple().isNVPTX();
10171016
const bool IsAMDGCN = this->getToolChain().getTriple().isAMDGCN();
10181017
const bool IsSYCLNativeCPU =
1019-
isSYCLNativeCPU(this->getToolChain().getTriple());
1018+
this->getToolChain().getTriple().isNativeCPU();
10201019
StringRef LibPostfix = ".bc";
10211020
StringRef NewLibPostfix = ".new.o";
10221021
if (HostTC->getTriple().isWindowsMSVCEnvironment() &&
@@ -1160,7 +1159,7 @@ void SYCL::Linker::ConstructJob(Compilation &C, const JobAction &JA,
11601159
assert((getToolChain().getTriple().isSPIROrSPIRV() ||
11611160
getToolChain().getTriple().isNVPTX() ||
11621161
getToolChain().getTriple().isAMDGCN() ||
1163-
isSYCLNativeCPU(getToolChain().getTriple())) &&
1162+
getToolChain().getTriple().isNativeCPU()) &&
11641163
"Unsupported target");
11651164

11661165
std::string SubArchName =
@@ -1552,7 +1551,7 @@ static ArrayRef<options::ID> getUnsupportedOpts() {
15521551
// Currently supported options by SYCL NativeCPU device compilation
15531552
static inline bool SupportedByNativeCPU(const llvm::Triple &Triple,
15541553
const OptSpecifier &Opt) {
1555-
if (!isSYCLNativeCPU(Triple))
1554+
if (!Triple.isNativeCPU())
15561555
return false;
15571556

15581557
switch (Opt.getID()) {
@@ -2001,7 +2000,7 @@ Tool *SYCLToolChain::buildBackendCompiler() const {
20012000
}
20022001

20032002
Tool *SYCLToolChain::buildLinker() const {
2004-
assert(getTriple().isSPIROrSPIRV() || isSYCLNativeCPU(getTriple()));
2003+
assert(getTriple().isSPIROrSPIRV() || getTriple().isNativeCPU());
20052004
return new tools::SYCL::Linker(*this);
20062005
}
20072006

clang/lib/Driver/ToolChains/SYCL.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,6 @@ class LLVM_LIBRARY_VISIBILITY BackendCompiler : public Tool {
258258
} // end namespace SYCL
259259
} // end namespace tools
260260

261-
inline bool isSYCLNativeCPU(const llvm::Triple &Triple) {
262-
return Triple.getArch() == llvm::Triple::UnknownArch &&
263-
Triple.str() == "native_cpu";
264-
}
265-
266261
namespace toolchains {
267262

268263
class LLVM_LIBRARY_VISIBILITY SYCLToolChain : public ToolChain {
@@ -303,12 +298,12 @@ class LLVM_LIBRARY_VISIBILITY SYCLToolChain : public ToolChain {
303298

304299
bool useIntegratedAs() const override { return true; }
305300
bool isPICDefault() const override {
306-
if (isSYCLNativeCPU(this->getTriple()))
301+
if (this->getTriple().isNativeCPU())
307302
return this->HostTC.isPICDefault();
308303
return false;
309304
}
310305
llvm::codegenoptions::DebugInfoFormat getDefaultDebugFormat() const override {
311-
if (isSYCLNativeCPU(this->getTriple()) &&
306+
if (this->getTriple().isNativeCPU() &&
312307
this->HostTC.getTriple().isWindowsMSVCEnvironment())
313308
return this->HostTC.getDefaultDebugFormat();
314309
return ToolChain::getDefaultDebugFormat();

clang/lib/Sema/Sema.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,7 @@ void Sema::ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind) {
12501250
}
12511251

12521252
if (getLangOpts().SYCLIsDevice) {
1253+
SYCL().finalizeFreeFunctionKernels();
12531254
// Set the names of the kernels, now that the names have settled down. This
12541255
// needs to happen before we generate the integration headers.
12551256
SYCL().SetSYCLKernelNames();

0 commit comments

Comments
 (0)