Skip to content

Commit bc273ff

Browse files
authored
[NFC][Driver] Refactor SYCLTargetInfoList init. (#19414)
Changed the logic from ```c++ if ( not NVPTX and not AMDGCN) { if (Intel) { // process Intel case continue; } // process targets which are not Intel, NVPTX or AMDGCN } else { // process NVPTX and AMDGCN case } ``` to more readable (in my opinion) ```c++ if (NVPTX or AMDGCN) { // process NVPTX and AMDGCN case } else if (Intel) { // process Intel case } else { // process targets which are not Intel, NVPTX or AMDGCN } ``` Inside NVPTX and AMDGCN branch replaced ```c++ auto it = find_if(...); if (it == end) ... ``` to ```c++ if (none_of(...)) ... ```
1 parent 3928e41 commit bc273ff

File tree

1 file changed

+31
-35
lines changed

1 file changed

+31
-35
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6383,46 +6383,42 @@ class OffloadingActionBuilder final {
63836383
ToolChains, [&](auto &TC) { return TT == TC->getTriple(); });
63846384
assert(TCIt != ToolChains.end() &&
63856385
"Toolchain was not created for this platform");
6386-
if (!TT.isNVPTX() && !TT.isAMDGCN()) {
6387-
// When users specify the target as 'intel_gpu_*', the proper
6388-
// triple is 'spir64_gen'. The given string from intel_gpu_*
6389-
// is the target device.
6390-
if (TT.isSPIR() &&
6391-
TT.getSubArch() == llvm::Triple::SPIRSubArch_gen) {
6392-
// Multiple spir64_gen targets are allowed to be used via the
6393-
// -fsycl-targets=spir64_gen and -fsycl-targets=intel_gpu_*
6394-
// specifiers. Using an index through the known GpuArchList
6395-
// values, increment through them accordingly to allow for
6396-
// the multiple settings as well as preventing re-use.
6397-
while (TT != GpuArchList[GenIndex].first &&
6398-
GenIndex < GpuArchList.size())
6399-
++GenIndex;
6400-
if (GpuArchList[GenIndex].first != TT)
6401-
// No match.
6402-
continue;
6403-
StringRef Device(GpuArchList[GenIndex].second);
6404-
SYCLTargetInfoList.emplace_back(
6405-
*TCIt, Device.empty() ? nullptr : Device.data());
6406-
++GenIndex;
6407-
continue;
6408-
}
6409-
SYCLTargetInfoList.emplace_back(*TCIt, nullptr);
6410-
} else {
6411-
const char *OffloadArch = nullptr;
6386+
if (TT.isNVPTX() || TT.isAMDGCN()) {
64126387
for (auto &TargetTripleArchPair : GpuArchList) {
64136388
if (TT == TargetTripleArchPair.first) {
6414-
OffloadArch = TargetTripleArchPair.second;
6415-
// Add an arch to the SYCLTargetInfoList
6416-
// only if it is not already present in the list.
6417-
auto Arch = llvm::find_if(
6418-
SYCLTargetInfoList, [&](auto &DeviceTargetInfo) {
6419-
return OffloadArch == DeviceTargetInfo.BoundArch;
6420-
});
6421-
6422-
if (Arch == SYCLTargetInfoList.end())
6389+
const char *OffloadArch = TargetTripleArchPair.second;
6390+
// Add an arch to the SYCLTargetInfoList only if it is not
6391+
// already present in the list.
6392+
if (llvm::none_of(
6393+
SYCLTargetInfoList, [&](auto &DeviceTargetInfo) {
6394+
return OffloadArch == DeviceTargetInfo.BoundArch;
6395+
}))
64236396
SYCLTargetInfoList.emplace_back(*TCIt, OffloadArch);
64246397
}
64256398
}
6399+
} else if (TT.isSPIR() &&
6400+
TT.getSubArch() == llvm::Triple::SPIRSubArch_gen) {
6401+
// When users specify the target as 'intel_gpu_*', the proper
6402+
// triple is 'spir64_gen'. The given string from intel_gpu_* is
6403+
// the target device.
6404+
6405+
// Multiple spir64_gen targets are allowed to be used via the
6406+
// -fsycl-targets=spir64_gen and -fsycl-targets=intel_gpu_*
6407+
// specifiers. Using an index through the known GpuArchList
6408+
// values, increment through them accordingly to allow for the
6409+
// multiple settings as well as preventing re-use.
6410+
while (TT != GpuArchList[GenIndex].first &&
6411+
GenIndex < GpuArchList.size())
6412+
++GenIndex;
6413+
if (GpuArchList[GenIndex].first != TT)
6414+
// No match.
6415+
continue;
6416+
StringRef Device(GpuArchList[GenIndex].second);
6417+
SYCLTargetInfoList.emplace_back(
6418+
*TCIt, Device.empty() ? nullptr : Device.data());
6419+
++GenIndex;
6420+
} else {
6421+
SYCLTargetInfoList.emplace_back(*TCIt, nullptr);
64266422
}
64276423
}
64286424
} else if (HasValidSYCLRuntime) {

0 commit comments

Comments
 (0)