xref: /openbsd-src/gnu/llvm/clang/lib/Driver/ToolChains/Cuda.cpp (revision 12c855180aad702bbcca06e0398d774beeafb155)
1e5dd7070Spatrick //===--- Cuda.cpp - Cuda Tool and ToolChain Implementations -----*- C++ -*-===//
2e5dd7070Spatrick //
3e5dd7070Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e5dd7070Spatrick // See https://llvm.org/LICENSE.txt for license information.
5e5dd7070Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6e5dd7070Spatrick //
7e5dd7070Spatrick //===----------------------------------------------------------------------===//
8e5dd7070Spatrick 
9e5dd7070Spatrick #include "Cuda.h"
10e5dd7070Spatrick #include "CommonArgs.h"
11e5dd7070Spatrick #include "clang/Basic/Cuda.h"
12e5dd7070Spatrick #include "clang/Config/config.h"
13e5dd7070Spatrick #include "clang/Driver/Compilation.h"
14e5dd7070Spatrick #include "clang/Driver/Distro.h"
15e5dd7070Spatrick #include "clang/Driver/Driver.h"
16e5dd7070Spatrick #include "clang/Driver/DriverDiagnostic.h"
17a9ac8606Spatrick #include "clang/Driver/InputInfo.h"
18e5dd7070Spatrick #include "clang/Driver/Options.h"
19*12c85518Srobert #include "llvm/ADT/StringExtras.h"
20e5dd7070Spatrick #include "llvm/Option/ArgList.h"
21e5dd7070Spatrick #include "llvm/Support/FileSystem.h"
22*12c85518Srobert #include "llvm/Support/FormatAdapters.h"
23*12c85518Srobert #include "llvm/Support/FormatVariadic.h"
24ec727ea7Spatrick #include "llvm/Support/Host.h"
25e5dd7070Spatrick #include "llvm/Support/Path.h"
26e5dd7070Spatrick #include "llvm/Support/Process.h"
27e5dd7070Spatrick #include "llvm/Support/Program.h"
28ec727ea7Spatrick #include "llvm/Support/TargetParser.h"
29e5dd7070Spatrick #include "llvm/Support/VirtualFileSystem.h"
30e5dd7070Spatrick #include <system_error>
31e5dd7070Spatrick 
32e5dd7070Spatrick using namespace clang::driver;
33e5dd7070Spatrick using namespace clang::driver::toolchains;
34e5dd7070Spatrick using namespace clang::driver::tools;
35e5dd7070Spatrick using namespace clang;
36e5dd7070Spatrick using namespace llvm::opt;
37e5dd7070Spatrick 
38ec727ea7Spatrick namespace {
39e5dd7070Spatrick 
getCudaVersion(uint32_t raw_version)40ec727ea7Spatrick CudaVersion getCudaVersion(uint32_t raw_version) {
41ec727ea7Spatrick   if (raw_version < 7050)
42ec727ea7Spatrick     return CudaVersion::CUDA_70;
43ec727ea7Spatrick   if (raw_version < 8000)
44ec727ea7Spatrick     return CudaVersion::CUDA_75;
45ec727ea7Spatrick   if (raw_version < 9000)
46ec727ea7Spatrick     return CudaVersion::CUDA_80;
47ec727ea7Spatrick   if (raw_version < 9010)
48ec727ea7Spatrick     return CudaVersion::CUDA_90;
49ec727ea7Spatrick   if (raw_version < 9020)
50ec727ea7Spatrick     return CudaVersion::CUDA_91;
51ec727ea7Spatrick   if (raw_version < 10000)
52ec727ea7Spatrick     return CudaVersion::CUDA_92;
53ec727ea7Spatrick   if (raw_version < 10010)
54ec727ea7Spatrick     return CudaVersion::CUDA_100;
55ec727ea7Spatrick   if (raw_version < 10020)
56ec727ea7Spatrick     return CudaVersion::CUDA_101;
57ec727ea7Spatrick   if (raw_version < 11000)
58ec727ea7Spatrick     return CudaVersion::CUDA_102;
59ec727ea7Spatrick   if (raw_version < 11010)
60ec727ea7Spatrick     return CudaVersion::CUDA_110;
61a9ac8606Spatrick   if (raw_version < 11020)
62a9ac8606Spatrick     return CudaVersion::CUDA_111;
63*12c85518Srobert   if (raw_version < 11030)
64*12c85518Srobert     return CudaVersion::CUDA_112;
65*12c85518Srobert   if (raw_version < 11040)
66*12c85518Srobert     return CudaVersion::CUDA_113;
67*12c85518Srobert   if (raw_version < 11050)
68*12c85518Srobert     return CudaVersion::CUDA_114;
69*12c85518Srobert   if (raw_version < 11060)
70*12c85518Srobert     return CudaVersion::CUDA_115;
71*12c85518Srobert   if (raw_version < 11070)
72*12c85518Srobert     return CudaVersion::CUDA_116;
73*12c85518Srobert   if (raw_version < 11080)
74*12c85518Srobert     return CudaVersion::CUDA_117;
75*12c85518Srobert   if (raw_version < 11090)
76*12c85518Srobert     return CudaVersion::CUDA_118;
77*12c85518Srobert   return CudaVersion::NEW;
78ec727ea7Spatrick }
79ec727ea7Spatrick 
parseCudaHFile(llvm::StringRef Input)80*12c85518Srobert CudaVersion parseCudaHFile(llvm::StringRef Input) {
81ec727ea7Spatrick   // Helper lambda which skips the words if the line starts with them or returns
82*12c85518Srobert   // std::nullopt otherwise.
83ec727ea7Spatrick   auto StartsWithWords =
84ec727ea7Spatrick       [](llvm::StringRef Line,
85*12c85518Srobert          const SmallVector<StringRef, 3> words) -> std::optional<StringRef> {
86ec727ea7Spatrick     for (StringRef word : words) {
87ec727ea7Spatrick       if (!Line.consume_front(word))
88ec727ea7Spatrick         return {};
89ec727ea7Spatrick       Line = Line.ltrim();
90ec727ea7Spatrick     }
91ec727ea7Spatrick     return Line;
92ec727ea7Spatrick   };
93ec727ea7Spatrick 
94ec727ea7Spatrick   Input = Input.ltrim();
95ec727ea7Spatrick   while (!Input.empty()) {
96ec727ea7Spatrick     if (auto Line =
97ec727ea7Spatrick             StartsWithWords(Input.ltrim(), {"#", "define", "CUDA_VERSION"})) {
98ec727ea7Spatrick       uint32_t RawVersion;
99ec727ea7Spatrick       Line->consumeInteger(10, RawVersion);
100*12c85518Srobert       return getCudaVersion(RawVersion);
101ec727ea7Spatrick     }
102ec727ea7Spatrick     // Find next non-empty line.
103ec727ea7Spatrick     Input = Input.drop_front(Input.find_first_of("\n\r")).ltrim();
104ec727ea7Spatrick   }
105*12c85518Srobert   return CudaVersion::UNKNOWN;
106ec727ea7Spatrick }
107ec727ea7Spatrick } // namespace
108ec727ea7Spatrick 
WarnIfUnsupportedVersion()109e5dd7070Spatrick void CudaInstallationDetector::WarnIfUnsupportedVersion() {
110*12c85518Srobert   if (Version > CudaVersion::PARTIALLY_SUPPORTED) {
111*12c85518Srobert     std::string VersionString = CudaVersionToString(Version);
112*12c85518Srobert     if (!VersionString.empty())
113*12c85518Srobert       VersionString.insert(0, " ");
114*12c85518Srobert     D.Diag(diag::warn_drv_new_cuda_version)
115*12c85518Srobert         << VersionString
116*12c85518Srobert         << (CudaVersion::PARTIALLY_SUPPORTED != CudaVersion::FULLY_SUPPORTED)
117*12c85518Srobert         << CudaVersionToString(CudaVersion::PARTIALLY_SUPPORTED);
118*12c85518Srobert   } else if (Version > CudaVersion::FULLY_SUPPORTED)
119*12c85518Srobert     D.Diag(diag::warn_drv_partially_supported_cuda_version)
120*12c85518Srobert         << CudaVersionToString(Version);
121e5dd7070Spatrick }
122e5dd7070Spatrick 
CudaInstallationDetector(const Driver & D,const llvm::Triple & HostTriple,const llvm::opt::ArgList & Args)123e5dd7070Spatrick CudaInstallationDetector::CudaInstallationDetector(
124e5dd7070Spatrick     const Driver &D, const llvm::Triple &HostTriple,
125e5dd7070Spatrick     const llvm::opt::ArgList &Args)
126e5dd7070Spatrick     : D(D) {
127e5dd7070Spatrick   struct Candidate {
128e5dd7070Spatrick     std::string Path;
129e5dd7070Spatrick     bool StrictChecking;
130e5dd7070Spatrick 
131e5dd7070Spatrick     Candidate(std::string Path, bool StrictChecking = false)
132e5dd7070Spatrick         : Path(Path), StrictChecking(StrictChecking) {}
133e5dd7070Spatrick   };
134e5dd7070Spatrick   SmallVector<Candidate, 4> Candidates;
135e5dd7070Spatrick 
136e5dd7070Spatrick   // In decreasing order so we prefer newer versions to older versions.
137e5dd7070Spatrick   std::initializer_list<const char *> Versions = {"8.0", "7.5", "7.0"};
138ec727ea7Spatrick   auto &FS = D.getVFS();
139e5dd7070Spatrick 
140e5dd7070Spatrick   if (Args.hasArg(clang::driver::options::OPT_cuda_path_EQ)) {
141e5dd7070Spatrick     Candidates.emplace_back(
142e5dd7070Spatrick         Args.getLastArgValue(clang::driver::options::OPT_cuda_path_EQ).str());
143e5dd7070Spatrick   } else if (HostTriple.isOSWindows()) {
144e5dd7070Spatrick     for (const char *Ver : Versions)
145e5dd7070Spatrick       Candidates.emplace_back(
146e5dd7070Spatrick           D.SysRoot + "/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v" +
147e5dd7070Spatrick           Ver);
148e5dd7070Spatrick   } else {
149e5dd7070Spatrick     if (!Args.hasArg(clang::driver::options::OPT_cuda_path_ignore_env)) {
150e5dd7070Spatrick       // Try to find ptxas binary. If the executable is located in a directory
151e5dd7070Spatrick       // called 'bin/', its parent directory might be a good guess for a valid
152e5dd7070Spatrick       // CUDA installation.
153e5dd7070Spatrick       // However, some distributions might installs 'ptxas' to /usr/bin. In that
154e5dd7070Spatrick       // case the candidate would be '/usr' which passes the following checks
155e5dd7070Spatrick       // because '/usr/include' exists as well. To avoid this case, we always
156e5dd7070Spatrick       // check for the directory potentially containing files for libdevice,
157e5dd7070Spatrick       // even if the user passes -nocudalib.
158e5dd7070Spatrick       if (llvm::ErrorOr<std::string> ptxas =
159e5dd7070Spatrick               llvm::sys::findProgramByName("ptxas")) {
160e5dd7070Spatrick         SmallString<256> ptxasAbsolutePath;
161e5dd7070Spatrick         llvm::sys::fs::real_path(*ptxas, ptxasAbsolutePath);
162e5dd7070Spatrick 
163e5dd7070Spatrick         StringRef ptxasDir = llvm::sys::path::parent_path(ptxasAbsolutePath);
164e5dd7070Spatrick         if (llvm::sys::path::filename(ptxasDir) == "bin")
165ec727ea7Spatrick           Candidates.emplace_back(
166ec727ea7Spatrick               std::string(llvm::sys::path::parent_path(ptxasDir)),
167e5dd7070Spatrick               /*StrictChecking=*/true);
168e5dd7070Spatrick       }
169e5dd7070Spatrick     }
170e5dd7070Spatrick 
171e5dd7070Spatrick     Candidates.emplace_back(D.SysRoot + "/usr/local/cuda");
172e5dd7070Spatrick     for (const char *Ver : Versions)
173e5dd7070Spatrick       Candidates.emplace_back(D.SysRoot + "/usr/local/cuda-" + Ver);
174e5dd7070Spatrick 
175ec727ea7Spatrick     Distro Dist(FS, llvm::Triple(llvm::sys::getProcessTriple()));
176e5dd7070Spatrick     if (Dist.IsDebian() || Dist.IsUbuntu())
177e5dd7070Spatrick       // Special case for Debian to have nvidia-cuda-toolkit work
178e5dd7070Spatrick       // out of the box. More info on http://bugs.debian.org/882505
179e5dd7070Spatrick       Candidates.emplace_back(D.SysRoot + "/usr/lib/cuda");
180e5dd7070Spatrick   }
181e5dd7070Spatrick 
182e5dd7070Spatrick   bool NoCudaLib = Args.hasArg(options::OPT_nogpulib);
183e5dd7070Spatrick 
184e5dd7070Spatrick   for (const auto &Candidate : Candidates) {
185e5dd7070Spatrick     InstallPath = Candidate.Path;
186ec727ea7Spatrick     if (InstallPath.empty() || !FS.exists(InstallPath))
187e5dd7070Spatrick       continue;
188e5dd7070Spatrick 
189e5dd7070Spatrick     BinPath = InstallPath + "/bin";
190e5dd7070Spatrick     IncludePath = InstallPath + "/include";
191e5dd7070Spatrick     LibDevicePath = InstallPath + "/nvvm/libdevice";
192e5dd7070Spatrick 
193e5dd7070Spatrick     if (!(FS.exists(IncludePath) && FS.exists(BinPath)))
194e5dd7070Spatrick       continue;
195e5dd7070Spatrick     bool CheckLibDevice = (!NoCudaLib || Candidate.StrictChecking);
196e5dd7070Spatrick     if (CheckLibDevice && !FS.exists(LibDevicePath))
197e5dd7070Spatrick       continue;
198e5dd7070Spatrick 
199*12c85518Srobert     Version = CudaVersion::UNKNOWN;
200ec727ea7Spatrick     if (auto CudaHFile = FS.getBufferForFile(InstallPath + "/include/cuda.h"))
201*12c85518Srobert       Version = parseCudaHFile((*CudaHFile)->getBuffer());
202*12c85518Srobert     // As the last resort, make an educated guess between CUDA-7.0, which had
203*12c85518Srobert     // old-style libdevice bitcode, and an unknown recent CUDA version.
204*12c85518Srobert     if (Version == CudaVersion::UNKNOWN) {
205*12c85518Srobert       Version = FS.exists(LibDevicePath + "/libdevice.10.bc")
206*12c85518Srobert                     ? CudaVersion::NEW
207*12c85518Srobert                     : CudaVersion::CUDA_70;
208e5dd7070Spatrick     }
209e5dd7070Spatrick 
210e5dd7070Spatrick     if (Version >= CudaVersion::CUDA_90) {
211e5dd7070Spatrick       // CUDA-9+ uses single libdevice file for all GPU variants.
212e5dd7070Spatrick       std::string FilePath = LibDevicePath + "/libdevice.10.bc";
213e5dd7070Spatrick       if (FS.exists(FilePath)) {
214ec727ea7Spatrick         for (int Arch = (int)CudaArch::SM_30, E = (int)CudaArch::LAST; Arch < E;
215ec727ea7Spatrick              ++Arch) {
216ec727ea7Spatrick           CudaArch GpuArch = static_cast<CudaArch>(Arch);
217ec727ea7Spatrick           if (!IsNVIDIAGpuArch(GpuArch))
218ec727ea7Spatrick             continue;
219ec727ea7Spatrick           std::string GpuArchName(CudaArchToString(GpuArch));
220e5dd7070Spatrick           LibDeviceMap[GpuArchName] = FilePath;
221e5dd7070Spatrick         }
222e5dd7070Spatrick       }
223e5dd7070Spatrick     } else {
224e5dd7070Spatrick       std::error_code EC;
225ec727ea7Spatrick       for (llvm::vfs::directory_iterator LI = FS.dir_begin(LibDevicePath, EC),
226ec727ea7Spatrick                                          LE;
227e5dd7070Spatrick            !EC && LI != LE; LI = LI.increment(EC)) {
228e5dd7070Spatrick         StringRef FilePath = LI->path();
229e5dd7070Spatrick         StringRef FileName = llvm::sys::path::filename(FilePath);
230e5dd7070Spatrick         // Process all bitcode filenames that look like
231e5dd7070Spatrick         // libdevice.compute_XX.YY.bc
232e5dd7070Spatrick         const StringRef LibDeviceName = "libdevice.";
233e5dd7070Spatrick         if (!(FileName.startswith(LibDeviceName) && FileName.endswith(".bc")))
234e5dd7070Spatrick           continue;
235e5dd7070Spatrick         StringRef GpuArch = FileName.slice(
236e5dd7070Spatrick             LibDeviceName.size(), FileName.find('.', LibDeviceName.size()));
237e5dd7070Spatrick         LibDeviceMap[GpuArch] = FilePath.str();
238e5dd7070Spatrick         // Insert map entries for specific devices with this compute
239e5dd7070Spatrick         // capability. NVCC's choice of the libdevice library version is
240e5dd7070Spatrick         // rather peculiar and depends on the CUDA version.
241e5dd7070Spatrick         if (GpuArch == "compute_20") {
242ec727ea7Spatrick           LibDeviceMap["sm_20"] = std::string(FilePath);
243ec727ea7Spatrick           LibDeviceMap["sm_21"] = std::string(FilePath);
244ec727ea7Spatrick           LibDeviceMap["sm_32"] = std::string(FilePath);
245e5dd7070Spatrick         } else if (GpuArch == "compute_30") {
246ec727ea7Spatrick           LibDeviceMap["sm_30"] = std::string(FilePath);
247e5dd7070Spatrick           if (Version < CudaVersion::CUDA_80) {
248ec727ea7Spatrick             LibDeviceMap["sm_50"] = std::string(FilePath);
249ec727ea7Spatrick             LibDeviceMap["sm_52"] = std::string(FilePath);
250ec727ea7Spatrick             LibDeviceMap["sm_53"] = std::string(FilePath);
251e5dd7070Spatrick           }
252ec727ea7Spatrick           LibDeviceMap["sm_60"] = std::string(FilePath);
253ec727ea7Spatrick           LibDeviceMap["sm_61"] = std::string(FilePath);
254ec727ea7Spatrick           LibDeviceMap["sm_62"] = std::string(FilePath);
255e5dd7070Spatrick         } else if (GpuArch == "compute_35") {
256ec727ea7Spatrick           LibDeviceMap["sm_35"] = std::string(FilePath);
257ec727ea7Spatrick           LibDeviceMap["sm_37"] = std::string(FilePath);
258e5dd7070Spatrick         } else if (GpuArch == "compute_50") {
259e5dd7070Spatrick           if (Version >= CudaVersion::CUDA_80) {
260ec727ea7Spatrick             LibDeviceMap["sm_50"] = std::string(FilePath);
261ec727ea7Spatrick             LibDeviceMap["sm_52"] = std::string(FilePath);
262ec727ea7Spatrick             LibDeviceMap["sm_53"] = std::string(FilePath);
263e5dd7070Spatrick           }
264e5dd7070Spatrick         }
265e5dd7070Spatrick       }
266e5dd7070Spatrick     }
267e5dd7070Spatrick 
268e5dd7070Spatrick     // Check that we have found at least one libdevice that we can link in if
269e5dd7070Spatrick     // -nocudalib hasn't been specified.
270e5dd7070Spatrick     if (LibDeviceMap.empty() && !NoCudaLib)
271e5dd7070Spatrick       continue;
272e5dd7070Spatrick 
273e5dd7070Spatrick     IsValid = true;
274e5dd7070Spatrick     break;
275e5dd7070Spatrick   }
276e5dd7070Spatrick }
277e5dd7070Spatrick 
AddCudaIncludeArgs(const ArgList & DriverArgs,ArgStringList & CC1Args) const278e5dd7070Spatrick void CudaInstallationDetector::AddCudaIncludeArgs(
279e5dd7070Spatrick     const ArgList &DriverArgs, ArgStringList &CC1Args) const {
280e5dd7070Spatrick   if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
281e5dd7070Spatrick     // Add cuda_wrappers/* to our system include path.  This lets us wrap
282e5dd7070Spatrick     // standard library headers.
283e5dd7070Spatrick     SmallString<128> P(D.ResourceDir);
284e5dd7070Spatrick     llvm::sys::path::append(P, "include");
285e5dd7070Spatrick     llvm::sys::path::append(P, "cuda_wrappers");
286e5dd7070Spatrick     CC1Args.push_back("-internal-isystem");
287e5dd7070Spatrick     CC1Args.push_back(DriverArgs.MakeArgString(P));
288e5dd7070Spatrick   }
289e5dd7070Spatrick 
290ec727ea7Spatrick   if (DriverArgs.hasArg(options::OPT_nogpuinc))
291e5dd7070Spatrick     return;
292e5dd7070Spatrick 
293e5dd7070Spatrick   if (!isValid()) {
294e5dd7070Spatrick     D.Diag(diag::err_drv_no_cuda_installation);
295e5dd7070Spatrick     return;
296e5dd7070Spatrick   }
297e5dd7070Spatrick 
298e5dd7070Spatrick   CC1Args.push_back("-include");
299e5dd7070Spatrick   CC1Args.push_back("__clang_cuda_runtime_wrapper.h");
300e5dd7070Spatrick }
301e5dd7070Spatrick 
CheckCudaVersionSupportsArch(CudaArch Arch) const302e5dd7070Spatrick void CudaInstallationDetector::CheckCudaVersionSupportsArch(
303e5dd7070Spatrick     CudaArch Arch) const {
304e5dd7070Spatrick   if (Arch == CudaArch::UNKNOWN || Version == CudaVersion::UNKNOWN ||
305a9ac8606Spatrick       ArchsWithBadVersion[(int)Arch])
306e5dd7070Spatrick     return;
307e5dd7070Spatrick 
308e5dd7070Spatrick   auto MinVersion = MinVersionForCudaArch(Arch);
309e5dd7070Spatrick   auto MaxVersion = MaxVersionForCudaArch(Arch);
310e5dd7070Spatrick   if (Version < MinVersion || Version > MaxVersion) {
311a9ac8606Spatrick     ArchsWithBadVersion[(int)Arch] = true;
312e5dd7070Spatrick     D.Diag(diag::err_drv_cuda_version_unsupported)
313e5dd7070Spatrick         << CudaArchToString(Arch) << CudaVersionToString(MinVersion)
314e5dd7070Spatrick         << CudaVersionToString(MaxVersion) << InstallPath
315e5dd7070Spatrick         << CudaVersionToString(Version);
316e5dd7070Spatrick   }
317e5dd7070Spatrick }
318e5dd7070Spatrick 
print(raw_ostream & OS) const319e5dd7070Spatrick void CudaInstallationDetector::print(raw_ostream &OS) const {
320e5dd7070Spatrick   if (isValid())
321e5dd7070Spatrick     OS << "Found CUDA installation: " << InstallPath << ", version "
322e5dd7070Spatrick        << CudaVersionToString(Version) << "\n";
323e5dd7070Spatrick }
324e5dd7070Spatrick 
325e5dd7070Spatrick namespace {
326e5dd7070Spatrick /// Debug info level for the NVPTX devices. We may need to emit different debug
327e5dd7070Spatrick /// info level for the host and for the device itselfi. This type controls
328e5dd7070Spatrick /// emission of the debug info for the devices. It either prohibits disable info
329e5dd7070Spatrick /// emission completely, or emits debug directives only, or emits same debug
330e5dd7070Spatrick /// info as for the host.
331e5dd7070Spatrick enum DeviceDebugInfoLevel {
332e5dd7070Spatrick   DisableDebugInfo,        /// Do not emit debug info for the devices.
333e5dd7070Spatrick   DebugDirectivesOnly,     /// Emit only debug directives.
334e5dd7070Spatrick   EmitSameDebugInfoAsHost, /// Use the same debug info level just like for the
335e5dd7070Spatrick                            /// host.
336e5dd7070Spatrick };
337e5dd7070Spatrick } // anonymous namespace
338e5dd7070Spatrick 
339e5dd7070Spatrick /// Define debug info level for the NVPTX devices. If the debug info for both
340e5dd7070Spatrick /// the host and device are disabled (-g0/-ggdb0 or no debug options at all). If
341e5dd7070Spatrick /// only debug directives are requested for the both host and device
342e5dd7070Spatrick /// (-gline-directvies-only), or the debug info only for the device is disabled
343e5dd7070Spatrick /// (optimization is on and --cuda-noopt-device-debug was not specified), the
344e5dd7070Spatrick /// debug directves only must be emitted for the device. Otherwise, use the same
345e5dd7070Spatrick /// debug info level just like for the host (with the limitations of only
346e5dd7070Spatrick /// supported DWARF2 standard).
mustEmitDebugInfo(const ArgList & Args)347e5dd7070Spatrick static DeviceDebugInfoLevel mustEmitDebugInfo(const ArgList &Args) {
348e5dd7070Spatrick   const Arg *A = Args.getLastArg(options::OPT_O_Group);
349e5dd7070Spatrick   bool IsDebugEnabled = !A || A->getOption().matches(options::OPT_O0) ||
350e5dd7070Spatrick                         Args.hasFlag(options::OPT_cuda_noopt_device_debug,
351e5dd7070Spatrick                                      options::OPT_no_cuda_noopt_device_debug,
352e5dd7070Spatrick                                      /*Default=*/false);
353e5dd7070Spatrick   if (const Arg *A = Args.getLastArg(options::OPT_g_Group)) {
354e5dd7070Spatrick     const Option &Opt = A->getOption();
355e5dd7070Spatrick     if (Opt.matches(options::OPT_gN_Group)) {
356e5dd7070Spatrick       if (Opt.matches(options::OPT_g0) || Opt.matches(options::OPT_ggdb0))
357e5dd7070Spatrick         return DisableDebugInfo;
358e5dd7070Spatrick       if (Opt.matches(options::OPT_gline_directives_only))
359e5dd7070Spatrick         return DebugDirectivesOnly;
360e5dd7070Spatrick     }
361e5dd7070Spatrick     return IsDebugEnabled ? EmitSameDebugInfoAsHost : DebugDirectivesOnly;
362e5dd7070Spatrick   }
363a9ac8606Spatrick   return willEmitRemarks(Args) ? DebugDirectivesOnly : DisableDebugInfo;
364e5dd7070Spatrick }
365e5dd7070Spatrick 
ConstructJob(Compilation & C,const JobAction & JA,const InputInfo & Output,const InputInfoList & Inputs,const ArgList & Args,const char * LinkingOutput) const366e5dd7070Spatrick void NVPTX::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
367e5dd7070Spatrick                                     const InputInfo &Output,
368e5dd7070Spatrick                                     const InputInfoList &Inputs,
369e5dd7070Spatrick                                     const ArgList &Args,
370e5dd7070Spatrick                                     const char *LinkingOutput) const {
371e5dd7070Spatrick   const auto &TC =
372*12c85518Srobert       static_cast<const toolchains::NVPTXToolChain &>(getToolChain());
373e5dd7070Spatrick   assert(TC.getTriple().isNVPTX() && "Wrong platform");
374e5dd7070Spatrick 
375e5dd7070Spatrick   StringRef GPUArchName;
376*12c85518Srobert   // If this is a CUDA action we need to extract the device architecture
377*12c85518Srobert   // from the Job's associated architecture, otherwise use the -march=arch
378*12c85518Srobert   // option. This option may come from -Xopenmp-target flag or the default
379*12c85518Srobert   // value.
380*12c85518Srobert   if (JA.isDeviceOffloading(Action::OFK_Cuda)) {
381*12c85518Srobert     GPUArchName = JA.getOffloadingArch();
382*12c85518Srobert   } else {
383e5dd7070Spatrick     GPUArchName = Args.getLastArgValue(options::OPT_march_EQ);
384e5dd7070Spatrick     assert(!GPUArchName.empty() && "Must have an architecture passed in.");
385*12c85518Srobert   }
386e5dd7070Spatrick 
387e5dd7070Spatrick   // Obtain architecture from the action.
388e5dd7070Spatrick   CudaArch gpu_arch = StringToCudaArch(GPUArchName);
389e5dd7070Spatrick   assert(gpu_arch != CudaArch::UNKNOWN &&
390e5dd7070Spatrick          "Device action expected to have an architecture.");
391e5dd7070Spatrick 
392e5dd7070Spatrick   // Check that our installation's ptxas supports gpu_arch.
393e5dd7070Spatrick   if (!Args.hasArg(options::OPT_no_cuda_version_check)) {
394e5dd7070Spatrick     TC.CudaInstallation.CheckCudaVersionSupportsArch(gpu_arch);
395e5dd7070Spatrick   }
396e5dd7070Spatrick 
397e5dd7070Spatrick   ArgStringList CmdArgs;
398e5dd7070Spatrick   CmdArgs.push_back(TC.getTriple().isArch64Bit() ? "-m64" : "-m32");
399e5dd7070Spatrick   DeviceDebugInfoLevel DIKind = mustEmitDebugInfo(Args);
400e5dd7070Spatrick   if (DIKind == EmitSameDebugInfoAsHost) {
401e5dd7070Spatrick     // ptxas does not accept -g option if optimization is enabled, so
402e5dd7070Spatrick     // we ignore the compiler's -O* options if we want debug info.
403e5dd7070Spatrick     CmdArgs.push_back("-g");
404e5dd7070Spatrick     CmdArgs.push_back("--dont-merge-basicblocks");
405e5dd7070Spatrick     CmdArgs.push_back("--return-at-end");
406e5dd7070Spatrick   } else if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
407e5dd7070Spatrick     // Map the -O we received to -O{0,1,2,3}.
408e5dd7070Spatrick     //
409e5dd7070Spatrick     // TODO: Perhaps we should map host -O2 to ptxas -O3. -O3 is ptxas's
410e5dd7070Spatrick     // default, so it may correspond more closely to the spirit of clang -O2.
411e5dd7070Spatrick 
412e5dd7070Spatrick     // -O3 seems like the least-bad option when -Osomething is specified to
413e5dd7070Spatrick     // clang but it isn't handled below.
414e5dd7070Spatrick     StringRef OOpt = "3";
415e5dd7070Spatrick     if (A->getOption().matches(options::OPT_O4) ||
416e5dd7070Spatrick         A->getOption().matches(options::OPT_Ofast))
417e5dd7070Spatrick       OOpt = "3";
418e5dd7070Spatrick     else if (A->getOption().matches(options::OPT_O0))
419e5dd7070Spatrick       OOpt = "0";
420e5dd7070Spatrick     else if (A->getOption().matches(options::OPT_O)) {
421e5dd7070Spatrick       // -Os, -Oz, and -O(anything else) map to -O2, for lack of better options.
422e5dd7070Spatrick       OOpt = llvm::StringSwitch<const char *>(A->getValue())
423e5dd7070Spatrick                  .Case("1", "1")
424e5dd7070Spatrick                  .Case("2", "2")
425e5dd7070Spatrick                  .Case("3", "3")
426e5dd7070Spatrick                  .Case("s", "2")
427e5dd7070Spatrick                  .Case("z", "2")
428e5dd7070Spatrick                  .Default("2");
429e5dd7070Spatrick     }
430e5dd7070Spatrick     CmdArgs.push_back(Args.MakeArgString(llvm::Twine("-O") + OOpt));
431e5dd7070Spatrick   } else {
432e5dd7070Spatrick     // If no -O was passed, pass -O0 to ptxas -- no opt flag should correspond
433e5dd7070Spatrick     // to no optimizations, but ptxas's default is -O3.
434e5dd7070Spatrick     CmdArgs.push_back("-O0");
435e5dd7070Spatrick   }
436e5dd7070Spatrick   if (DIKind == DebugDirectivesOnly)
437e5dd7070Spatrick     CmdArgs.push_back("-lineinfo");
438e5dd7070Spatrick 
439e5dd7070Spatrick   // Pass -v to ptxas if it was passed to the driver.
440e5dd7070Spatrick   if (Args.hasArg(options::OPT_v))
441e5dd7070Spatrick     CmdArgs.push_back("-v");
442e5dd7070Spatrick 
443e5dd7070Spatrick   CmdArgs.push_back("--gpu-name");
444e5dd7070Spatrick   CmdArgs.push_back(Args.MakeArgString(CudaArchToString(gpu_arch)));
445e5dd7070Spatrick   CmdArgs.push_back("--output-file");
446*12c85518Srobert   std::string OutputFileName = TC.getInputFilename(Output);
447*12c85518Srobert 
448*12c85518Srobert   // If we are invoking `nvlink` internally we need to output a `.cubin` file.
449*12c85518Srobert   // FIXME: This should hopefully be removed if NVIDIA updates their tooling.
450*12c85518Srobert   if (!C.getInputArgs().getLastArg(options::OPT_c)) {
451*12c85518Srobert     SmallString<256> Filename(Output.getFilename());
452*12c85518Srobert     llvm::sys::path::replace_extension(Filename, "cubin");
453*12c85518Srobert     OutputFileName = Filename.str();
454*12c85518Srobert   }
455*12c85518Srobert   if (Output.isFilename() && OutputFileName != Output.getFilename())
456*12c85518Srobert     C.addTempFile(Args.MakeArgString(OutputFileName));
457*12c85518Srobert 
458*12c85518Srobert   CmdArgs.push_back(Args.MakeArgString(OutputFileName));
459e5dd7070Spatrick   for (const auto &II : Inputs)
460e5dd7070Spatrick     CmdArgs.push_back(Args.MakeArgString(II.getFilename()));
461e5dd7070Spatrick 
462e5dd7070Spatrick   for (const auto &A : Args.getAllArgValues(options::OPT_Xcuda_ptxas))
463e5dd7070Spatrick     CmdArgs.push_back(Args.MakeArgString(A));
464e5dd7070Spatrick 
465*12c85518Srobert   bool Relocatable;
466e5dd7070Spatrick   if (JA.isOffloading(Action::OFK_OpenMP))
467e5dd7070Spatrick     // In OpenMP we need to generate relocatable code.
468e5dd7070Spatrick     Relocatable = Args.hasFlag(options::OPT_fopenmp_relocatable_target,
469e5dd7070Spatrick                                options::OPT_fnoopenmp_relocatable_target,
470e5dd7070Spatrick                                /*Default=*/true);
471e5dd7070Spatrick   else if (JA.isOffloading(Action::OFK_Cuda))
472*12c85518Srobert     // In CUDA we generate relocatable code by default.
473*12c85518Srobert     Relocatable = Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
474*12c85518Srobert                                /*Default=*/false);
475*12c85518Srobert   else
476*12c85518Srobert     // Otherwise, we are compiling directly and should create linkable output.
477*12c85518Srobert     Relocatable = true;
478e5dd7070Spatrick 
479e5dd7070Spatrick   if (Relocatable)
480e5dd7070Spatrick     CmdArgs.push_back("-c");
481e5dd7070Spatrick 
482e5dd7070Spatrick   const char *Exec;
483e5dd7070Spatrick   if (Arg *A = Args.getLastArg(options::OPT_ptxas_path_EQ))
484e5dd7070Spatrick     Exec = A->getValue();
485e5dd7070Spatrick   else
486e5dd7070Spatrick     Exec = Args.MakeArgString(TC.GetProgramPath("ptxas"));
487ec727ea7Spatrick   C.addCommand(std::make_unique<Command>(
488ec727ea7Spatrick       JA, *this,
489ec727ea7Spatrick       ResponseFileSupport{ResponseFileSupport::RF_Full, llvm::sys::WEM_UTF8,
490ec727ea7Spatrick                           "--options-file"},
491a9ac8606Spatrick       Exec, CmdArgs, Inputs, Output));
492e5dd7070Spatrick }
493e5dd7070Spatrick 
shouldIncludePTX(const ArgList & Args,const char * gpu_arch)494e5dd7070Spatrick static bool shouldIncludePTX(const ArgList &Args, const char *gpu_arch) {
495e5dd7070Spatrick   bool includePTX = true;
496e5dd7070Spatrick   for (Arg *A : Args) {
497e5dd7070Spatrick     if (!(A->getOption().matches(options::OPT_cuda_include_ptx_EQ) ||
498e5dd7070Spatrick           A->getOption().matches(options::OPT_no_cuda_include_ptx_EQ)))
499e5dd7070Spatrick       continue;
500e5dd7070Spatrick     A->claim();
501e5dd7070Spatrick     const StringRef ArchStr = A->getValue();
502e5dd7070Spatrick     if (ArchStr == "all" || ArchStr == gpu_arch) {
503e5dd7070Spatrick       includePTX = A->getOption().matches(options::OPT_cuda_include_ptx_EQ);
504e5dd7070Spatrick       continue;
505e5dd7070Spatrick     }
506e5dd7070Spatrick   }
507e5dd7070Spatrick   return includePTX;
508e5dd7070Spatrick }
509e5dd7070Spatrick 
510e5dd7070Spatrick // All inputs to this linker must be from CudaDeviceActions, as we need to look
511e5dd7070Spatrick // at the Inputs' Actions in order to figure out which GPU architecture they
512e5dd7070Spatrick // correspond to.
ConstructJob(Compilation & C,const JobAction & JA,const InputInfo & Output,const InputInfoList & Inputs,const ArgList & Args,const char * LinkingOutput) const513*12c85518Srobert void NVPTX::FatBinary::ConstructJob(Compilation &C, const JobAction &JA,
514e5dd7070Spatrick                                     const InputInfo &Output,
515e5dd7070Spatrick                                     const InputInfoList &Inputs,
516e5dd7070Spatrick                                     const ArgList &Args,
517e5dd7070Spatrick                                     const char *LinkingOutput) const {
518e5dd7070Spatrick   const auto &TC =
519e5dd7070Spatrick       static_cast<const toolchains::CudaToolChain &>(getToolChain());
520e5dd7070Spatrick   assert(TC.getTriple().isNVPTX() && "Wrong platform");
521e5dd7070Spatrick 
522e5dd7070Spatrick   ArgStringList CmdArgs;
523e5dd7070Spatrick   if (TC.CudaInstallation.version() <= CudaVersion::CUDA_100)
524e5dd7070Spatrick     CmdArgs.push_back("--cuda");
525e5dd7070Spatrick   CmdArgs.push_back(TC.getTriple().isArch64Bit() ? "-64" : "-32");
526e5dd7070Spatrick   CmdArgs.push_back(Args.MakeArgString("--create"));
527e5dd7070Spatrick   CmdArgs.push_back(Args.MakeArgString(Output.getFilename()));
528e5dd7070Spatrick   if (mustEmitDebugInfo(Args) == EmitSameDebugInfoAsHost)
529e5dd7070Spatrick     CmdArgs.push_back("-g");
530e5dd7070Spatrick 
531e5dd7070Spatrick   for (const auto &II : Inputs) {
532e5dd7070Spatrick     auto *A = II.getAction();
533e5dd7070Spatrick     assert(A->getInputs().size() == 1 &&
534e5dd7070Spatrick            "Device offload action is expected to have a single input");
535e5dd7070Spatrick     const char *gpu_arch_str = A->getOffloadingArch();
536e5dd7070Spatrick     assert(gpu_arch_str &&
537e5dd7070Spatrick            "Device action expected to have associated a GPU architecture!");
538e5dd7070Spatrick     CudaArch gpu_arch = StringToCudaArch(gpu_arch_str);
539e5dd7070Spatrick 
540e5dd7070Spatrick     if (II.getType() == types::TY_PP_Asm &&
541e5dd7070Spatrick         !shouldIncludePTX(Args, gpu_arch_str))
542e5dd7070Spatrick       continue;
543e5dd7070Spatrick     // We need to pass an Arch of the form "sm_XX" for cubin files and
544e5dd7070Spatrick     // "compute_XX" for ptx.
545ec727ea7Spatrick     const char *Arch = (II.getType() == types::TY_PP_Asm)
546ec727ea7Spatrick                            ? CudaArchToVirtualArchString(gpu_arch)
547e5dd7070Spatrick                            : gpu_arch_str;
548*12c85518Srobert     CmdArgs.push_back(
549*12c85518Srobert         Args.MakeArgString(llvm::Twine("--image=profile=") + Arch +
550*12c85518Srobert                            ",file=" + getToolChain().getInputFilename(II)));
551e5dd7070Spatrick   }
552e5dd7070Spatrick 
553e5dd7070Spatrick   for (const auto &A : Args.getAllArgValues(options::OPT_Xcuda_fatbinary))
554e5dd7070Spatrick     CmdArgs.push_back(Args.MakeArgString(A));
555e5dd7070Spatrick 
556e5dd7070Spatrick   const char *Exec = Args.MakeArgString(TC.GetProgramPath("fatbinary"));
557ec727ea7Spatrick   C.addCommand(std::make_unique<Command>(
558ec727ea7Spatrick       JA, *this,
559ec727ea7Spatrick       ResponseFileSupport{ResponseFileSupport::RF_Full, llvm::sys::WEM_UTF8,
560ec727ea7Spatrick                           "--options-file"},
561a9ac8606Spatrick       Exec, CmdArgs, Inputs, Output));
562e5dd7070Spatrick }
563e5dd7070Spatrick 
ConstructJob(Compilation & C,const JobAction & JA,const InputInfo & Output,const InputInfoList & Inputs,const ArgList & Args,const char * LinkingOutput) const564*12c85518Srobert void NVPTX::Linker::ConstructJob(Compilation &C, const JobAction &JA,
565e5dd7070Spatrick                                  const InputInfo &Output,
566e5dd7070Spatrick                                  const InputInfoList &Inputs,
567e5dd7070Spatrick                                  const ArgList &Args,
568e5dd7070Spatrick                                  const char *LinkingOutput) const {
569e5dd7070Spatrick   const auto &TC =
570*12c85518Srobert       static_cast<const toolchains::NVPTXToolChain &>(getToolChain());
571e5dd7070Spatrick   assert(TC.getTriple().isNVPTX() && "Wrong platform");
572e5dd7070Spatrick 
573e5dd7070Spatrick   ArgStringList CmdArgs;
574e5dd7070Spatrick   if (Output.isFilename()) {
575e5dd7070Spatrick     CmdArgs.push_back("-o");
576e5dd7070Spatrick     CmdArgs.push_back(Output.getFilename());
577*12c85518Srobert   } else {
578e5dd7070Spatrick     assert(Output.isNothing() && "Invalid output.");
579*12c85518Srobert   }
580*12c85518Srobert 
581e5dd7070Spatrick   if (mustEmitDebugInfo(Args) == EmitSameDebugInfoAsHost)
582e5dd7070Spatrick     CmdArgs.push_back("-g");
583e5dd7070Spatrick 
584e5dd7070Spatrick   if (Args.hasArg(options::OPT_v))
585e5dd7070Spatrick     CmdArgs.push_back("-v");
586e5dd7070Spatrick 
587*12c85518Srobert   StringRef GPUArch = Args.getLastArgValue(options::OPT_march_EQ);
588*12c85518Srobert   assert(!GPUArch.empty() && "At least one GPU Arch required for nvlink.");
589e5dd7070Spatrick 
590e5dd7070Spatrick   CmdArgs.push_back("-arch");
591e5dd7070Spatrick   CmdArgs.push_back(Args.MakeArgString(GPUArch));
592e5dd7070Spatrick 
593e5dd7070Spatrick   // Add paths specified in LIBRARY_PATH environment variable as -L options.
594e5dd7070Spatrick   addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH");
595e5dd7070Spatrick 
596e5dd7070Spatrick   // Add paths for the default clang library path.
597e5dd7070Spatrick   SmallString<256> DefaultLibPath =
598e5dd7070Spatrick       llvm::sys::path::parent_path(TC.getDriver().Dir);
599*12c85518Srobert   llvm::sys::path::append(DefaultLibPath, CLANG_INSTALL_LIBDIR_BASENAME);
600e5dd7070Spatrick   CmdArgs.push_back(Args.MakeArgString(Twine("-L") + DefaultLibPath));
601e5dd7070Spatrick 
602e5dd7070Spatrick   for (const auto &II : Inputs) {
603*12c85518Srobert     if (II.getType() == types::TY_LLVM_IR || II.getType() == types::TY_LTO_IR ||
604*12c85518Srobert         II.getType() == types::TY_LTO_BC || II.getType() == types::TY_LLVM_BC) {
605e5dd7070Spatrick       C.getDriver().Diag(diag::err_drv_no_linker_llvm_support)
606e5dd7070Spatrick           << getToolChain().getTripleString();
607e5dd7070Spatrick       continue;
608e5dd7070Spatrick     }
609e5dd7070Spatrick 
610e5dd7070Spatrick     // Currently, we only pass the input files to the linker, we do not pass
611e5dd7070Spatrick     // any libraries that may be valid only for the host.
612e5dd7070Spatrick     if (!II.isFilename())
613e5dd7070Spatrick       continue;
614e5dd7070Spatrick 
615*12c85518Srobert     // The 'nvlink' application performs RDC-mode linking when given a '.o'
616*12c85518Srobert     // file and device linking when given a '.cubin' file. We always want to
617*12c85518Srobert     // perform device linking, so just rename any '.o' files.
618*12c85518Srobert     // FIXME: This should hopefully be removed if NVIDIA updates their tooling.
619*12c85518Srobert     auto InputFile = getToolChain().getInputFilename(II);
620*12c85518Srobert     if (llvm::sys::path::extension(InputFile) != ".cubin") {
621*12c85518Srobert       // If there are no actions above this one then this is direct input and we
622*12c85518Srobert       // can copy it. Otherwise the input is internal so a `.cubin` file should
623*12c85518Srobert       // exist.
624*12c85518Srobert       if (II.getAction() && II.getAction()->getInputs().size() == 0) {
625*12c85518Srobert         const char *CubinF =
626*12c85518Srobert             Args.MakeArgString(getToolChain().getDriver().GetTemporaryPath(
627*12c85518Srobert                 llvm::sys::path::stem(InputFile), "cubin"));
628*12c85518Srobert         if (std::error_code EC =
629*12c85518Srobert                 llvm::sys::fs::copy_file(InputFile, C.addTempFile(CubinF)))
630*12c85518Srobert           continue;
631e5dd7070Spatrick 
632e5dd7070Spatrick         CmdArgs.push_back(CubinF);
633*12c85518Srobert       } else {
634*12c85518Srobert         SmallString<256> Filename(InputFile);
635*12c85518Srobert         llvm::sys::path::replace_extension(Filename, "cubin");
636*12c85518Srobert         CmdArgs.push_back(Args.MakeArgString(Filename));
637*12c85518Srobert       }
638*12c85518Srobert     } else {
639*12c85518Srobert       CmdArgs.push_back(Args.MakeArgString(InputFile));
640*12c85518Srobert     }
641e5dd7070Spatrick   }
642e5dd7070Spatrick 
643ec727ea7Spatrick   C.addCommand(std::make_unique<Command>(
644ec727ea7Spatrick       JA, *this,
645ec727ea7Spatrick       ResponseFileSupport{ResponseFileSupport::RF_Full, llvm::sys::WEM_UTF8,
646ec727ea7Spatrick                           "--options-file"},
647*12c85518Srobert       Args.MakeArgString(getToolChain().GetProgramPath("nvlink")), CmdArgs,
648*12c85518Srobert       Inputs, Output));
649e5dd7070Spatrick }
650e5dd7070Spatrick 
getNVPTXTargetFeatures(const Driver & D,const llvm::Triple & Triple,const llvm::opt::ArgList & Args,std::vector<StringRef> & Features)651*12c85518Srobert void NVPTX::getNVPTXTargetFeatures(const Driver &D, const llvm::Triple &Triple,
652*12c85518Srobert                                    const llvm::opt::ArgList &Args,
653*12c85518Srobert                                    std::vector<StringRef> &Features) {
654*12c85518Srobert   if (Args.hasArg(options::OPT_cuda_feature_EQ)) {
655*12c85518Srobert     StringRef PtxFeature =
656*12c85518Srobert         Args.getLastArgValue(options::OPT_cuda_feature_EQ, "+ptx42");
657*12c85518Srobert     Features.push_back(Args.MakeArgString(PtxFeature));
658*12c85518Srobert     return;
659*12c85518Srobert   }
660*12c85518Srobert   CudaInstallationDetector CudaInstallation(D, Triple, Args);
661e5dd7070Spatrick 
662*12c85518Srobert   // New CUDA versions often introduce new instructions that are only supported
663*12c85518Srobert   // by new PTX version, so we need to raise PTX level to enable them in NVPTX
664*12c85518Srobert   // back-end.
665*12c85518Srobert   const char *PtxFeature = nullptr;
666*12c85518Srobert   switch (CudaInstallation.version()) {
667*12c85518Srobert #define CASE_CUDA_VERSION(CUDA_VER, PTX_VER)                                   \
668*12c85518Srobert   case CudaVersion::CUDA_##CUDA_VER:                                           \
669*12c85518Srobert     PtxFeature = "+ptx" #PTX_VER;                                              \
670*12c85518Srobert     break;
671*12c85518Srobert     CASE_CUDA_VERSION(118, 78);
672*12c85518Srobert     CASE_CUDA_VERSION(117, 77);
673*12c85518Srobert     CASE_CUDA_VERSION(116, 76);
674*12c85518Srobert     CASE_CUDA_VERSION(115, 75);
675*12c85518Srobert     CASE_CUDA_VERSION(114, 74);
676*12c85518Srobert     CASE_CUDA_VERSION(113, 73);
677*12c85518Srobert     CASE_CUDA_VERSION(112, 72);
678*12c85518Srobert     CASE_CUDA_VERSION(111, 71);
679*12c85518Srobert     CASE_CUDA_VERSION(110, 70);
680*12c85518Srobert     CASE_CUDA_VERSION(102, 65);
681*12c85518Srobert     CASE_CUDA_VERSION(101, 64);
682*12c85518Srobert     CASE_CUDA_VERSION(100, 63);
683*12c85518Srobert     CASE_CUDA_VERSION(92, 61);
684*12c85518Srobert     CASE_CUDA_VERSION(91, 61);
685*12c85518Srobert     CASE_CUDA_VERSION(90, 60);
686*12c85518Srobert #undef CASE_CUDA_VERSION
687*12c85518Srobert   default:
688*12c85518Srobert     PtxFeature = "+ptx42";
689*12c85518Srobert   }
690*12c85518Srobert   Features.push_back(PtxFeature);
691*12c85518Srobert }
692*12c85518Srobert 
693*12c85518Srobert /// NVPTX toolchain. Our assembler is ptxas, and our linker is nvlink. This
694*12c85518Srobert /// operates as a stand-alone version of the NVPTX tools without the host
695*12c85518Srobert /// toolchain.
NVPTXToolChain(const Driver & D,const llvm::Triple & Triple,const llvm::Triple & HostTriple,const ArgList & Args)696*12c85518Srobert NVPTXToolChain::NVPTXToolChain(const Driver &D, const llvm::Triple &Triple,
697*12c85518Srobert                                const llvm::Triple &HostTriple,
698*12c85518Srobert                                const ArgList &Args)
699*12c85518Srobert     : ToolChain(D, Triple, Args), CudaInstallation(D, HostTriple, Args) {
700e5dd7070Spatrick   if (CudaInstallation.isValid()) {
701e5dd7070Spatrick     CudaInstallation.WarnIfUnsupportedVersion();
702ec727ea7Spatrick     getProgramPaths().push_back(std::string(CudaInstallation.getBinPath()));
703e5dd7070Spatrick   }
704e5dd7070Spatrick   // Lookup binaries into the driver directory, this is used to
705e5dd7070Spatrick   // discover the clang-offload-bundler executable.
706e5dd7070Spatrick   getProgramPaths().push_back(getDriver().Dir);
707e5dd7070Spatrick }
708e5dd7070Spatrick 
709*12c85518Srobert /// We only need the host triple to locate the CUDA binary utilities, use the
710*12c85518Srobert /// system's default triple if not provided.
NVPTXToolChain(const Driver & D,const llvm::Triple & Triple,const ArgList & Args)711*12c85518Srobert NVPTXToolChain::NVPTXToolChain(const Driver &D, const llvm::Triple &Triple,
712*12c85518Srobert                                const ArgList &Args)
713*12c85518Srobert     : NVPTXToolChain(D, Triple,
714*12c85518Srobert                      llvm::Triple(llvm::sys::getDefaultTargetTriple()), Args) {}
715e5dd7070Spatrick 
716*12c85518Srobert llvm::opt::DerivedArgList *
TranslateArgs(const llvm::opt::DerivedArgList & Args,StringRef BoundArch,Action::OffloadKind DeviceOffloadKind) const717*12c85518Srobert NVPTXToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
718*12c85518Srobert                               StringRef BoundArch,
719*12c85518Srobert                               Action::OffloadKind DeviceOffloadKind) const {
720*12c85518Srobert   DerivedArgList *DAL =
721*12c85518Srobert       ToolChain::TranslateArgs(Args, BoundArch, DeviceOffloadKind);
722*12c85518Srobert   if (!DAL)
723*12c85518Srobert     DAL = new DerivedArgList(Args.getBaseArgs());
724*12c85518Srobert 
725*12c85518Srobert   const OptTable &Opts = getDriver().getOpts();
726*12c85518Srobert 
727*12c85518Srobert   for (Arg *A : Args)
728*12c85518Srobert     if (!llvm::is_contained(*DAL, A))
729*12c85518Srobert       DAL->append(A);
730*12c85518Srobert 
731*12c85518Srobert   if (!DAL->hasArg(options::OPT_march_EQ))
732*12c85518Srobert     DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
733*12c85518Srobert                       CudaArchToString(CudaArch::CudaDefault));
734*12c85518Srobert 
735*12c85518Srobert   return DAL;
736e5dd7070Spatrick }
737e5dd7070Spatrick 
supportsDebugInfoOption(const llvm::opt::Arg * A) const738*12c85518Srobert bool NVPTXToolChain::supportsDebugInfoOption(const llvm::opt::Arg *A) const {
739*12c85518Srobert   const Option &O = A->getOption();
740*12c85518Srobert   return (O.matches(options::OPT_gN_Group) &&
741*12c85518Srobert           !O.matches(options::OPT_gmodules)) ||
742*12c85518Srobert          O.matches(options::OPT_g_Flag) ||
743*12c85518Srobert          O.matches(options::OPT_ggdbN_Group) || O.matches(options::OPT_ggdb) ||
744*12c85518Srobert          O.matches(options::OPT_gdwarf) || O.matches(options::OPT_gdwarf_2) ||
745*12c85518Srobert          O.matches(options::OPT_gdwarf_3) || O.matches(options::OPT_gdwarf_4) ||
746*12c85518Srobert          O.matches(options::OPT_gdwarf_5) ||
747*12c85518Srobert          O.matches(options::OPT_gcolumn_info);
748*12c85518Srobert }
749*12c85518Srobert 
adjustDebugInfoKind(codegenoptions::DebugInfoKind & DebugInfoKind,const ArgList & Args) const750*12c85518Srobert void NVPTXToolChain::adjustDebugInfoKind(
751*12c85518Srobert     codegenoptions::DebugInfoKind &DebugInfoKind, const ArgList &Args) const {
752*12c85518Srobert   switch (mustEmitDebugInfo(Args)) {
753*12c85518Srobert   case DisableDebugInfo:
754*12c85518Srobert     DebugInfoKind = codegenoptions::NoDebugInfo;
755*12c85518Srobert     break;
756*12c85518Srobert   case DebugDirectivesOnly:
757*12c85518Srobert     DebugInfoKind = codegenoptions::DebugDirectivesOnly;
758*12c85518Srobert     break;
759*12c85518Srobert   case EmitSameDebugInfoAsHost:
760*12c85518Srobert     // Use same debug info level as the host.
761*12c85518Srobert     break;
762*12c85518Srobert   }
763*12c85518Srobert }
764*12c85518Srobert 
765*12c85518Srobert /// CUDA toolchain.  Our assembler is ptxas, and our "linker" is fatbinary,
766*12c85518Srobert /// which isn't properly a linker but nonetheless performs the step of stitching
767*12c85518Srobert /// together object files from the assembler into a single blob.
768*12c85518Srobert 
CudaToolChain(const Driver & D,const llvm::Triple & Triple,const ToolChain & HostTC,const ArgList & Args)769*12c85518Srobert CudaToolChain::CudaToolChain(const Driver &D, const llvm::Triple &Triple,
770*12c85518Srobert                              const ToolChain &HostTC, const ArgList &Args)
771*12c85518Srobert     : NVPTXToolChain(D, Triple, HostTC.getTriple(), Args), HostTC(HostTC) {}
772*12c85518Srobert 
addClangTargetOptions(const llvm::opt::ArgList & DriverArgs,llvm::opt::ArgStringList & CC1Args,Action::OffloadKind DeviceOffloadingKind) const773e5dd7070Spatrick void CudaToolChain::addClangTargetOptions(
774*12c85518Srobert     const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
775e5dd7070Spatrick     Action::OffloadKind DeviceOffloadingKind) const {
776e5dd7070Spatrick   HostTC.addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadingKind);
777e5dd7070Spatrick 
778e5dd7070Spatrick   StringRef GpuArch = DriverArgs.getLastArgValue(options::OPT_march_EQ);
779e5dd7070Spatrick   assert(!GpuArch.empty() && "Must have an explicit GPU arch.");
780e5dd7070Spatrick   assert((DeviceOffloadingKind == Action::OFK_OpenMP ||
781e5dd7070Spatrick           DeviceOffloadingKind == Action::OFK_Cuda) &&
782e5dd7070Spatrick          "Only OpenMP or CUDA offloading kinds are supported for NVIDIA GPUs.");
783e5dd7070Spatrick 
784e5dd7070Spatrick   if (DeviceOffloadingKind == Action::OFK_Cuda) {
785*12c85518Srobert     CC1Args.append(
786*12c85518Srobert         {"-fcuda-is-device", "-mllvm", "-enable-memcpyopt-without-libcalls"});
787e5dd7070Spatrick 
788e5dd7070Spatrick     if (DriverArgs.hasFlag(options::OPT_fcuda_approx_transcendentals,
789e5dd7070Spatrick                            options::OPT_fno_cuda_approx_transcendentals, false))
790e5dd7070Spatrick       CC1Args.push_back("-fcuda-approx-transcendentals");
791e5dd7070Spatrick   }
792e5dd7070Spatrick 
793e5dd7070Spatrick   if (DriverArgs.hasArg(options::OPT_nogpulib))
794e5dd7070Spatrick     return;
795e5dd7070Spatrick 
796e5dd7070Spatrick   if (DeviceOffloadingKind == Action::OFK_OpenMP &&
797e5dd7070Spatrick       DriverArgs.hasArg(options::OPT_S))
798e5dd7070Spatrick     return;
799e5dd7070Spatrick 
800a9ac8606Spatrick   std::string LibDeviceFile = CudaInstallation.getLibDeviceFile(GpuArch);
801a9ac8606Spatrick   if (LibDeviceFile.empty()) {
802e5dd7070Spatrick     getDriver().Diag(diag::err_drv_no_cuda_libdevice) << GpuArch;
803e5dd7070Spatrick     return;
804e5dd7070Spatrick   }
805e5dd7070Spatrick 
806e5dd7070Spatrick   CC1Args.push_back("-mlink-builtin-bitcode");
807e5dd7070Spatrick   CC1Args.push_back(DriverArgs.MakeArgString(LibDeviceFile));
808e5dd7070Spatrick 
809a9ac8606Spatrick   clang::CudaVersion CudaInstallationVersion = CudaInstallation.version();
810a9ac8606Spatrick 
811e5dd7070Spatrick   if (DriverArgs.hasFlag(options::OPT_fcuda_short_ptr,
812e5dd7070Spatrick                          options::OPT_fno_cuda_short_ptr, false))
813e5dd7070Spatrick     CC1Args.append({"-mllvm", "--nvptx-short-ptr"});
814e5dd7070Spatrick 
815a9ac8606Spatrick   if (CudaInstallationVersion >= CudaVersion::UNKNOWN)
816a9ac8606Spatrick     CC1Args.push_back(
817a9ac8606Spatrick         DriverArgs.MakeArgString(Twine("-target-sdk-version=") +
818a9ac8606Spatrick                                  CudaVersionToString(CudaInstallationVersion)));
819e5dd7070Spatrick 
820e5dd7070Spatrick   if (DeviceOffloadingKind == Action::OFK_OpenMP) {
821a9ac8606Spatrick     if (CudaInstallationVersion < CudaVersion::CUDA_92) {
822a9ac8606Spatrick       getDriver().Diag(
823a9ac8606Spatrick           diag::err_drv_omp_offload_target_cuda_version_not_support)
824a9ac8606Spatrick           << CudaVersionToString(CudaInstallationVersion);
825a9ac8606Spatrick       return;
826e5dd7070Spatrick     }
827e5dd7070Spatrick 
828*12c85518Srobert     // Link the bitcode library late if we're using device LTO.
829*12c85518Srobert     if (getDriver().isUsingLTO(/* IsOffload */ true))
830*12c85518Srobert       return;
831e5dd7070Spatrick 
832*12c85518Srobert     addOpenMPDeviceRTL(getDriver(), DriverArgs, CC1Args, GpuArch.str(),
833a9ac8606Spatrick                        getTriple());
834e5dd7070Spatrick   }
835e5dd7070Spatrick }
836e5dd7070Spatrick 
getDefaultDenormalModeForType(const llvm::opt::ArgList & DriverArgs,const JobAction & JA,const llvm::fltSemantics * FPType) const837ec727ea7Spatrick llvm::DenormalMode CudaToolChain::getDefaultDenormalModeForType(
838ec727ea7Spatrick     const llvm::opt::ArgList &DriverArgs, const JobAction &JA,
839ec727ea7Spatrick     const llvm::fltSemantics *FPType) const {
840ec727ea7Spatrick   if (JA.getOffloadingDeviceKind() == Action::OFK_Cuda) {
841ec727ea7Spatrick     if (FPType && FPType == &llvm::APFloat::IEEEsingle() &&
842a9ac8606Spatrick         DriverArgs.hasFlag(options::OPT_fgpu_flush_denormals_to_zero,
843a9ac8606Spatrick                            options::OPT_fno_gpu_flush_denormals_to_zero, false))
844ec727ea7Spatrick       return llvm::DenormalMode::getPreserveSign();
845ec727ea7Spatrick   }
846ec727ea7Spatrick 
847ec727ea7Spatrick   assert(JA.getOffloadingDeviceKind() != Action::OFK_Host);
848ec727ea7Spatrick   return llvm::DenormalMode::getIEEE();
849ec727ea7Spatrick }
850ec727ea7Spatrick 
AddCudaIncludeArgs(const ArgList & DriverArgs,ArgStringList & CC1Args) const851e5dd7070Spatrick void CudaToolChain::AddCudaIncludeArgs(const ArgList &DriverArgs,
852e5dd7070Spatrick                                        ArgStringList &CC1Args) const {
853e5dd7070Spatrick   // Check our CUDA version if we're going to include the CUDA headers.
854ec727ea7Spatrick   if (!DriverArgs.hasArg(options::OPT_nogpuinc) &&
855e5dd7070Spatrick       !DriverArgs.hasArg(options::OPT_no_cuda_version_check)) {
856e5dd7070Spatrick     StringRef Arch = DriverArgs.getLastArgValue(options::OPT_march_EQ);
857e5dd7070Spatrick     assert(!Arch.empty() && "Must have an explicit GPU arch.");
858e5dd7070Spatrick     CudaInstallation.CheckCudaVersionSupportsArch(StringToCudaArch(Arch));
859e5dd7070Spatrick   }
860e5dd7070Spatrick   CudaInstallation.AddCudaIncludeArgs(DriverArgs, CC1Args);
861e5dd7070Spatrick }
862e5dd7070Spatrick 
getInputFilename(const InputInfo & Input) const863*12c85518Srobert std::string CudaToolChain::getInputFilename(const InputInfo &Input) const {
864*12c85518Srobert   // Only object files are changed, for example assembly files keep their .s
865*12c85518Srobert   // extensions. If the user requested device-only compilation don't change it.
866*12c85518Srobert   if (Input.getType() != types::TY_Object || getDriver().offloadDeviceOnly())
867*12c85518Srobert     return ToolChain::getInputFilename(Input);
868*12c85518Srobert 
869*12c85518Srobert   // Replace extension for object files with cubin because nvlink relies on
870*12c85518Srobert   // these particular file names.
871*12c85518Srobert   SmallString<256> Filename(ToolChain::getInputFilename(Input));
872*12c85518Srobert   llvm::sys::path::replace_extension(Filename, "cubin");
873*12c85518Srobert   return std::string(Filename.str());
874*12c85518Srobert }
875*12c85518Srobert 
876e5dd7070Spatrick llvm::opt::DerivedArgList *
TranslateArgs(const llvm::opt::DerivedArgList & Args,StringRef BoundArch,Action::OffloadKind DeviceOffloadKind) const877e5dd7070Spatrick CudaToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
878e5dd7070Spatrick                              StringRef BoundArch,
879e5dd7070Spatrick                              Action::OffloadKind DeviceOffloadKind) const {
880e5dd7070Spatrick   DerivedArgList *DAL =
881e5dd7070Spatrick       HostTC.TranslateArgs(Args, BoundArch, DeviceOffloadKind);
882e5dd7070Spatrick   if (!DAL)
883e5dd7070Spatrick     DAL = new DerivedArgList(Args.getBaseArgs());
884e5dd7070Spatrick 
885e5dd7070Spatrick   const OptTable &Opts = getDriver().getOpts();
886e5dd7070Spatrick 
887e5dd7070Spatrick   // For OpenMP device offloading, append derived arguments. Make sure
888e5dd7070Spatrick   // flags are not duplicated.
889e5dd7070Spatrick   // Also append the compute capability.
890e5dd7070Spatrick   if (DeviceOffloadKind == Action::OFK_OpenMP) {
891*12c85518Srobert     for (Arg *A : Args)
892*12c85518Srobert       if (!llvm::is_contained(*DAL, A))
893e5dd7070Spatrick         DAL->append(A);
894e5dd7070Spatrick 
895*12c85518Srobert     if (!DAL->hasArg(options::OPT_march_EQ)) {
896*12c85518Srobert       StringRef Arch = BoundArch;
897*12c85518Srobert       if (Arch.empty()) {
898*12c85518Srobert         auto ArchsOrErr = getSystemGPUArchs(Args);
899*12c85518Srobert         if (!ArchsOrErr) {
900*12c85518Srobert           std::string ErrMsg =
901*12c85518Srobert               llvm::formatv("{0}", llvm::fmt_consume(ArchsOrErr.takeError()));
902*12c85518Srobert           getDriver().Diag(diag::err_drv_undetermined_gpu_arch)
903*12c85518Srobert               << llvm::Triple::getArchTypeName(getArch()) << ErrMsg << "-march";
904*12c85518Srobert           Arch = CudaArchToString(CudaArch::CudaDefault);
905*12c85518Srobert         } else {
906*12c85518Srobert           Arch = Args.MakeArgString(ArchsOrErr->front());
907*12c85518Srobert         }
908*12c85518Srobert       }
909*12c85518Srobert       DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ), Arch);
910*12c85518Srobert     }
911e5dd7070Spatrick 
912e5dd7070Spatrick     return DAL;
913e5dd7070Spatrick   }
914e5dd7070Spatrick 
915e5dd7070Spatrick   for (Arg *A : Args) {
916e5dd7070Spatrick     DAL->append(A);
917e5dd7070Spatrick   }
918e5dd7070Spatrick 
919e5dd7070Spatrick   if (!BoundArch.empty()) {
920e5dd7070Spatrick     DAL->eraseArg(options::OPT_march_EQ);
921*12c85518Srobert     DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
922*12c85518Srobert                       BoundArch);
923e5dd7070Spatrick   }
924e5dd7070Spatrick   return DAL;
925e5dd7070Spatrick }
926e5dd7070Spatrick 
927*12c85518Srobert Expected<SmallVector<std::string>>
getSystemGPUArchs(const ArgList & Args) const928*12c85518Srobert CudaToolChain::getSystemGPUArchs(const ArgList &Args) const {
929*12c85518Srobert   // Detect NVIDIA GPUs availible on the system.
930*12c85518Srobert   std::string Program;
931*12c85518Srobert   if (Arg *A = Args.getLastArg(options::OPT_nvptx_arch_tool_EQ))
932*12c85518Srobert     Program = A->getValue();
933*12c85518Srobert   else
934*12c85518Srobert     Program = GetProgramPath("nvptx-arch");
935*12c85518Srobert 
936*12c85518Srobert   auto StdoutOrErr = executeToolChainProgram(Program);
937*12c85518Srobert   if (!StdoutOrErr)
938*12c85518Srobert     return StdoutOrErr.takeError();
939*12c85518Srobert 
940*12c85518Srobert   SmallVector<std::string, 1> GPUArchs;
941*12c85518Srobert   for (StringRef Arch : llvm::split((*StdoutOrErr)->getBuffer(), "\n"))
942*12c85518Srobert     if (!Arch.empty())
943*12c85518Srobert       GPUArchs.push_back(Arch.str());
944*12c85518Srobert 
945*12c85518Srobert   if (GPUArchs.empty())
946*12c85518Srobert     return llvm::createStringError(std::error_code(),
947*12c85518Srobert                                    "No NVIDIA GPU detected in the system");
948*12c85518Srobert 
949*12c85518Srobert   return std::move(GPUArchs);
950*12c85518Srobert }
951*12c85518Srobert 
buildAssembler() const952*12c85518Srobert Tool *NVPTXToolChain::buildAssembler() const {
953*12c85518Srobert   return new tools::NVPTX::Assembler(*this);
954*12c85518Srobert }
955*12c85518Srobert 
buildLinker() const956*12c85518Srobert Tool *NVPTXToolChain::buildLinker() const {
957*12c85518Srobert   return new tools::NVPTX::Linker(*this);
958*12c85518Srobert }
959*12c85518Srobert 
buildAssembler() const960e5dd7070Spatrick Tool *CudaToolChain::buildAssembler() const {
961e5dd7070Spatrick   return new tools::NVPTX::Assembler(*this);
962e5dd7070Spatrick }
963e5dd7070Spatrick 
buildLinker() const964e5dd7070Spatrick Tool *CudaToolChain::buildLinker() const {
965*12c85518Srobert   return new tools::NVPTX::FatBinary(*this);
966e5dd7070Spatrick }
967e5dd7070Spatrick 
addClangWarningOptions(ArgStringList & CC1Args) const968e5dd7070Spatrick void CudaToolChain::addClangWarningOptions(ArgStringList &CC1Args) const {
969e5dd7070Spatrick   HostTC.addClangWarningOptions(CC1Args);
970e5dd7070Spatrick }
971e5dd7070Spatrick 
972e5dd7070Spatrick ToolChain::CXXStdlibType
GetCXXStdlibType(const ArgList & Args) const973e5dd7070Spatrick CudaToolChain::GetCXXStdlibType(const ArgList &Args) const {
974e5dd7070Spatrick   return HostTC.GetCXXStdlibType(Args);
975e5dd7070Spatrick }
976e5dd7070Spatrick 
AddClangSystemIncludeArgs(const ArgList & DriverArgs,ArgStringList & CC1Args) const977e5dd7070Spatrick void CudaToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
978e5dd7070Spatrick                                               ArgStringList &CC1Args) const {
979e5dd7070Spatrick   HostTC.AddClangSystemIncludeArgs(DriverArgs, CC1Args);
980*12c85518Srobert 
981*12c85518Srobert   if (!DriverArgs.hasArg(options::OPT_nogpuinc) && CudaInstallation.isValid())
982*12c85518Srobert     CC1Args.append(
983*12c85518Srobert         {"-internal-isystem",
984*12c85518Srobert          DriverArgs.MakeArgString(CudaInstallation.getIncludePath())});
985e5dd7070Spatrick }
986e5dd7070Spatrick 
AddClangCXXStdlibIncludeArgs(const ArgList & Args,ArgStringList & CC1Args) const987e5dd7070Spatrick void CudaToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &Args,
988e5dd7070Spatrick                                                  ArgStringList &CC1Args) const {
989e5dd7070Spatrick   HostTC.AddClangCXXStdlibIncludeArgs(Args, CC1Args);
990e5dd7070Spatrick }
991e5dd7070Spatrick 
AddIAMCUIncludeArgs(const ArgList & Args,ArgStringList & CC1Args) const992e5dd7070Spatrick void CudaToolChain::AddIAMCUIncludeArgs(const ArgList &Args,
993e5dd7070Spatrick                                         ArgStringList &CC1Args) const {
994e5dd7070Spatrick   HostTC.AddIAMCUIncludeArgs(Args, CC1Args);
995e5dd7070Spatrick }
996e5dd7070Spatrick 
getSupportedSanitizers() const997e5dd7070Spatrick SanitizerMask CudaToolChain::getSupportedSanitizers() const {
998e5dd7070Spatrick   // The CudaToolChain only supports sanitizers in the sense that it allows
999e5dd7070Spatrick   // sanitizer arguments on the command line if they are supported by the host
1000e5dd7070Spatrick   // toolchain. The CudaToolChain will actually ignore any command line
1001e5dd7070Spatrick   // arguments for any of these "supported" sanitizers. That means that no
1002e5dd7070Spatrick   // sanitization of device code is actually supported at this time.
1003e5dd7070Spatrick   //
1004e5dd7070Spatrick   // This behavior is necessary because the host and device toolchains
1005e5dd7070Spatrick   // invocations often share the command line, so the device toolchain must
1006e5dd7070Spatrick   // tolerate flags meant only for the host toolchain.
1007e5dd7070Spatrick   return HostTC.getSupportedSanitizers();
1008e5dd7070Spatrick }
1009e5dd7070Spatrick 
computeMSVCVersion(const Driver * D,const ArgList & Args) const1010e5dd7070Spatrick VersionTuple CudaToolChain::computeMSVCVersion(const Driver *D,
1011e5dd7070Spatrick                                                const ArgList &Args) const {
1012e5dd7070Spatrick   return HostTC.computeMSVCVersion(D, Args);
1013e5dd7070Spatrick }
1014