================ @@ -6601,6 +6573,72 @@ std::string Driver::GetClPchPath(Compilation &C, StringRef BaseName) const { return std::string(Output); } +const ToolChain &Driver::getOffloadToolChain( + const llvm::opt::ArgList &Args, const Action::OffloadKind Kind, + const llvm::Triple &Target, const llvm::Triple &AuxTarget) const { + auto &TC = ToolChains[Target.str() + "/" + AuxTarget.str()]; + auto &HostTC = ToolChains[AuxTarget.str()]; + + assert(HostTC && "Host toolchain for offloading doesn't exit?"); + if (!TC) { + // Detect the toolchain based off of the target operating system. + switch (Target.getOS()) { + case llvm::Triple::CUDA: + TC = std::make_unique<toolchains::CudaToolChain>(*this, Target, *HostTC, + Args); + break; + case llvm::Triple::AMDHSA: + if (Kind == Action::OFK_HIP) + TC = std::make_unique<toolchains::HIPAMDToolChain>(*this, Target, + *HostTC, Args); + else if (Kind == Action::OFK_OpenMP) + TC = std::make_unique<toolchains::AMDGPUOpenMPToolChain>(*this, Target, + *HostTC, Args); + break; + default: + break; + } + } + if (!TC) { + // Detect the toolchain based off of the target architecture if that failed. + switch (Target.getArch()) { + case llvm::Triple::spir: + case llvm::Triple::spir64: + case llvm::Triple::spirv: + case llvm::Triple::spirv32: + case llvm::Triple::spirv64: + switch (Kind) { + case Action::OFK_SYCL: + TC = std::make_unique<toolchains::SYCLToolChain>(*this, Target, *HostTC, + Args); + break; + case Action::OFK_HIP: + TC = std::make_unique<toolchains::HIPSPVToolChain>(*this, Target, + *HostTC, Args); + break; + case Action::OFK_OpenMP: + TC = std::make_unique<toolchains::SPIRVOpenMPToolChain>(*this, Target, + *HostTC, Args); + break; + case Action::OFK_Cuda: + TC = std::make_unique<toolchains::CudaToolChain>(*this, Target, *HostTC, + Args); + break; + default: + break; + } + break; + default: + break; + } + } + + // If all else fails, just look up the normal toolchain for the target. + if (!TC) ---------------- Artem-B wrote:
If it returns a reference, it implies that it can not fail. If we do expect to see failures, we should return std::optional instead. https://github.com/llvm/llvm-project/pull/125095 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits