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