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