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