diff options
Diffstat (limited to 'clang/lib/Driver')
-rw-r--r-- | clang/lib/Driver/Driver.cpp | 13 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChain.cpp | 9 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChains/AMDGPU.h | 1 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChains/Arch/AArch64.cpp | 15 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChains/Arch/AArch64.h | 1 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChains/BareMetal.cpp | 21 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChains/Clang.cpp | 3 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChains/CommonArgs.cpp | 14 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChains/Cuda.h | 56 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChains/Darwin.h | 8 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChains/Gnu.h | 8 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChains/HIPAMD.h | 1 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChains/HIPSPV.cpp | 9 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChains/LazyDetector.h | 45 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChains/MSVC.h | 8 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChains/MinGW.cpp | 11 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChains/MinGW.h | 5 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChains/ROCm.h | 314 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChains/SYCL.h | 11 |
19 files changed, 81 insertions, 472 deletions
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 853f694..99de951 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -910,7 +910,7 @@ getSystemOffloadArchs(Compilation &C, Action::OffloadKind Kind) { SmallVector<std::string> GPUArchs; if (llvm::ErrorOr<std::string> Executable = - llvm::sys::findProgramByName(Program)) { + llvm::sys::findProgramByName(Program, {C.getDriver().Dir})) { llvm::SmallVector<StringRef> Args{*Executable}; if (Kind == Action::OFK_HIP) Args.push_back("--only=amdgpu"); @@ -4919,13 +4919,14 @@ Action *Driver::BuildOffloadingActions(Compilation &C, } // HIP code in device-only non-RDC mode will bundle the output if it invoked - // the linker. + // the linker or if the user explicitly requested it. bool ShouldBundleHIP = - HIPNoRDC && offloadDeviceOnly() && Args.hasFlag(options::OPT_gpu_bundle_output, - options::OPT_no_gpu_bundle_output, true) && - !llvm::any_of(OffloadActions, - [](Action *A) { return A->getType() != types::TY_Image; }); + options::OPT_no_gpu_bundle_output, false) || + (HIPNoRDC && offloadDeviceOnly() && + llvm::none_of(OffloadActions, [](Action *A) { + return A->getType() != types::TY_Image; + })); // All kinds exit now in device-only mode except for non-RDC mode HIP. if (offloadDeviceOnly() && !ShouldBundleHIP) diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index 1d7dad0..25c6b5a 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -191,9 +191,10 @@ static void getAArch64MultilibFlags(const Driver &D, for (const auto &ArchInfo : AArch64::ArchInfos) if (FeatureSet.contains(ArchInfo->ArchFeature)) ArchName = ArchInfo->Name; - assert(!ArchName.empty() && "at least one architecture should be found"); - MArch.insert(MArch.begin(), ("-march=" + ArchName).str()); - Result.push_back(llvm::join(MArch, "+")); + if (!ArchName.empty()) { + MArch.insert(MArch.begin(), ("-march=" + ArchName).str()); + Result.push_back(llvm::join(MArch, "+")); + } const Arg *BranchProtectionArg = Args.getLastArgNoClaim(options::OPT_mbranch_protection_EQ); @@ -760,7 +761,7 @@ std::string ToolChain::buildCompilerRTBasename(const llvm::opt::ArgList &Args, break; case ToolChain::FT_Shared: if (TT.isOSWindows()) - Suffix = TT.isWindowsGNUEnvironment() ? ".dll.a" : ".lib"; + Suffix = TT.isOSCygMing() ? ".dll.a" : ".lib"; else if (TT.isOSAIX()) Suffix = ".a"; else diff --git a/clang/lib/Driver/ToolChains/AMDGPU.h b/clang/lib/Driver/ToolChains/AMDGPU.h index 513c77d..e5d41e2 100644 --- a/clang/lib/Driver/ToolChains/AMDGPU.h +++ b/clang/lib/Driver/ToolChains/AMDGPU.h @@ -10,7 +10,6 @@ #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_AMDGPU_H #include "Gnu.h" -#include "ROCm.h" #include "clang/Basic/TargetID.h" #include "clang/Driver/Options.h" #include "clang/Driver/Tool.h" diff --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp index 6bd710e..418f9fd 100644 --- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp +++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp @@ -467,3 +467,18 @@ void aarch64::setPAuthABIInTriple(const Driver &D, const ArgList &Args, break; } } + +/// Is the triple {aarch64.aarch64_be}-none-elf? +bool aarch64::isAArch64BareMetal(const llvm::Triple &Triple) { + if (Triple.getArch() != llvm::Triple::aarch64 && + Triple.getArch() != llvm::Triple::aarch64_be) + return false; + + if (Triple.getVendor() != llvm::Triple::UnknownVendor) + return false; + + if (Triple.getOS() != llvm::Triple::UnknownOS) + return false; + + return Triple.getEnvironmentName() == "elf"; +} diff --git a/clang/lib/Driver/ToolChains/Arch/AArch64.h b/clang/lib/Driver/ToolChains/Arch/AArch64.h index 2057272..2765ee8 100644 --- a/clang/lib/Driver/ToolChains/Arch/AArch64.h +++ b/clang/lib/Driver/ToolChains/Arch/AArch64.h @@ -30,6 +30,7 @@ std::string getAArch64TargetCPU(const llvm::opt::ArgList &Args, void setPAuthABIInTriple(const Driver &D, const llvm::opt::ArgList &Args, llvm::Triple &triple); +bool isAArch64BareMetal(const llvm::Triple &Triple); } // end namespace aarch64 } // end namespace target diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp b/clang/lib/Driver/ToolChains/BareMetal.cpp index 497f333..207150e 100644 --- a/clang/lib/Driver/ToolChains/BareMetal.cpp +++ b/clang/lib/Driver/ToolChains/BareMetal.cpp @@ -12,6 +12,7 @@ #include "clang/Driver/CommonArgs.h" #include "clang/Driver/InputInfo.h" +#include "Arch/AArch64.h" #include "Arch/ARM.h" #include "Arch/RISCV.h" #include "clang/Driver/Compilation.h" @@ -31,21 +32,6 @@ using namespace clang::driver; using namespace clang::driver::tools; using namespace clang::driver::toolchains; -/// Is the triple {aarch64.aarch64_be}-none-elf? -static bool isAArch64BareMetal(const llvm::Triple &Triple) { - if (Triple.getArch() != llvm::Triple::aarch64 && - Triple.getArch() != llvm::Triple::aarch64_be) - return false; - - if (Triple.getVendor() != llvm::Triple::UnknownVendor) - return false; - - if (Triple.getOS() != llvm::Triple::UnknownOS) - return false; - - return Triple.getEnvironmentName() == "elf"; -} - static bool isRISCVBareMetal(const llvm::Triple &Triple) { if (!Triple.isRISCV()) return false; @@ -363,8 +349,9 @@ void BareMetal::findMultilibs(const Driver &D, const llvm::Triple &Triple, } bool BareMetal::handlesTarget(const llvm::Triple &Triple) { - return arm::isARMEABIBareMetal(Triple) || isAArch64BareMetal(Triple) || - isRISCVBareMetal(Triple) || isPPCBareMetal(Triple); + return arm::isARMEABIBareMetal(Triple) || + aarch64::isAArch64BareMetal(Triple) || isRISCVBareMetal(Triple) || + isPPCBareMetal(Triple); } Tool *BareMetal::buildLinker() const { diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 9d882db..f4674a5 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -16,6 +16,7 @@ #include "Arch/SystemZ.h" #include "Hexagon.h" #include "PS4CPU.h" +#include "ToolChains/Cuda.h" #include "clang/Basic/CLWarnings.h" #include "clang/Basic/CodeGenOptions.h" #include "clang/Basic/HeaderInclude.h" @@ -5944,7 +5945,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-mms-bitfields"); } - if (Triple.isWindowsGNUEnvironment()) { + if (Triple.isOSCygMing()) { Args.addOptOutFlag(CmdArgs, options::OPT_fauto_import, options::OPT_fno_auto_import); } diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 826e2ea..256c266 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -23,6 +23,7 @@ #include "Hexagon.h" #include "MSP430.h" #include "Solaris.h" +#include "ToolChains/Cuda.h" #include "clang/Basic/CodeGenOptions.h" #include "clang/Config/config.h" #include "clang/Driver/Action.h" @@ -547,15 +548,22 @@ const char *tools::getLDMOption(const llvm::Triple &T, const ArgList &Args) { case llvm::Triple::aarch64: if (T.isOSManagarm()) return "aarch64managarm"; + else if (aarch64::isAArch64BareMetal(T)) + return "aarch64elf"; return "aarch64linux"; case llvm::Triple::aarch64_be: + if (aarch64::isAArch64BareMetal(T)) + return "aarch64elfb"; return "aarch64linuxb"; case llvm::Triple::arm: case llvm::Triple::thumb: case llvm::Triple::armeb: - case llvm::Triple::thumbeb: - return tools::arm::isARMBigEndian(T, Args) ? "armelfb_linux_eabi" - : "armelf_linux_eabi"; + case llvm::Triple::thumbeb: { + bool IsBigEndian = tools::arm::isARMBigEndian(T, Args); + if (arm::isARMEABIBareMetal(T)) + return IsBigEndian ? "armelfb" : "armelf"; + return IsBigEndian ? "armelfb_linux_eabi" : "armelf_linux_eabi"; + } case llvm::Triple::m68k: return "m68kelf"; case llvm::Triple::ppc: diff --git a/clang/lib/Driver/ToolChains/Cuda.h b/clang/lib/Driver/ToolChains/Cuda.h index 259eda6..8aeba53 100644 --- a/clang/lib/Driver/ToolChains/Cuda.h +++ b/clang/lib/Driver/ToolChains/Cuda.h @@ -11,6 +11,7 @@ #include "clang/Basic/Cuda.h" #include "clang/Driver/Action.h" +#include "clang/Driver/CudaInstallationDetector.h" #include "clang/Driver/Multilib.h" #include "clang/Driver/Tool.h" #include "clang/Driver/ToolChain.h" @@ -22,61 +23,6 @@ namespace clang { namespace driver { - -/// A class to find a viable CUDA installation -class CudaInstallationDetector { -private: - const Driver &D; - bool IsValid = false; - CudaVersion Version = CudaVersion::UNKNOWN; - std::string InstallPath; - std::string BinPath; - std::string LibDevicePath; - std::string IncludePath; - llvm::StringMap<std::string> LibDeviceMap; - - // CUDA architectures for which we have raised an error in - // CheckCudaVersionSupportsArch. - mutable std::bitset<(int)OffloadArch::LAST> ArchsWithBadVersion; - -public: - CudaInstallationDetector(const Driver &D, const llvm::Triple &HostTriple, - const llvm::opt::ArgList &Args); - - void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs, - llvm::opt::ArgStringList &CC1Args) const; - - /// Emit an error if Version does not support the given Arch. - /// - /// If either Version or Arch is unknown, does not emit an error. Emits at - /// most one error per Arch. - void CheckCudaVersionSupportsArch(OffloadArch Arch) const; - - /// Check whether we detected a valid Cuda install. - bool isValid() const { return IsValid; } - /// Print information about the detected CUDA installation. - void print(raw_ostream &OS) const; - - /// Get the detected Cuda install's version. - CudaVersion version() const { - return Version == CudaVersion::NEW ? CudaVersion::PARTIALLY_SUPPORTED - : Version; - } - /// Get the detected Cuda installation path. - StringRef getInstallPath() const { return InstallPath; } - /// Get the detected path to Cuda's bin directory. - StringRef getBinPath() const { return BinPath; } - /// Get the detected Cuda Include path. - StringRef getIncludePath() const { return IncludePath; } - /// Get the detected Cuda device library path. - StringRef getLibDevicePath() const { return LibDevicePath; } - /// Get libdevice file for given architecture - std::string getLibDeviceFile(StringRef Gpu) const { - return LibDeviceMap.lookup(Gpu); - } - void WarnIfUnsupportedVersion() const; -}; - namespace tools { namespace NVPTX { diff --git a/clang/lib/Driver/ToolChains/Darwin.h b/clang/lib/Driver/ToolChains/Darwin.h index b38bfe6..d1cfb6f 100644 --- a/clang/lib/Driver/ToolChains/Darwin.h +++ b/clang/lib/Driver/ToolChains/Darwin.h @@ -9,12 +9,12 @@ #ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_DARWIN_H #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_DARWIN_H -#include "Cuda.h" -#include "LazyDetector.h" -#include "ROCm.h" -#include "SYCL.h" #include "clang/Basic/DarwinSDKInfo.h" #include "clang/Basic/LangOptions.h" +#include "clang/Driver/CudaInstallationDetector.h" +#include "clang/Driver/LazyDetector.h" +#include "clang/Driver/RocmInstallationDetector.h" +#include "clang/Driver/SyclInstallationDetector.h" #include "clang/Driver/Tool.h" #include "clang/Driver/ToolChain.h" #include "clang/Driver/XRayArgs.h" diff --git a/clang/lib/Driver/ToolChains/Gnu.h b/clang/lib/Driver/ToolChains/Gnu.h index 3b8df71..4c42a5e5 100644 --- a/clang/lib/Driver/ToolChains/Gnu.h +++ b/clang/lib/Driver/ToolChains/Gnu.h @@ -9,10 +9,10 @@ #ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_GNU_H #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_GNU_H -#include "Cuda.h" -#include "LazyDetector.h" -#include "ROCm.h" -#include "SYCL.h" +#include "clang/Driver/CudaInstallationDetector.h" +#include "clang/Driver/LazyDetector.h" +#include "clang/Driver/RocmInstallationDetector.h" +#include "clang/Driver/SyclInstallationDetector.h" #include "clang/Driver/Tool.h" #include "clang/Driver/ToolChain.h" #include <set> diff --git a/clang/lib/Driver/ToolChains/HIPAMD.h b/clang/lib/Driver/ToolChains/HIPAMD.h index bcc3ebb..30fc01a 100644 --- a/clang/lib/Driver/ToolChains/HIPAMD.h +++ b/clang/lib/Driver/ToolChains/HIPAMD.h @@ -10,6 +10,7 @@ #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPAMD_H #include "AMDGPU.h" +#include "clang/Driver/SyclInstallationDetector.h" #include "clang/Driver/Tool.h" #include "clang/Driver/ToolChain.h" diff --git a/clang/lib/Driver/ToolChains/HIPSPV.cpp b/clang/lib/Driver/ToolChains/HIPSPV.cpp index 643a67f..62bca04 100644 --- a/clang/lib/Driver/ToolChains/HIPSPV.cpp +++ b/clang/lib/Driver/ToolChains/HIPSPV.cpp @@ -69,8 +69,17 @@ void HIPSPV::Linker::constructLinkAndEmitSpirvCommand( // Link LLVM bitcode. ArgStringList LinkArgs{}; + for (auto Input : Inputs) LinkArgs.push_back(Input.getFilename()); + + // Add static device libraries using the common helper function. + // This handles unbundling archives (.a) containing bitcode bundles. + StringRef Arch = getToolChain().getTriple().getArchName(); + StringRef Target = + "generic"; // SPIR-V is generic, no specific target ID like -mcpu + tools::AddStaticDeviceLibsLinking(C, *this, JA, Inputs, Args, LinkArgs, Arch, + Target, /*IsBitCodeSDL=*/true); LinkArgs.append({"-o", TempFile}); const char *LlvmLink = Args.MakeArgString(getToolChain().GetProgramPath("llvm-link")); diff --git a/clang/lib/Driver/ToolChains/LazyDetector.h b/clang/lib/Driver/ToolChains/LazyDetector.h deleted file mode 100644 index 813d00a..0000000 --- a/clang/lib/Driver/ToolChains/LazyDetector.h +++ /dev/null @@ -1,45 +0,0 @@ -//===--- LazyDetector.h - Lazy ToolChain Detection --------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_LAZYDETECTOR_H -#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_LAZYDETECTOR_H - -#include "clang/Driver/Tool.h" -#include "clang/Driver/ToolChain.h" -#include <optional> - -namespace clang { - -/// Simple wrapper for toolchain detector with costly initialization. This -/// delays the creation of the actual detector until its first usage. - -template <class T> class LazyDetector { - const driver::Driver &D; - llvm::Triple Triple; - const llvm::opt::ArgList &Args; - - std::optional<T> Detector; - -public: - LazyDetector(const driver::Driver &D, const llvm::Triple &Triple, - const llvm::opt::ArgList &Args) - : D(D), Triple(Triple), Args(Args) {} - T *operator->() { - if (!Detector) - Detector.emplace(D, Triple, Args); - return &*Detector; - } - const T *operator->() const { - return const_cast<T const *>( - const_cast<LazyDetector &>(*this).operator->()); - } -}; - -} // end namespace clang - -#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_LAZYDETECTOR_H diff --git a/clang/lib/Driver/ToolChains/MSVC.h b/clang/lib/Driver/ToolChains/MSVC.h index b35390c..5c17edc 100644 --- a/clang/lib/Driver/ToolChains/MSVC.h +++ b/clang/lib/Driver/ToolChains/MSVC.h @@ -9,11 +9,11 @@ #ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MSVC_H #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MSVC_H -#include "AMDGPU.h" -#include "Cuda.h" -#include "LazyDetector.h" -#include "SYCL.h" #include "clang/Driver/Compilation.h" +#include "clang/Driver/CudaInstallationDetector.h" +#include "clang/Driver/LazyDetector.h" +#include "clang/Driver/RocmInstallationDetector.h" +#include "clang/Driver/SyclInstallationDetector.h" #include "clang/Driver/Tool.h" #include "clang/Driver/ToolChain.h" #include "llvm/Frontend/Debug/Options.h" diff --git a/clang/lib/Driver/ToolChains/MinGW.cpp b/clang/lib/Driver/ToolChains/MinGW.cpp index 6abd0c0..1bb9bcf 100644 --- a/clang/lib/Driver/ToolChains/MinGW.cpp +++ b/clang/lib/Driver/ToolChains/MinGW.cpp @@ -85,11 +85,18 @@ void tools::MinGW::Linker::AddLibGCC(const ArgList &Args, CmdArgs.push_back("-lmoldname"); CmdArgs.push_back("-lmingwex"); - for (auto Lib : Args.getAllArgValues(options::OPT_l)) + for (auto Lib : Args.getAllArgValues(options::OPT_l)) { if (StringRef(Lib).starts_with("msvcr") || StringRef(Lib).starts_with("ucrt") || - StringRef(Lib).starts_with("crtdll")) + StringRef(Lib).starts_with("crtdll")) { + std::string CRTLib = (llvm::Twine("-l") + Lib).str(); + // Respect the user's chosen crt variant, but still provide it + // again as the last linker argument, because some of the libraries + // we added above may depend on it. + CmdArgs.push_back(Args.MakeArgStringRef(CRTLib)); return; + } + } CmdArgs.push_back("-lmsvcrt"); } diff --git a/clang/lib/Driver/ToolChains/MinGW.h b/clang/lib/Driver/ToolChains/MinGW.h index a9963d8..1730da4 100644 --- a/clang/lib/Driver/ToolChains/MinGW.h +++ b/clang/lib/Driver/ToolChains/MinGW.h @@ -11,8 +11,9 @@ #include "Cuda.h" #include "Gnu.h" -#include "LazyDetector.h" -#include "ROCm.h" +#include "clang/Driver/CudaInstallationDetector.h" +#include "clang/Driver/LazyDetector.h" +#include "clang/Driver/RocmInstallationDetector.h" #include "clang/Driver/Tool.h" #include "clang/Driver/ToolChain.h" #include "llvm/Support/ErrorOr.h" diff --git a/clang/lib/Driver/ToolChains/ROCm.h b/clang/lib/Driver/ToolChains/ROCm.h deleted file mode 100644 index ebd5443..0000000 --- a/clang/lib/Driver/ToolChains/ROCm.h +++ /dev/null @@ -1,314 +0,0 @@ -//===--- ROCm.h - ROCm installation detector --------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_ROCM_H -#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_ROCM_H - -#include "clang/Basic/Cuda.h" -#include "clang/Basic/LLVM.h" -#include "clang/Driver/CommonArgs.h" -#include "clang/Driver/Driver.h" -#include "clang/Driver/Options.h" -#include "clang/Driver/SanitizerArgs.h" -#include "llvm/ADT/SmallString.h" -#include "llvm/ADT/StringMap.h" -#include "llvm/Option/ArgList.h" -#include "llvm/Support/VersionTuple.h" -#include "llvm/TargetParser/TargetParser.h" -#include "llvm/TargetParser/Triple.h" - -namespace clang { -namespace driver { - -/// ABI version of device library. -struct DeviceLibABIVersion { - unsigned ABIVersion = 0; - DeviceLibABIVersion(unsigned V) : ABIVersion(V) {} - static DeviceLibABIVersion fromCodeObjectVersion(unsigned CodeObjectVersion) { - if (CodeObjectVersion < 4) - CodeObjectVersion = 4; - return DeviceLibABIVersion(CodeObjectVersion * 100); - } - /// Whether ABI version bc file is requested. - /// ABIVersion is code object version multiplied by 100. Code object v4 - /// and below works with ROCm 5.0 and below which does not have - /// abi_version_*.bc. Code object v5 requires abi_version_500.bc. - bool requiresLibrary() { return ABIVersion >= 500; } - std::string toString() { return Twine(getAsCodeObjectVersion()).str(); } - - unsigned getAsCodeObjectVersion() const { - assert(ABIVersion % 100 == 0 && "Not supported"); - return ABIVersion / 100; - } -}; - -/// A class to find a viable ROCM installation -/// TODO: Generalize to handle libclc. -class RocmInstallationDetector { -private: - struct ConditionalLibrary { - SmallString<0> On; - SmallString<0> Off; - - bool isValid() const { return !On.empty() && !Off.empty(); } - - StringRef get(bool Enabled) const { - assert(isValid()); - return Enabled ? On : Off; - } - }; - - // Installation path candidate. - struct Candidate { - llvm::SmallString<0> Path; - bool StrictChecking; - // Release string for ROCm packages built with SPACK if not empty. The - // installation directories of ROCm packages built with SPACK follow the - // convention <package_name>-<rocm_release_string>-<hash>. - std::string SPACKReleaseStr; - - bool isSPACK() const { return !SPACKReleaseStr.empty(); } - Candidate(std::string Path, bool StrictChecking = false, - StringRef SPACKReleaseStr = {}) - : Path(Path), StrictChecking(StrictChecking), - SPACKReleaseStr(SPACKReleaseStr.str()) {} - }; - - struct CommonBitcodeLibsPreferences { - CommonBitcodeLibsPreferences(const Driver &D, - const llvm::opt::ArgList &DriverArgs, - StringRef GPUArch, - const Action::OffloadKind DeviceOffloadingKind, - const bool NeedsASanRT); - - DeviceLibABIVersion ABIVer; - bool IsOpenMP; - bool Wave64; - bool DAZ; - bool FiniteOnly; - bool UnsafeMathOpt; - bool FastRelaxedMath; - bool CorrectSqrt; - bool GPUSan; - }; - - const Driver &D; - bool HasHIPRuntime = false; - bool HasDeviceLibrary = false; - bool HasHIPStdParLibrary = false; - bool HasRocThrustLibrary = false; - bool HasRocPrimLibrary = false; - - // Default version if not detected or specified. - const unsigned DefaultVersionMajor = 3; - const unsigned DefaultVersionMinor = 5; - const char *DefaultVersionPatch = "0"; - - // The version string in Major.Minor.Patch format. - std::string DetectedVersion; - // Version containing major and minor. - llvm::VersionTuple VersionMajorMinor; - // Version containing patch. - std::string VersionPatch; - - // ROCm path specified by --rocm-path. - StringRef RocmPathArg; - // ROCm device library paths specified by --rocm-device-lib-path. - std::vector<std::string> RocmDeviceLibPathArg; - // HIP runtime path specified by --hip-path. - StringRef HIPPathArg; - // HIP Standard Parallel Algorithm acceleration library specified by - // --hipstdpar-path - StringRef HIPStdParPathArg; - // rocThrust algorithm library specified by --hipstdpar-thrust-path - StringRef HIPRocThrustPathArg; - // rocPrim algorithm library specified by --hipstdpar-prim-path - StringRef HIPRocPrimPathArg; - // HIP version specified by --hip-version. - StringRef HIPVersionArg; - // Wheter -nogpulib is specified. - bool NoBuiltinLibs = false; - - // Paths - SmallString<0> InstallPath; - SmallString<0> BinPath; - SmallString<0> LibPath; - SmallString<0> LibDevicePath; - SmallString<0> IncludePath; - SmallString<0> SharePath; - llvm::StringMap<std::string> LibDeviceMap; - - // Libraries that are always linked. - SmallString<0> OCML; - SmallString<0> OCKL; - - // Libraries that are always linked depending on the language - SmallString<0> OpenCL; - - // Asan runtime library - SmallString<0> AsanRTL; - - // Libraries swapped based on compile flags. - ConditionalLibrary WavefrontSize64; - ConditionalLibrary FiniteOnly; - ConditionalLibrary UnsafeMath; - ConditionalLibrary DenormalsAreZero; - ConditionalLibrary CorrectlyRoundedSqrt; - - // Maps ABI version to library path. The version number is in the format of - // three digits as used in the ABI version library name. - std::map<unsigned, std::string> ABIVersionMap; - - // Cache ROCm installation search paths. - SmallVector<Candidate, 4> ROCmSearchDirs; - bool PrintROCmSearchDirs; - bool Verbose; - - bool allGenericLibsValid() const { - return !OCML.empty() && !OCKL.empty() && !OpenCL.empty() && - WavefrontSize64.isValid() && FiniteOnly.isValid() && - UnsafeMath.isValid() && DenormalsAreZero.isValid() && - CorrectlyRoundedSqrt.isValid(); - } - - void scanLibDevicePath(llvm::StringRef Path); - bool parseHIPVersionFile(llvm::StringRef V); - const SmallVectorImpl<Candidate> &getInstallationPathCandidates(); - - /// Find the path to a SPACK package under the ROCm candidate installation - /// directory if the candidate is a SPACK ROCm candidate. \returns empty - /// string if the candidate is not SPACK ROCm candidate or the requested - /// package is not found. - llvm::SmallString<0> findSPACKPackage(const Candidate &Cand, - StringRef PackageName); - -public: - RocmInstallationDetector(const Driver &D, const llvm::Triple &HostTriple, - const llvm::opt::ArgList &Args, - bool DetectHIPRuntime = true, - bool DetectDeviceLib = false); - - /// Get file paths of default bitcode libraries common to AMDGPU based - /// toolchains. - llvm::SmallVector<ToolChain::BitCodeLibraryInfo, 12> - getCommonBitcodeLibs(const llvm::opt::ArgList &DriverArgs, - StringRef LibDeviceFile, StringRef GPUArch, - const Action::OffloadKind DeviceOffloadingKind, - const bool NeedsASanRT) const; - /// Check file paths of default bitcode libraries common to AMDGPU based - /// toolchains. \returns false if there are invalid or missing files. - bool checkCommonBitcodeLibs(StringRef GPUArch, StringRef LibDeviceFile, - DeviceLibABIVersion ABIVer) const; - - /// Check whether we detected a valid HIP runtime. - bool hasHIPRuntime() const { return HasHIPRuntime; } - - /// Check whether we detected a valid ROCm device library. - bool hasDeviceLibrary() const { return HasDeviceLibrary; } - - /// Check whether we detected a valid HIP STDPAR Acceleration library. - bool hasHIPStdParLibrary() const { return HasHIPStdParLibrary; } - - /// Print information about the detected ROCm installation. - void print(raw_ostream &OS) const; - - /// Get the detected Rocm install's version. - // RocmVersion version() const { return Version; } - - /// Get the detected Rocm installation path. - StringRef getInstallPath() const { return InstallPath; } - - /// Get the detected path to Rocm's bin directory. - // StringRef getBinPath() const { return BinPath; } - - /// Get the detected Rocm Include path. - StringRef getIncludePath() const { return IncludePath; } - - /// Get the detected Rocm library path. - StringRef getLibPath() const { return LibPath; } - - /// Get the detected Rocm device library path. - StringRef getLibDevicePath() const { return LibDevicePath; } - - StringRef getOCMLPath() const { - assert(!OCML.empty()); - return OCML; - } - - StringRef getOCKLPath() const { - assert(!OCKL.empty()); - return OCKL; - } - - StringRef getOpenCLPath() const { - assert(!OpenCL.empty()); - return OpenCL; - } - - /// Returns empty string of Asan runtime library is not available. - StringRef getAsanRTLPath() const { return AsanRTL; } - - StringRef getWavefrontSize64Path(bool Enabled) const { - return WavefrontSize64.get(Enabled); - } - - StringRef getFiniteOnlyPath(bool Enabled) const { - return FiniteOnly.get(Enabled); - } - - StringRef getUnsafeMathPath(bool Enabled) const { - return UnsafeMath.get(Enabled); - } - - StringRef getDenormalsAreZeroPath(bool Enabled) const { - return DenormalsAreZero.get(Enabled); - } - - StringRef getCorrectlyRoundedSqrtPath(bool Enabled) const { - return CorrectlyRoundedSqrt.get(Enabled); - } - - StringRef getABIVersionPath(DeviceLibABIVersion ABIVer) const { - auto Loc = ABIVersionMap.find(ABIVer.ABIVersion); - if (Loc == ABIVersionMap.end()) - return StringRef(); - return Loc->second; - } - - /// Get libdevice file for given architecture - StringRef getLibDeviceFile(StringRef Gpu) const { - auto Loc = LibDeviceMap.find(Gpu); - if (Loc == LibDeviceMap.end()) - return ""; - return Loc->second; - } - - void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs, - llvm::opt::ArgStringList &CC1Args) const; - - void detectDeviceLibrary(); - void detectHIPRuntime(); - - /// Get the values for --rocm-device-lib-path arguments - ArrayRef<std::string> getRocmDeviceLibPathArg() const { - return RocmDeviceLibPathArg; - } - - /// Get the value for --rocm-path argument - StringRef getRocmPathArg() const { return RocmPathArg; } - - /// Get the value for --hip-version argument - StringRef getHIPVersionArg() const { return HIPVersionArg; } - - StringRef getHIPVersion() const { return DetectedVersion; } -}; - -} // end namespace driver -} // end namespace clang - -#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_ROCM_H diff --git a/clang/lib/Driver/ToolChains/SYCL.h b/clang/lib/Driver/ToolChains/SYCL.h index 2a8b4ec..be4ba47 100644 --- a/clang/lib/Driver/ToolChains/SYCL.h +++ b/clang/lib/Driver/ToolChains/SYCL.h @@ -9,21 +9,12 @@ #ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_SYCL_H #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_SYCL_H +#include "clang/Driver/SyclInstallationDetector.h" #include "clang/Driver/Tool.h" #include "clang/Driver/ToolChain.h" namespace clang { namespace driver { - -class SYCLInstallationDetector { -public: - SYCLInstallationDetector(const Driver &D, const llvm::Triple &HostTriple, - const llvm::opt::ArgList &Args); - - void addSYCLIncludeArgs(const llvm::opt::ArgList &DriverArgs, - llvm::opt::ArgStringList &CC1Args) const; -}; - namespace toolchains { class LLVM_LIBRARY_VISIBILITY SYCLToolChain : public ToolChain { |