blob: 119c9fcd0d9e5ad96f20625f67365324f3f7368a [file] [log] [blame]
David L. Jonesf561aba2017-03-08 01:02:16 +00001//===--- Cuda.cpp - Cuda Tool and ToolChain Implementations -----*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
David L. Jonesf561aba2017-03-08 01:02:16 +00006//
7//===----------------------------------------------------------------------===//
8
9#include "Cuda.h"
Gheorghe-Teodor Bercea2c926932017-08-08 14:33:05 +000010#include "CommonArgs.h"
Jonas Hahnfeld7f9c5182018-01-31 08:26:51 +000011#include "InputInfo.h"
David L. Jonesf561aba2017-03-08 01:02:16 +000012#include "clang/Basic/Cuda.h"
Jonas Hahnfeld7f9c5182018-01-31 08:26:51 +000013#include "clang/Config/config.h"
David L. Jonesf561aba2017-03-08 01:02:16 +000014#include "clang/Driver/Compilation.h"
Jonas Hahnfeld7f9c5182018-01-31 08:26:51 +000015#include "clang/Driver/Distro.h"
David L. Jonesf561aba2017-03-08 01:02:16 +000016#include "clang/Driver/Driver.h"
17#include "clang/Driver/DriverDiagnostic.h"
18#include "clang/Driver/Options.h"
19#include "llvm/Option/ArgList.h"
Jonas Hahnfeld7f9c5182018-01-31 08:26:51 +000020#include "llvm/Support/FileSystem.h"
David L. Jonesf561aba2017-03-08 01:02:16 +000021#include "llvm/Support/Path.h"
Gheorghe-Teodor Bercea148046c2018-03-13 19:39:19 +000022#include "llvm/Support/Process.h"
Jonas Hahnfeld7f9c5182018-01-31 08:26:51 +000023#include "llvm/Support/Program.h"
Jonas Devliegherefc514902018-10-10 13:27:25 +000024#include "llvm/Support/VirtualFileSystem.h"
David L. Jonesf561aba2017-03-08 01:02:16 +000025#include <system_error>
26
27using namespace clang::driver;
28using namespace clang::driver::toolchains;
29using namespace clang::driver::tools;
30using namespace clang;
31using namespace llvm::opt;
32
33// Parses the contents of version.txt in an CUDA installation. It should
34// contain one line of the from e.g. "CUDA Version 7.5.2".
35static CudaVersion ParseCudaVersionFile(llvm::StringRef V) {
36 if (!V.startswith("CUDA Version "))
37 return CudaVersion::UNKNOWN;
38 V = V.substr(strlen("CUDA Version "));
39 int Major = -1, Minor = -1;
40 auto First = V.split('.');
41 auto Second = First.second.split('.');
42 if (First.first.getAsInteger(10, Major) ||
43 Second.first.getAsInteger(10, Minor))
44 return CudaVersion::UNKNOWN;
45
46 if (Major == 7 && Minor == 0) {
47 // This doesn't appear to ever happen -- version.txt doesn't exist in the
48 // CUDA 7 installs I've seen. But no harm in checking.
49 return CudaVersion::CUDA_70;
50 }
51 if (Major == 7 && Minor == 5)
52 return CudaVersion::CUDA_75;
53 if (Major == 8 && Minor == 0)
54 return CudaVersion::CUDA_80;
Artem Belevich8af4e232017-09-07 18:14:32 +000055 if (Major == 9 && Minor == 0)
56 return CudaVersion::CUDA_90;
Artem Belevichfbc56a92018-01-30 00:00:12 +000057 if (Major == 9 && Minor == 1)
58 return CudaVersion::CUDA_91;
Artem Belevich3cce3072018-04-24 18:23:19 +000059 if (Major == 9 && Minor == 2)
60 return CudaVersion::CUDA_92;
Artem Belevich44ecb0e2018-09-24 23:10:44 +000061 if (Major == 10 && Minor == 0)
62 return CudaVersion::CUDA_100;
David L. Jonesf561aba2017-03-08 01:02:16 +000063 return CudaVersion::UNKNOWN;
64}
65
66CudaInstallationDetector::CudaInstallationDetector(
67 const Driver &D, const llvm::Triple &HostTriple,
68 const llvm::opt::ArgList &Args)
69 : D(D) {
Jonas Hahnfeld7f9c5182018-01-31 08:26:51 +000070 struct Candidate {
71 std::string Path;
72 bool StrictChecking;
73
74 Candidate(std::string Path, bool StrictChecking = false)
75 : Path(Path), StrictChecking(StrictChecking) {}
76 };
77 SmallVector<Candidate, 4> Candidates;
David L. Jonesf561aba2017-03-08 01:02:16 +000078
79 // In decreasing order so we prefer newer versions to older versions.
80 std::initializer_list<const char *> Versions = {"8.0", "7.5", "7.0"};
81
82 if (Args.hasArg(clang::driver::options::OPT_cuda_path_EQ)) {
Jonas Hahnfeld7f9c5182018-01-31 08:26:51 +000083 Candidates.emplace_back(
84 Args.getLastArgValue(clang::driver::options::OPT_cuda_path_EQ).str());
David L. Jonesf561aba2017-03-08 01:02:16 +000085 } else if (HostTriple.isOSWindows()) {
86 for (const char *Ver : Versions)
Jonas Hahnfeld7f9c5182018-01-31 08:26:51 +000087 Candidates.emplace_back(
David L. Jonesf561aba2017-03-08 01:02:16 +000088 D.SysRoot + "/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v" +
89 Ver);
90 } else {
Jonas Hahnfeld7f9c5182018-01-31 08:26:51 +000091 if (!Args.hasArg(clang::driver::options::OPT_cuda_path_ignore_env)) {
92 // Try to find ptxas binary. If the executable is located in a directory
93 // called 'bin/', its parent directory might be a good guess for a valid
94 // CUDA installation.
95 // However, some distributions might installs 'ptxas' to /usr/bin. In that
96 // case the candidate would be '/usr' which passes the following checks
97 // because '/usr/include' exists as well. To avoid this case, we always
98 // check for the directory potentially containing files for libdevice,
99 // even if the user passes -nocudalib.
100 if (llvm::ErrorOr<std::string> ptxas =
101 llvm::sys::findProgramByName("ptxas")) {
102 SmallString<256> ptxasAbsolutePath;
103 llvm::sys::fs::real_path(*ptxas, ptxasAbsolutePath);
104
105 StringRef ptxasDir = llvm::sys::path::parent_path(ptxasAbsolutePath);
106 if (llvm::sys::path::filename(ptxasDir) == "bin")
107 Candidates.emplace_back(llvm::sys::path::parent_path(ptxasDir),
108 /*StrictChecking=*/true);
109 }
110 }
111
112 Candidates.emplace_back(D.SysRoot + "/usr/local/cuda");
David L. Jonesf561aba2017-03-08 01:02:16 +0000113 for (const char *Ver : Versions)
Jonas Hahnfeld7f9c5182018-01-31 08:26:51 +0000114 Candidates.emplace_back(D.SysRoot + "/usr/local/cuda-" + Ver);
Sylvestre Ledru0cfcdc32017-11-29 15:03:28 +0000115
Joel E. Denny6dd34dc2018-12-06 17:46:17 +0000116 if (Distro(D.getVFS()).IsDebian() || Distro(D.getVFS()).IsUbuntu())
Sylvestre Ledru0cfcdc32017-11-29 15:03:28 +0000117 // Special case for Debian to have nvidia-cuda-toolkit work
118 // out of the box. More info on http://bugs.debian.org/882505
Jonas Hahnfeld7f9c5182018-01-31 08:26:51 +0000119 Candidates.emplace_back(D.SysRoot + "/usr/lib/cuda");
David L. Jonesf561aba2017-03-08 01:02:16 +0000120 }
121
Jonas Hahnfeld7f9c5182018-01-31 08:26:51 +0000122 bool NoCudaLib = Args.hasArg(options::OPT_nocudalib);
123
124 for (const auto &Candidate : Candidates) {
125 InstallPath = Candidate.Path;
126 if (InstallPath.empty() || !D.getVFS().exists(InstallPath))
David L. Jonesf561aba2017-03-08 01:02:16 +0000127 continue;
128
Jonas Hahnfeld7f9c5182018-01-31 08:26:51 +0000129 BinPath = InstallPath + "/bin";
David L. Jonesf561aba2017-03-08 01:02:16 +0000130 IncludePath = InstallPath + "/include";
131 LibDevicePath = InstallPath + "/nvvm/libdevice";
132
133 auto &FS = D.getVFS();
Jonas Hahnfelde2c342f2017-10-16 13:31:30 +0000134 if (!(FS.exists(IncludePath) && FS.exists(BinPath)))
David L. Jonesf561aba2017-03-08 01:02:16 +0000135 continue;
Jonas Hahnfeld7f9c5182018-01-31 08:26:51 +0000136 bool CheckLibDevice = (!NoCudaLib || Candidate.StrictChecking);
137 if (CheckLibDevice && !FS.exists(LibDevicePath))
138 continue;
David L. Jonesf561aba2017-03-08 01:02:16 +0000139
140 // On Linux, we have both lib and lib64 directories, and we need to choose
141 // based on our triple. On MacOS, we have only a lib directory.
142 //
143 // It's sufficient for our purposes to be flexible: If both lib and lib64
144 // exist, we choose whichever one matches our triple. Otherwise, if only
145 // lib exists, we use it.
146 if (HostTriple.isArch64Bit() && FS.exists(InstallPath + "/lib64"))
147 LibPath = InstallPath + "/lib64";
148 else if (FS.exists(InstallPath + "/lib"))
149 LibPath = InstallPath + "/lib";
150 else
151 continue;
152
153 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> VersionFile =
154 FS.getBufferForFile(InstallPath + "/version.txt");
155 if (!VersionFile) {
156 // CUDA 7.0 doesn't have a version.txt, so guess that's our version if
157 // version.txt isn't present.
158 Version = CudaVersion::CUDA_70;
159 } else {
160 Version = ParseCudaVersionFile((*VersionFile)->getBuffer());
161 }
162
Artem Belevichfbc56a92018-01-30 00:00:12 +0000163 if (Version >= CudaVersion::CUDA_90) {
164 // CUDA-9+ uses single libdevice file for all GPU variants.
Artem Belevich8af4e232017-09-07 18:14:32 +0000165 std::string FilePath = LibDevicePath + "/libdevice.10.bc";
166 if (FS.exists(FilePath)) {
Artem Belevichfbc56a92018-01-30 00:00:12 +0000167 for (const char *GpuArchName :
Artem Belevich578653a2018-05-23 16:45:23 +0000168 {"sm_30", "sm_32", "sm_35", "sm_37", "sm_50", "sm_52", "sm_53",
Artem Belevich44ecb0e2018-09-24 23:10:44 +0000169 "sm_60", "sm_61", "sm_62", "sm_70", "sm_72", "sm_75"}) {
Artem Belevichfbc56a92018-01-30 00:00:12 +0000170 const CudaArch GpuArch = StringToCudaArch(GpuArchName);
171 if (Version >= MinVersionForCudaArch(GpuArch) &&
172 Version <= MaxVersionForCudaArch(GpuArch))
173 LibDeviceMap[GpuArchName] = FilePath;
174 }
Artem Belevich8af4e232017-09-07 18:14:32 +0000175 }
176 } else {
177 std::error_code EC;
178 for (llvm::sys::fs::directory_iterator LI(LibDevicePath, EC), LE;
179 !EC && LI != LE; LI = LI.increment(EC)) {
180 StringRef FilePath = LI->path();
181 StringRef FileName = llvm::sys::path::filename(FilePath);
182 // Process all bitcode filenames that look like
183 // libdevice.compute_XX.YY.bc
184 const StringRef LibDeviceName = "libdevice.";
185 if (!(FileName.startswith(LibDeviceName) && FileName.endswith(".bc")))
186 continue;
187 StringRef GpuArch = FileName.slice(
188 LibDeviceName.size(), FileName.find('.', LibDeviceName.size()));
189 LibDeviceMap[GpuArch] = FilePath.str();
Alexander Kornienko2a8c18d2018-04-06 15:14:32 +0000190 // Insert map entries for specific devices with this compute
Artem Belevich8af4e232017-09-07 18:14:32 +0000191 // capability. NVCC's choice of the libdevice library version is
192 // rather peculiar and depends on the CUDA version.
193 if (GpuArch == "compute_20") {
194 LibDeviceMap["sm_20"] = FilePath;
195 LibDeviceMap["sm_21"] = FilePath;
196 LibDeviceMap["sm_32"] = FilePath;
197 } else if (GpuArch == "compute_30") {
198 LibDeviceMap["sm_30"] = FilePath;
199 if (Version < CudaVersion::CUDA_80) {
200 LibDeviceMap["sm_50"] = FilePath;
201 LibDeviceMap["sm_52"] = FilePath;
202 LibDeviceMap["sm_53"] = FilePath;
203 }
204 LibDeviceMap["sm_60"] = FilePath;
205 LibDeviceMap["sm_61"] = FilePath;
206 LibDeviceMap["sm_62"] = FilePath;
207 } else if (GpuArch == "compute_35") {
208 LibDeviceMap["sm_35"] = FilePath;
209 LibDeviceMap["sm_37"] = FilePath;
210 } else if (GpuArch == "compute_50") {
211 if (Version >= CudaVersion::CUDA_80) {
212 LibDeviceMap["sm_50"] = FilePath;
213 LibDeviceMap["sm_52"] = FilePath;
214 LibDeviceMap["sm_53"] = FilePath;
215 }
David L. Jonesf561aba2017-03-08 01:02:16 +0000216 }
217 }
218 }
219
Jonas Hahnfelde2c342f2017-10-16 13:31:30 +0000220 // Check that we have found at least one libdevice that we can link in if
221 // -nocudalib hasn't been specified.
Jonas Hahnfeld7f9c5182018-01-31 08:26:51 +0000222 if (LibDeviceMap.empty() && !NoCudaLib)
Gheorghe-Teodor Bercea9c525742017-08-11 15:46:22 +0000223 continue;
224
David L. Jonesf561aba2017-03-08 01:02:16 +0000225 IsValid = true;
226 break;
227 }
228}
229
230void CudaInstallationDetector::AddCudaIncludeArgs(
231 const ArgList &DriverArgs, ArgStringList &CC1Args) const {
232 if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
233 // Add cuda_wrappers/* to our system include path. This lets us wrap
234 // standard library headers.
235 SmallString<128> P(D.ResourceDir);
236 llvm::sys::path::append(P, "include");
237 llvm::sys::path::append(P, "cuda_wrappers");
238 CC1Args.push_back("-internal-isystem");
239 CC1Args.push_back(DriverArgs.MakeArgString(P));
240 }
241
242 if (DriverArgs.hasArg(options::OPT_nocudainc))
243 return;
244
245 if (!isValid()) {
246 D.Diag(diag::err_drv_no_cuda_installation);
247 return;
248 }
249
250 CC1Args.push_back("-internal-isystem");
251 CC1Args.push_back(DriverArgs.MakeArgString(getIncludePath()));
252 CC1Args.push_back("-include");
253 CC1Args.push_back("__clang_cuda_runtime_wrapper.h");
254}
255
256void CudaInstallationDetector::CheckCudaVersionSupportsArch(
257 CudaArch Arch) const {
258 if (Arch == CudaArch::UNKNOWN || Version == CudaVersion::UNKNOWN ||
Justin Lebar066494d2017-10-25 21:32:06 +0000259 ArchsWithBadVersion.count(Arch) > 0)
David L. Jonesf561aba2017-03-08 01:02:16 +0000260 return;
261
Justin Lebar066494d2017-10-25 21:32:06 +0000262 auto MinVersion = MinVersionForCudaArch(Arch);
263 auto MaxVersion = MaxVersionForCudaArch(Arch);
264 if (Version < MinVersion || Version > MaxVersion) {
265 ArchsWithBadVersion.insert(Arch);
266 D.Diag(diag::err_drv_cuda_version_unsupported)
267 << CudaArchToString(Arch) << CudaVersionToString(MinVersion)
268 << CudaVersionToString(MaxVersion) << InstallPath
269 << CudaVersionToString(Version);
David L. Jonesf561aba2017-03-08 01:02:16 +0000270 }
271}
272
273void CudaInstallationDetector::print(raw_ostream &OS) const {
274 if (isValid())
275 OS << "Found CUDA installation: " << InstallPath << ", version "
276 << CudaVersionToString(Version) << "\n";
277}
278
Alexey Bataeve36c67b2018-04-18 16:31:09 +0000279namespace {
Alexey Bataevc92fc3c2018-12-12 14:52:27 +0000280/// Debug info level for the NVPTX devices. We may need to emit different debug
281/// info level for the host and for the device itselfi. This type controls
282/// emission of the debug info for the devices. It either prohibits disable info
283/// emission completely, or emits debug directives only, or emits same debug
284/// info as for the host.
285enum DeviceDebugInfoLevel {
286 DisableDebugInfo, /// Do not emit debug info for the devices.
287 DebugDirectivesOnly, /// Emit only debug directives.
288 EmitSameDebugInfoAsHost, /// Use the same debug info level just like for the
289 /// host.
Alexey Bataeve36c67b2018-04-18 16:31:09 +0000290};
291} // anonymous namespace
292
Alexey Bataevc92fc3c2018-12-12 14:52:27 +0000293/// Define debug info level for the NVPTX devices. If the debug info for both
294/// the host and device are disabled (-g0/-ggdb0 or no debug options at all). If
295/// only debug directives are requested for the both host and device
296/// (-gline-directvies-only), or the debug info only for the device is disabled
297/// (optimization is on and --cuda-noopt-device-debug was not specified), the
298/// debug directves only must be emitted for the device. Otherwise, use the same
299/// debug info level just like for the host (with the limitations of only
300/// supported DWARF2 standard).
301static DeviceDebugInfoLevel mustEmitDebugInfo(const ArgList &Args) {
302 const Arg *A = Args.getLastArg(options::OPT_O_Group);
303 bool IsDebugEnabled = !A || A->getOption().matches(options::OPT_O0) ||
304 Args.hasFlag(options::OPT_cuda_noopt_device_debug,
305 options::OPT_no_cuda_noopt_device_debug,
306 /*Default=*/false);
307 if (const Arg *A = Args.getLastArg(options::OPT_g_Group)) {
308 const Option &Opt = A->getOption();
309 if (Opt.matches(options::OPT_gN_Group)) {
310 if (Opt.matches(options::OPT_g0) || Opt.matches(options::OPT_ggdb0))
311 return DisableDebugInfo;
312 if (Opt.matches(options::OPT_gline_directives_only))
313 return DebugDirectivesOnly;
Alexey Bataeve36c67b2018-04-18 16:31:09 +0000314 }
Alexey Bataevc92fc3c2018-12-12 14:52:27 +0000315 return IsDebugEnabled ? EmitSameDebugInfoAsHost : DebugDirectivesOnly;
Alexey Bataeve36c67b2018-04-18 16:31:09 +0000316 }
Alexey Bataevc92fc3c2018-12-12 14:52:27 +0000317 return DisableDebugInfo;
Alexey Bataeve36c67b2018-04-18 16:31:09 +0000318}
319
David L. Jonesf561aba2017-03-08 01:02:16 +0000320void NVPTX::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
321 const InputInfo &Output,
322 const InputInfoList &Inputs,
323 const ArgList &Args,
324 const char *LinkingOutput) const {
325 const auto &TC =
326 static_cast<const toolchains::CudaToolChain &>(getToolChain());
327 assert(TC.getTriple().isNVPTX() && "Wrong platform");
328
Gheorghe-Teodor Bercea47e0cf32017-08-07 15:39:11 +0000329 StringRef GPUArchName;
330 // If this is an OpenMP action we need to extract the device architecture
331 // from the -march=arch option. This option may come from -Xopenmp-target
332 // flag or the default value.
333 if (JA.isDeviceOffloading(Action::OFK_OpenMP)) {
334 GPUArchName = Args.getLastArgValue(options::OPT_march_EQ);
335 assert(!GPUArchName.empty() && "Must have an architecture passed in.");
336 } else
337 GPUArchName = JA.getOffloadingArch();
338
David L. Jonesf561aba2017-03-08 01:02:16 +0000339 // Obtain architecture from the action.
Gheorghe-Teodor Bercea47e0cf32017-08-07 15:39:11 +0000340 CudaArch gpu_arch = StringToCudaArch(GPUArchName);
David L. Jonesf561aba2017-03-08 01:02:16 +0000341 assert(gpu_arch != CudaArch::UNKNOWN &&
342 "Device action expected to have an architecture.");
343
344 // Check that our installation's ptxas supports gpu_arch.
345 if (!Args.hasArg(options::OPT_no_cuda_version_check)) {
346 TC.CudaInstallation.CheckCudaVersionSupportsArch(gpu_arch);
347 }
348
349 ArgStringList CmdArgs;
350 CmdArgs.push_back(TC.getTriple().isArch64Bit() ? "-m64" : "-m32");
Alexey Bataevc92fc3c2018-12-12 14:52:27 +0000351 DeviceDebugInfoLevel DIKind = mustEmitDebugInfo(Args);
352 if (DIKind == EmitSameDebugInfoAsHost) {
David L. Jonesf561aba2017-03-08 01:02:16 +0000353 // ptxas does not accept -g option if optimization is enabled, so
354 // we ignore the compiler's -O* options if we want debug info.
355 CmdArgs.push_back("-g");
356 CmdArgs.push_back("--dont-merge-basicblocks");
357 CmdArgs.push_back("--return-at-end");
358 } else if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
359 // Map the -O we received to -O{0,1,2,3}.
360 //
361 // TODO: Perhaps we should map host -O2 to ptxas -O3. -O3 is ptxas's
362 // default, so it may correspond more closely to the spirit of clang -O2.
363
364 // -O3 seems like the least-bad option when -Osomething is specified to
365 // clang but it isn't handled below.
366 StringRef OOpt = "3";
367 if (A->getOption().matches(options::OPT_O4) ||
368 A->getOption().matches(options::OPT_Ofast))
369 OOpt = "3";
370 else if (A->getOption().matches(options::OPT_O0))
371 OOpt = "0";
372 else if (A->getOption().matches(options::OPT_O)) {
373 // -Os, -Oz, and -O(anything else) map to -O2, for lack of better options.
374 OOpt = llvm::StringSwitch<const char *>(A->getValue())
375 .Case("1", "1")
376 .Case("2", "2")
377 .Case("3", "3")
378 .Case("s", "2")
379 .Case("z", "2")
380 .Default("2");
381 }
382 CmdArgs.push_back(Args.MakeArgString(llvm::Twine("-O") + OOpt));
383 } else {
384 // If no -O was passed, pass -O0 to ptxas -- no opt flag should correspond
385 // to no optimizations, but ptxas's default is -O3.
386 CmdArgs.push_back("-O0");
387 }
Alexey Bataevc92fc3c2018-12-12 14:52:27 +0000388 if (DIKind == DebugDirectivesOnly)
Alexey Bataeve36c67b2018-04-18 16:31:09 +0000389 CmdArgs.push_back("-lineinfo");
David L. Jonesf561aba2017-03-08 01:02:16 +0000390
Gheorghe-Teodor Bercea53431bc2017-08-07 20:19:23 +0000391 // Pass -v to ptxas if it was passed to the driver.
392 if (Args.hasArg(options::OPT_v))
393 CmdArgs.push_back("-v");
394
David L. Jonesf561aba2017-03-08 01:02:16 +0000395 CmdArgs.push_back("--gpu-name");
396 CmdArgs.push_back(Args.MakeArgString(CudaArchToString(gpu_arch)));
397 CmdArgs.push_back("--output-file");
Jonas Hahnfeld7c78cc52017-11-21 14:44:45 +0000398 CmdArgs.push_back(Args.MakeArgString(TC.getInputFilename(Output)));
David L. Jonesf561aba2017-03-08 01:02:16 +0000399 for (const auto& II : Inputs)
400 CmdArgs.push_back(Args.MakeArgString(II.getFilename()));
401
402 for (const auto& A : Args.getAllArgValues(options::OPT_Xcuda_ptxas))
403 CmdArgs.push_back(Args.MakeArgString(A));
404
Jonas Hahnfeld5379c6d2018-02-12 10:46:45 +0000405 bool Relocatable = false;
406 if (JA.isOffloading(Action::OFK_OpenMP))
407 // In OpenMP we need to generate relocatable code.
408 Relocatable = Args.hasFlag(options::OPT_fopenmp_relocatable_target,
409 options::OPT_fnoopenmp_relocatable_target,
410 /*Default=*/true);
411 else if (JA.isOffloading(Action::OFK_Cuda))
Yaxun Liu97670892018-10-02 17:48:54 +0000412 Relocatable = Args.hasFlag(options::OPT_fgpu_rdc,
413 options::OPT_fno_gpu_rdc, /*Default=*/false);
Jonas Hahnfeld5379c6d2018-02-12 10:46:45 +0000414
415 if (Relocatable)
Gheorghe-Teodor Berceab9d11722017-08-09 14:59:35 +0000416 CmdArgs.push_back("-c");
417
David L. Jonesf561aba2017-03-08 01:02:16 +0000418 const char *Exec;
419 if (Arg *A = Args.getLastArg(options::OPT_ptxas_path_EQ))
420 Exec = A->getValue();
421 else
422 Exec = Args.MakeArgString(TC.GetProgramPath("ptxas"));
423 C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
424}
425
Artem Belevichdde3dc22018-04-10 18:38:22 +0000426static bool shouldIncludePTX(const ArgList &Args, const char *gpu_arch) {
427 bool includePTX = true;
428 for (Arg *A : Args) {
429 if (!(A->getOption().matches(options::OPT_cuda_include_ptx_EQ) ||
430 A->getOption().matches(options::OPT_no_cuda_include_ptx_EQ)))
431 continue;
432 A->claim();
433 const StringRef ArchStr = A->getValue();
434 if (ArchStr == "all" || ArchStr == gpu_arch) {
435 includePTX = A->getOption().matches(options::OPT_cuda_include_ptx_EQ);
436 continue;
437 }
438 }
439 return includePTX;
440}
441
David L. Jonesf561aba2017-03-08 01:02:16 +0000442// All inputs to this linker must be from CudaDeviceActions, as we need to look
443// at the Inputs' Actions in order to figure out which GPU architecture they
444// correspond to.
445void NVPTX::Linker::ConstructJob(Compilation &C, const JobAction &JA,
446 const InputInfo &Output,
447 const InputInfoList &Inputs,
448 const ArgList &Args,
449 const char *LinkingOutput) const {
450 const auto &TC =
451 static_cast<const toolchains::CudaToolChain &>(getToolChain());
452 assert(TC.getTriple().isNVPTX() && "Wrong platform");
453
454 ArgStringList CmdArgs;
455 CmdArgs.push_back("--cuda");
456 CmdArgs.push_back(TC.getTriple().isArch64Bit() ? "-64" : "-32");
457 CmdArgs.push_back(Args.MakeArgString("--create"));
458 CmdArgs.push_back(Args.MakeArgString(Output.getFilename()));
Alexey Bataevc92fc3c2018-12-12 14:52:27 +0000459 if (mustEmitDebugInfo(Args) == EmitSameDebugInfoAsHost)
Alexey Bataeve36c67b2018-04-18 16:31:09 +0000460 CmdArgs.push_back("-g");
David L. Jonesf561aba2017-03-08 01:02:16 +0000461
462 for (const auto& II : Inputs) {
463 auto *A = II.getAction();
464 assert(A->getInputs().size() == 1 &&
465 "Device offload action is expected to have a single input");
466 const char *gpu_arch_str = A->getOffloadingArch();
467 assert(gpu_arch_str &&
468 "Device action expected to have associated a GPU architecture!");
469 CudaArch gpu_arch = StringToCudaArch(gpu_arch_str);
470
Artem Belevichdde3dc22018-04-10 18:38:22 +0000471 if (II.getType() == types::TY_PP_Asm &&
472 !shouldIncludePTX(Args, gpu_arch_str))
473 continue;
David L. Jonesf561aba2017-03-08 01:02:16 +0000474 // We need to pass an Arch of the form "sm_XX" for cubin files and
475 // "compute_XX" for ptx.
476 const char *Arch =
477 (II.getType() == types::TY_PP_Asm)
478 ? CudaVirtualArchToString(VirtualArchForCudaArch(gpu_arch))
479 : gpu_arch_str;
480 CmdArgs.push_back(Args.MakeArgString(llvm::Twine("--image=profile=") +
481 Arch + ",file=" + II.getFilename()));
482 }
483
484 for (const auto& A : Args.getAllArgValues(options::OPT_Xcuda_fatbinary))
485 CmdArgs.push_back(Args.MakeArgString(A));
486
487 const char *Exec = Args.MakeArgString(TC.GetProgramPath("fatbinary"));
488 C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
489}
490
Gheorghe-Teodor Bercea2c926932017-08-08 14:33:05 +0000491void NVPTX::OpenMPLinker::ConstructJob(Compilation &C, const JobAction &JA,
492 const InputInfo &Output,
493 const InputInfoList &Inputs,
494 const ArgList &Args,
495 const char *LinkingOutput) const {
496 const auto &TC =
497 static_cast<const toolchains::CudaToolChain &>(getToolChain());
498 assert(TC.getTriple().isNVPTX() && "Wrong platform");
499
500 ArgStringList CmdArgs;
501
502 // OpenMP uses nvlink to link cubin files. The result will be embedded in the
503 // host binary by the host linker.
504 assert(!JA.isHostOffloading(Action::OFK_OpenMP) &&
505 "CUDA toolchain not expected for an OpenMP host device.");
506
507 if (Output.isFilename()) {
508 CmdArgs.push_back("-o");
509 CmdArgs.push_back(Output.getFilename());
510 } else
511 assert(Output.isNothing() && "Invalid output.");
Alexey Bataevc92fc3c2018-12-12 14:52:27 +0000512 if (mustEmitDebugInfo(Args) == EmitSameDebugInfoAsHost)
Gheorghe-Teodor Bercea2c926932017-08-08 14:33:05 +0000513 CmdArgs.push_back("-g");
514
515 if (Args.hasArg(options::OPT_v))
516 CmdArgs.push_back("-v");
517
518 StringRef GPUArch =
519 Args.getLastArgValue(options::OPT_march_EQ);
520 assert(!GPUArch.empty() && "At least one GPU Arch required for ptxas.");
521
522 CmdArgs.push_back("-arch");
523 CmdArgs.push_back(Args.MakeArgString(GPUArch));
524
Jonas Hahnfelda981f672018-09-27 16:12:32 +0000525 // Assume that the directory specified with --libomptarget_nvptx_path
526 // contains the static library libomptarget-nvptx.a.
527 if (const Arg *A = Args.getLastArg(options::OPT_libomptarget_nvptx_path_EQ))
528 CmdArgs.push_back(Args.MakeArgString(Twine("-L") + A->getValue()));
529
Gheorghe-Teodor Bercea2c926932017-08-08 14:33:05 +0000530 // Add paths specified in LIBRARY_PATH environment variable as -L options.
531 addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH");
532
533 // Add paths for the default clang library path.
534 SmallString<256> DefaultLibPath =
535 llvm::sys::path::parent_path(TC.getDriver().Dir);
536 llvm::sys::path::append(DefaultLibPath, "lib" CLANG_LIBDIR_SUFFIX);
537 CmdArgs.push_back(Args.MakeArgString(Twine("-L") + DefaultLibPath));
538
539 // Add linking against library implementing OpenMP calls on NVPTX target.
540 CmdArgs.push_back("-lomptarget-nvptx");
541
542 for (const auto &II : Inputs) {
543 if (II.getType() == types::TY_LLVM_IR ||
544 II.getType() == types::TY_LTO_IR ||
545 II.getType() == types::TY_LTO_BC ||
546 II.getType() == types::TY_LLVM_BC) {
547 C.getDriver().Diag(diag::err_drv_no_linker_llvm_support)
548 << getToolChain().getTripleString();
549 continue;
550 }
551
552 // Currently, we only pass the input files to the linker, we do not pass
553 // any libraries that may be valid only for the host.
554 if (!II.isFilename())
555 continue;
556
Jonas Hahnfeld7c78cc52017-11-21 14:44:45 +0000557 const char *CubinF = C.addTempFile(
558 C.getArgs().MakeArgString(getToolChain().getInputFilename(II)));
Gheorghe-Teodor Bercea2c926932017-08-08 14:33:05 +0000559
560 CmdArgs.push_back(CubinF);
561 }
562
563 AddOpenMPLinkerScript(getToolChain(), C, Output, Inputs, Args, CmdArgs, JA);
564
565 const char *Exec =
566 Args.MakeArgString(getToolChain().GetProgramPath("nvlink"));
567 C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
568}
569
David L. Jonesf561aba2017-03-08 01:02:16 +0000570/// CUDA toolchain. Our assembler is ptxas, and our "linker" is fatbinary,
571/// which isn't properly a linker but nonetheless performs the step of stitching
572/// together object files from the assembler into a single blob.
573
574CudaToolChain::CudaToolChain(const Driver &D, const llvm::Triple &Triple,
Gheorghe-Teodor Bercea2c926932017-08-08 14:33:05 +0000575 const ToolChain &HostTC, const ArgList &Args,
576 const Action::OffloadKind OK)
David L. Jonesf561aba2017-03-08 01:02:16 +0000577 : ToolChain(D, Triple, Args), HostTC(HostTC),
Gheorghe-Teodor Bercea2c926932017-08-08 14:33:05 +0000578 CudaInstallation(D, HostTC.getTriple(), Args), OK(OK) {
David L. Jonesf561aba2017-03-08 01:02:16 +0000579 if (CudaInstallation.isValid())
580 getProgramPaths().push_back(CudaInstallation.getBinPath());
Gheorghe-Teodor Bercea690f6f92017-08-09 19:52:28 +0000581 // Lookup binaries into the driver directory, this is used to
582 // discover the clang-offload-bundler executable.
583 getProgramPaths().push_back(getDriver().Dir);
David L. Jonesf561aba2017-03-08 01:02:16 +0000584}
585
Jonas Hahnfeld7c78cc52017-11-21 14:44:45 +0000586std::string CudaToolChain::getInputFilename(const InputInfo &Input) const {
587 // Only object files are changed, for example assembly files keep their .s
588 // extensions. CUDA also continues to use .o as they don't use nvlink but
589 // fatbinary.
590 if (!(OK == Action::OFK_OpenMP && Input.getType() == types::TY_Object))
591 return ToolChain::getInputFilename(Input);
592
593 // Replace extension for object files with cubin because nvlink relies on
594 // these particular file names.
595 SmallString<256> Filename(ToolChain::getInputFilename(Input));
596 llvm::sys::path::replace_extension(Filename, "cubin");
597 return Filename.str();
598}
599
David L. Jonesf561aba2017-03-08 01:02:16 +0000600void CudaToolChain::addClangTargetOptions(
601 const llvm::opt::ArgList &DriverArgs,
Gheorghe-Teodor Berceaf0f29602017-07-06 16:22:21 +0000602 llvm::opt::ArgStringList &CC1Args,
603 Action::OffloadKind DeviceOffloadingKind) const {
604 HostTC.addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadingKind);
David L. Jonesf561aba2017-03-08 01:02:16 +0000605
606 StringRef GpuArch = DriverArgs.getLastArgValue(options::OPT_march_EQ);
607 assert(!GpuArch.empty() && "Must have an explicit GPU arch.");
Gheorghe-Teodor Berceaf0f29602017-07-06 16:22:21 +0000608 assert((DeviceOffloadingKind == Action::OFK_OpenMP ||
609 DeviceOffloadingKind == Action::OFK_Cuda) &&
610 "Only OpenMP or CUDA offloading kinds are supported for NVIDIA GPUs.");
611
612 if (DeviceOffloadingKind == Action::OFK_Cuda) {
613 CC1Args.push_back("-fcuda-is-device");
614
615 if (DriverArgs.hasFlag(options::OPT_fcuda_flush_denormals_to_zero,
616 options::OPT_fno_cuda_flush_denormals_to_zero, false))
617 CC1Args.push_back("-fcuda-flush-denormals-to-zero");
618
619 if (DriverArgs.hasFlag(options::OPT_fcuda_approx_transcendentals,
620 options::OPT_fno_cuda_approx_transcendentals, false))
621 CC1Args.push_back("-fcuda-approx-transcendentals");
Jonas Hahnfeld5379c6d2018-02-12 10:46:45 +0000622
Yaxun Liu97670892018-10-02 17:48:54 +0000623 if (DriverArgs.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
Jonas Hahnfeld5379c6d2018-02-12 10:46:45 +0000624 false))
Yaxun Liu97670892018-10-02 17:48:54 +0000625 CC1Args.push_back("-fgpu-rdc");
Gheorghe-Teodor Berceaf0f29602017-07-06 16:22:21 +0000626 }
627
Gheorghe-Teodor Bercea20789a52017-09-25 21:56:32 +0000628 if (DriverArgs.hasArg(options::OPT_nocudalib))
629 return;
630
David L. Jonesf561aba2017-03-08 01:02:16 +0000631 std::string LibDeviceFile = CudaInstallation.getLibDeviceFile(GpuArch);
632
633 if (LibDeviceFile.empty()) {
Gheorghe-Teodor Bercea5a3608c2017-09-26 15:36:20 +0000634 if (DeviceOffloadingKind == Action::OFK_OpenMP &&
635 DriverArgs.hasArg(options::OPT_S))
636 return;
637
David L. Jonesf561aba2017-03-08 01:02:16 +0000638 getDriver().Diag(diag::err_drv_no_cuda_libdevice) << GpuArch;
639 return;
640 }
641
Matt Arsenaulta13746b2018-08-20 18:16:48 +0000642 CC1Args.push_back("-mlink-builtin-bitcode");
David L. Jonesf561aba2017-03-08 01:02:16 +0000643 CC1Args.push_back(DriverArgs.MakeArgString(LibDeviceFile));
644
Artem Belevich0ae85902018-04-18 21:51:48 +0000645 // Libdevice in CUDA-7.0 requires PTX version that's more recent than LLVM
646 // defaults to. Use PTX4.2 by default, which is the PTX version that came with
647 // CUDA-7.0.
648 const char *PtxFeature = "+ptx42";
Artem Belevich44ecb0e2018-09-24 23:10:44 +0000649 // TODO(tra): CUDA-10+ needs PTX 6.3 to support new features. However that
650 // requires fair amount of work on LLVM side. We'll keep using PTX 6.1 until
651 // all prerequisites are in place.
Artem Belevich0ae85902018-04-18 21:51:48 +0000652 if (CudaInstallation.version() >= CudaVersion::CUDA_91) {
653 // CUDA-9.1 uses new instructions that are only available in PTX6.1+
654 PtxFeature = "+ptx61";
655 } else if (CudaInstallation.version() >= CudaVersion::CUDA_90) {
656 // CUDA-9.0 uses new instructions that are only available in PTX6.0+
657 PtxFeature = "+ptx60";
Artem Belevich4654dc82017-09-20 21:23:07 +0000658 }
Artem Belevich679dafe2018-05-09 23:10:09 +0000659 CC1Args.append({"-target-feature", PtxFeature});
660 if (DriverArgs.hasFlag(options::OPT_fcuda_short_ptr,
661 options::OPT_fno_cuda_short_ptr, false))
662 CC1Args.append({"-mllvm", "--nvptx-short-ptr"});
Gheorghe-Teodor Bercea0d5aa842018-03-13 23:19:52 +0000663
664 if (DeviceOffloadingKind == Action::OFK_OpenMP) {
665 SmallVector<StringRef, 8> LibraryPaths;
Jonas Hahnfelda981f672018-09-27 16:12:32 +0000666
667 if (const Arg *A = DriverArgs.getLastArg(options::OPT_libomptarget_nvptx_path_EQ))
668 LibraryPaths.push_back(A->getValue());
Gheorghe-Teodor Bercea0d5aa842018-03-13 23:19:52 +0000669
670 // Add user defined library paths from LIBRARY_PATH.
671 llvm::Optional<std::string> LibPath =
672 llvm::sys::Process::GetEnv("LIBRARY_PATH");
673 if (LibPath) {
674 SmallVector<StringRef, 8> Frags;
675 const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
676 llvm::SplitString(*LibPath, Frags, EnvPathSeparatorStr);
677 for (StringRef Path : Frags)
678 LibraryPaths.emplace_back(Path.trim());
679 }
680
Jonas Hahnfelda981f672018-09-27 16:12:32 +0000681 // Add path to lib / lib64 folder.
682 SmallString<256> DefaultLibPath =
683 llvm::sys::path::parent_path(getDriver().Dir);
684 llvm::sys::path::append(DefaultLibPath, Twine("lib") + CLANG_LIBDIR_SUFFIX);
685 LibraryPaths.emplace_back(DefaultLibPath.c_str());
686
Gheorghe-Teodor Bercea0d5aa842018-03-13 23:19:52 +0000687 std::string LibOmpTargetName =
688 "libomptarget-nvptx-" + GpuArch.str() + ".bc";
689 bool FoundBCLibrary = false;
690 for (StringRef LibraryPath : LibraryPaths) {
691 SmallString<128> LibOmpTargetFile(LibraryPath);
692 llvm::sys::path::append(LibOmpTargetFile, LibOmpTargetName);
693 if (llvm::sys::fs::exists(LibOmpTargetFile)) {
Matt Arsenaulta13746b2018-08-20 18:16:48 +0000694 CC1Args.push_back("-mlink-builtin-bitcode");
Gheorghe-Teodor Bercea0d5aa842018-03-13 23:19:52 +0000695 CC1Args.push_back(DriverArgs.MakeArgString(LibOmpTargetFile));
696 FoundBCLibrary = true;
697 break;
698 }
699 }
700 if (!FoundBCLibrary)
701 getDriver().Diag(diag::warn_drv_omp_offload_target_missingbcruntime)
702 << LibOmpTargetName;
703 }
David L. Jonesf561aba2017-03-08 01:02:16 +0000704}
705
Alexey Bataevb83b4e42018-07-27 19:45:14 +0000706bool CudaToolChain::supportsDebugInfoOption(const llvm::opt::Arg *A) const {
707 const Option &O = A->getOption();
708 return (O.matches(options::OPT_gN_Group) &&
709 !O.matches(options::OPT_gmodules)) ||
710 O.matches(options::OPT_g_Flag) ||
711 O.matches(options::OPT_ggdbN_Group) || O.matches(options::OPT_ggdb) ||
712 O.matches(options::OPT_gdwarf) || O.matches(options::OPT_gdwarf_2) ||
713 O.matches(options::OPT_gdwarf_3) || O.matches(options::OPT_gdwarf_4) ||
714 O.matches(options::OPT_gdwarf_5) ||
715 O.matches(options::OPT_gcolumn_info);
716}
717
Alexey Bataevc92fc3c2018-12-12 14:52:27 +0000718void CudaToolChain::adjustDebugInfoKind(
719 codegenoptions::DebugInfoKind &DebugInfoKind, const ArgList &Args) const {
720 switch (mustEmitDebugInfo(Args)) {
721 case DisableDebugInfo:
722 DebugInfoKind = codegenoptions::NoDebugInfo;
723 break;
724 case DebugDirectivesOnly:
725 DebugInfoKind = codegenoptions::DebugDirectivesOnly;
726 break;
727 case EmitSameDebugInfoAsHost:
728 // Use same debug info level as the host.
729 break;
730 }
731}
732
David L. Jonesf561aba2017-03-08 01:02:16 +0000733void CudaToolChain::AddCudaIncludeArgs(const ArgList &DriverArgs,
734 ArgStringList &CC1Args) const {
735 // Check our CUDA version if we're going to include the CUDA headers.
736 if (!DriverArgs.hasArg(options::OPT_nocudainc) &&
737 !DriverArgs.hasArg(options::OPT_no_cuda_version_check)) {
738 StringRef Arch = DriverArgs.getLastArgValue(options::OPT_march_EQ);
739 assert(!Arch.empty() && "Must have an explicit GPU arch.");
740 CudaInstallation.CheckCudaVersionSupportsArch(StringToCudaArch(Arch));
741 }
742 CudaInstallation.AddCudaIncludeArgs(DriverArgs, CC1Args);
743}
744
745llvm::opt::DerivedArgList *
746CudaToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
747 StringRef BoundArch,
748 Action::OffloadKind DeviceOffloadKind) const {
749 DerivedArgList *DAL =
750 HostTC.TranslateArgs(Args, BoundArch, DeviceOffloadKind);
751 if (!DAL)
752 DAL = new DerivedArgList(Args.getBaseArgs());
753
754 const OptTable &Opts = getDriver().getOpts();
755
Gheorghe-Teodor Berceaf0f29602017-07-06 16:22:21 +0000756 // For OpenMP device offloading, append derived arguments. Make sure
757 // flags are not duplicated.
Gheorghe-Teodor Bercea47e0cf32017-08-07 15:39:11 +0000758 // Also append the compute capability.
Gheorghe-Teodor Berceaf0f29602017-07-06 16:22:21 +0000759 if (DeviceOffloadKind == Action::OFK_OpenMP) {
Jonas Hahnfeld30b44182017-10-17 13:37:36 +0000760 for (Arg *A : Args) {
Gheorghe-Teodor Berceaf0f29602017-07-06 16:22:21 +0000761 bool IsDuplicate = false;
Jonas Hahnfeld30b44182017-10-17 13:37:36 +0000762 for (Arg *DALArg : *DAL) {
Gheorghe-Teodor Berceaf0f29602017-07-06 16:22:21 +0000763 if (A == DALArg) {
764 IsDuplicate = true;
765 break;
766 }
767 }
768 if (!IsDuplicate)
769 DAL->append(A);
770 }
Gheorghe-Teodor Bercea47e0cf32017-08-07 15:39:11 +0000771
772 StringRef Arch = DAL->getLastArgValue(options::OPT_march_EQ);
Jonas Hahnfeld30b44182017-10-17 13:37:36 +0000773 if (Arch.empty())
774 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
775 CLANG_OPENMP_NVPTX_DEFAULT_ARCH);
Gheorghe-Teodor Bercea47e0cf32017-08-07 15:39:11 +0000776
Gheorghe-Teodor Berceaf0f29602017-07-06 16:22:21 +0000777 return DAL;
778 }
779
David L. Jonesf561aba2017-03-08 01:02:16 +0000780 for (Arg *A : Args) {
781 if (A->getOption().matches(options::OPT_Xarch__)) {
782 // Skip this argument unless the architecture matches BoundArch
783 if (BoundArch.empty() || A->getValue(0) != BoundArch)
784 continue;
785
786 unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(1));
787 unsigned Prev = Index;
788 std::unique_ptr<Arg> XarchArg(Opts.ParseOneArg(Args, Index));
789
790 // If the argument parsing failed or more than one argument was
791 // consumed, the -Xarch_ argument's parameter tried to consume
792 // extra arguments. Emit an error and ignore.
793 //
794 // We also want to disallow any options which would alter the
795 // driver behavior; that isn't going to work in our model. We
796 // use isDriverOption() as an approximation, although things
797 // like -O4 are going to slip through.
798 if (!XarchArg || Index > Prev + 1) {
799 getDriver().Diag(diag::err_drv_invalid_Xarch_argument_with_args)
800 << A->getAsString(Args);
801 continue;
802 } else if (XarchArg->getOption().hasFlag(options::DriverOption)) {
803 getDriver().Diag(diag::err_drv_invalid_Xarch_argument_isdriver)
804 << A->getAsString(Args);
805 continue;
806 }
807 XarchArg->setBaseArg(A);
808 A = XarchArg.release();
809 DAL->AddSynthesizedArg(A);
810 }
811 DAL->append(A);
812 }
813
814 if (!BoundArch.empty()) {
815 DAL->eraseArg(options::OPT_march_EQ);
816 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ), BoundArch);
817 }
818 return DAL;
819}
820
821Tool *CudaToolChain::buildAssembler() const {
822 return new tools::NVPTX::Assembler(*this);
823}
824
825Tool *CudaToolChain::buildLinker() const {
Gheorghe-Teodor Bercea2c926932017-08-08 14:33:05 +0000826 if (OK == Action::OFK_OpenMP)
827 return new tools::NVPTX::OpenMPLinker(*this);
David L. Jonesf561aba2017-03-08 01:02:16 +0000828 return new tools::NVPTX::Linker(*this);
829}
830
831void CudaToolChain::addClangWarningOptions(ArgStringList &CC1Args) const {
832 HostTC.addClangWarningOptions(CC1Args);
833}
834
835ToolChain::CXXStdlibType
836CudaToolChain::GetCXXStdlibType(const ArgList &Args) const {
837 return HostTC.GetCXXStdlibType(Args);
838}
839
840void CudaToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
841 ArgStringList &CC1Args) const {
842 HostTC.AddClangSystemIncludeArgs(DriverArgs, CC1Args);
843}
844
845void CudaToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &Args,
846 ArgStringList &CC1Args) const {
847 HostTC.AddClangCXXStdlibIncludeArgs(Args, CC1Args);
848}
849
850void CudaToolChain::AddIAMCUIncludeArgs(const ArgList &Args,
851 ArgStringList &CC1Args) const {
852 HostTC.AddIAMCUIncludeArgs(Args, CC1Args);
853}
854
855SanitizerMask CudaToolChain::getSupportedSanitizers() const {
856 // The CudaToolChain only supports sanitizers in the sense that it allows
857 // sanitizer arguments on the command line if they are supported by the host
858 // toolchain. The CudaToolChain will actually ignore any command line
859 // arguments for any of these "supported" sanitizers. That means that no
860 // sanitization of device code is actually supported at this time.
861 //
862 // This behavior is necessary because the host and device toolchains
863 // invocations often share the command line, so the device toolchain must
864 // tolerate flags meant only for the host toolchain.
865 return HostTC.getSupportedSanitizers();
866}
867
868VersionTuple CudaToolChain::computeMSVCVersion(const Driver *D,
869 const ArgList &Args) const {
870 return HostTC.computeMSVCVersion(D, Args);
871}