From 4f16845d9170f61d50ad3a5254911a6ddad42399 Mon Sep 17 00:00:00 2001 From: Alexey Bader Date: Fri, 11 Jul 2025 16:44:26 -0700 Subject: [PATCH] [NFC][Driver] Refactor SYCLTargetInfoList init. 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(...)) ... ``` --- clang/lib/Driver/Driver.cpp | 66 +++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 35 deletions(-) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 4dfe6160bc43f..258ee6ffb403c 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -6388,46 +6388,42 @@ class OffloadingActionBuilder final { ToolChains, [&](auto &TC) { return TT == TC->getTriple(); }); assert(TCIt != ToolChains.end() && "Toolchain was not created for this platform"); - if (!TT.isNVPTX() && !TT.isAMDGCN()) { - // When users specify the target as 'intel_gpu_*', the proper - // triple is 'spir64_gen'. The given string from intel_gpu_* - // is the target device. - if (TT.isSPIR() && - TT.getSubArch() == llvm::Triple::SPIRSubArch_gen) { - // Multiple spir64_gen targets are allowed to be used via the - // -fsycl-targets=spir64_gen and -fsycl-targets=intel_gpu_* - // specifiers. Using an index through the known GpuArchList - // values, increment through them accordingly to allow for - // the multiple settings as well as preventing re-use. - while (TT != GpuArchList[GenIndex].first && - GenIndex < GpuArchList.size()) - ++GenIndex; - if (GpuArchList[GenIndex].first != TT) - // No match. - continue; - StringRef Device(GpuArchList[GenIndex].second); - SYCLTargetInfoList.emplace_back( - *TCIt, Device.empty() ? nullptr : Device.data()); - ++GenIndex; - continue; - } - SYCLTargetInfoList.emplace_back(*TCIt, nullptr); - } else { - const char *OffloadArch = nullptr; + if (TT.isNVPTX() || TT.isAMDGCN()) { for (auto &TargetTripleArchPair : GpuArchList) { if (TT == TargetTripleArchPair.first) { - OffloadArch = TargetTripleArchPair.second; - // Add an arch to the SYCLTargetInfoList - // only if it is not already present in the list. - auto Arch = llvm::find_if( - SYCLTargetInfoList, [&](auto &DeviceTargetInfo) { - return OffloadArch == DeviceTargetInfo.BoundArch; - }); - - if (Arch == SYCLTargetInfoList.end()) + const char *OffloadArch = TargetTripleArchPair.second; + // Add an arch to the SYCLTargetInfoList only if it is not + // already present in the list. + if (llvm::none_of( + SYCLTargetInfoList, [&](auto &DeviceTargetInfo) { + return OffloadArch == DeviceTargetInfo.BoundArch; + })) SYCLTargetInfoList.emplace_back(*TCIt, OffloadArch); } } + } else if (TT.isSPIR() && + TT.getSubArch() == llvm::Triple::SPIRSubArch_gen) { + // When users specify the target as 'intel_gpu_*', the proper + // triple is 'spir64_gen'. The given string from intel_gpu_* is + // the target device. + + // Multiple spir64_gen targets are allowed to be used via the + // -fsycl-targets=spir64_gen and -fsycl-targets=intel_gpu_* + // specifiers. Using an index through the known GpuArchList + // values, increment through them accordingly to allow for the + // multiple settings as well as preventing re-use. + while (TT != GpuArchList[GenIndex].first && + GenIndex < GpuArchList.size()) + ++GenIndex; + if (GpuArchList[GenIndex].first != TT) + // No match. + continue; + StringRef Device(GpuArchList[GenIndex].second); + SYCLTargetInfoList.emplace_back( + *TCIt, Device.empty() ? nullptr : Device.data()); + ++GenIndex; + } else { + SYCLTargetInfoList.emplace_back(*TCIt, nullptr); } } }