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()) {
600 C.getDriver().Diag(diag::err_drv_offload_missing_gpu_arch)
601 << getToolChain().getArchName() << getShortName();
602 return;
603 }
604
605 CmdArgs.push_back("-arch");
606 CmdArgs.push_back(Args.MakeArgString(GPUArch));
607
608 if (Args.hasArg(options::OPT_ptxas_path_EQ))
609 CmdArgs.push_back(Args.MakeArgString(
610 "--pxtas-path=" + Args.getLastArgValue(options::OPT_ptxas_path_EQ)));
611
612 if (Args.hasArg(options::OPT_cuda_path_EQ))
613 CmdArgs.push_back(Args.MakeArgString(
614 "--cuda-path=" + Args.getLastArgValue(options::OPT_cuda_path_EQ)));
615
616 // Add paths specified in LIBRARY_PATH environment variable as -L options.
617 addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH");
618
619 // Add standard library search paths passed on the command line.
620 Args.AddAllArgs(CmdArgs, options::OPT_L);
621 getToolChain().AddFilePathLibArgs(Args, CmdArgs);
622 AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
623
624 if (C.getDriver().isUsingLTO())
625 addLTOOptions(getToolChain(), Args, CmdArgs, Output, Inputs[0],
626 C.getDriver().getLTOMode() == LTOK_Thin);
627
628 addGPULibraries(getToolChain(), Args, CmdArgs);
629
630 // Add paths for the default clang library path.
631 SmallString<256> DefaultLibPath =
632 llvm::sys::path::parent_path(TC.getDriver().Dir);
633 llvm::sys::path::append(DefaultLibPath, CLANG_INSTALL_LIBDIR_BASENAME);
634 CmdArgs.push_back(Args.MakeArgString(Twine("-L") + DefaultLibPath));
635
636 C.addCommand(std::make_unique<Command>(
637 JA, *this,
639 "--options-file"},
640 Args.MakeArgString(getToolChain().GetProgramPath("clang-nvlink-wrapper")),
641 CmdArgs, Inputs, Output));
642}
643
644void NVPTX::getNVPTXTargetFeatures(const Driver &D, const llvm::Triple &Triple,
645 const llvm::opt::ArgList &Args,
646 std::vector<StringRef> &Features) {
647 if (Args.hasArg(options::OPT_cuda_feature_EQ)) {
648 StringRef PtxFeature =
649 Args.getLastArgValue(options::OPT_cuda_feature_EQ, "+ptx42");
650 Features.push_back(Args.MakeArgString(PtxFeature));
651 return;
652 }
653 CudaInstallationDetector CudaInstallation(D, Triple, Args);
654
655 // New CUDA versions often introduce new instructions that are only supported
656 // by new PTX version, so we need to raise PTX level to enable them in NVPTX
657 // back-end.
658 const char *PtxFeature = nullptr;
659 switch (CudaInstallation.version()) {
660#define CASE_CUDA_VERSION(CUDA_VER, PTX_VER) \
661 case CudaVersion::CUDA_##CUDA_VER: \
662 PtxFeature = "+ptx" #PTX_VER; \
663 break;
664 CASE_CUDA_VERSION(125, 85);
665 CASE_CUDA_VERSION(124, 84);
666 CASE_CUDA_VERSION(123, 83);
667 CASE_CUDA_VERSION(122, 82);
668 CASE_CUDA_VERSION(121, 81);
669 CASE_CUDA_VERSION(120, 80);
670 CASE_CUDA_VERSION(118, 78);
671 CASE_CUDA_VERSION(117, 77);
672 CASE_CUDA_VERSION(116, 76);
673 CASE_CUDA_VERSION(115, 75);
674 CASE_CUDA_VERSION(114, 74);
675 CASE_CUDA_VERSION(113, 73);
676 CASE_CUDA_VERSION(112, 72);
677 CASE_CUDA_VERSION(111, 71);
678 CASE_CUDA_VERSION(110, 70);
679 CASE_CUDA_VERSION(102, 65);
680 CASE_CUDA_VERSION(101, 64);
681 CASE_CUDA_VERSION(100, 63);
682 CASE_CUDA_VERSION(92, 61);
683 CASE_CUDA_VERSION(91, 61);
684 CASE_CUDA_VERSION(90, 60);
685#undef CASE_CUDA_VERSION
686 default:
687 PtxFeature = "+ptx42";
688 }
689 Features.push_back(PtxFeature);
690}
691
692/// NVPTX toolchain. Our assembler is ptxas, and our linker is nvlink. This
693/// operates as a stand-alone version of the NVPTX tools without the host
694/// toolchain.
695NVPTXToolChain::NVPTXToolChain(const Driver &D, const llvm::Triple &Triple,
696 const llvm::Triple &HostTriple,
697 const ArgList &Args, bool Freestanding = false)
698 : ToolChain(D, Triple, Args), CudaInstallation(D, HostTriple, Args),
699 Freestanding(Freestanding) {
700 if (CudaInstallation.isValid())
701 getProgramPaths().push_back(std::string(CudaInstallation.getBinPath()));
702 // Lookup binaries into the driver directory, this is used to
703 // discover the 'nvptx-arch' executable.
704 getProgramPaths().push_back(getDriver().Dir);
705}
706
707/// We only need the host triple to locate the CUDA binary utilities, use the
708/// system's default triple if not provided.
709NVPTXToolChain::NVPTXToolChain(const Driver &D, const llvm::Triple &Triple,
710 const ArgList &Args)
711 : NVPTXToolChain(D, Triple, llvm::Triple(LLVM_HOST_TRIPLE), Args,
712 /*Freestanding=*/true) {}
713
714llvm::opt::DerivedArgList *
715NVPTXToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
716 StringRef BoundArch,
717 Action::OffloadKind OffloadKind) const {
718 DerivedArgList *DAL = ToolChain::TranslateArgs(Args, BoundArch, OffloadKind);
719 if (!DAL)
720 DAL = new DerivedArgList(Args.getBaseArgs());
721
722 const OptTable &Opts = getDriver().getOpts();
723
724 for (Arg *A : Args)
725 if (!llvm::is_contained(*DAL, A))
726 DAL->append(A);
727
728 if (!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) {
729 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
731 } else if (DAL->getLastArgValue(options::OPT_march_EQ) == "generic" &&
732 OffloadKind == Action::OFK_None) {
733 DAL->eraseArg(options::OPT_march_EQ);
734 } else if (DAL->getLastArgValue(options::OPT_march_EQ) == "native") {
735 auto GPUsOrErr = getSystemGPUArchs(Args);
736 if (!GPUsOrErr) {
737 getDriver().Diag(diag::err_drv_undetermined_gpu_arch)
738 << getArchName() << llvm::toString(GPUsOrErr.takeError()) << "-march";
739 } else {
740 if (GPUsOrErr->size() > 1)
741 getDriver().Diag(diag::warn_drv_multi_gpu_arch)
742 << getArchName() << llvm::join(*GPUsOrErr, ", ") << "-march";
743 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
744 Args.MakeArgString(GPUsOrErr->front()));
745 }
746 }
747
748 return DAL;
749}
750
752 const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
753 Action::OffloadKind DeviceOffloadingKind) const {
754 // If we are compiling with a standalone NVPTX toolchain we want to try to
755 // mimic a standard environment as much as possible. So we enable lowering
756 // ctor / dtor functions to global symbols that can be registered.
757 if (Freestanding)
758 CC1Args.append({"-mllvm", "--nvptx-lower-global-ctor-dtor"});
759}
760
761bool NVPTXToolChain::supportsDebugInfoOption(const llvm::opt::Arg *A) const {
762 const Option &O = A->getOption();
763 return (O.matches(options::OPT_gN_Group) &&
764 !O.matches(options::OPT_gmodules)) ||
765 O.matches(options::OPT_g_Flag) ||
766 O.matches(options::OPT_ggdbN_Group) || O.matches(options::OPT_ggdb) ||
767 O.matches(options::OPT_gdwarf) || O.matches(options::OPT_gdwarf_2) ||
768 O.matches(options::OPT_gdwarf_3) || O.matches(options::OPT_gdwarf_4) ||
769 O.matches(options::OPT_gdwarf_5) ||
770 O.matches(options::OPT_gcolumn_info);
771}
772
774 llvm::codegenoptions::DebugInfoKind &DebugInfoKind,
775 const ArgList &Args) const {
776 switch (mustEmitDebugInfo(Args)) {
777 case DisableDebugInfo:
778 DebugInfoKind = llvm::codegenoptions::NoDebugInfo;
779 break;
780 case DebugDirectivesOnly:
781 DebugInfoKind = llvm::codegenoptions::DebugDirectivesOnly;
782 break;
783 case EmitSameDebugInfoAsHost:
784 // Use same debug info level as the host.
785 break;
786 }
787}
788
790NVPTXToolChain::getSystemGPUArchs(const ArgList &Args) const {
791 // Detect NVIDIA GPUs availible on the system.
792 std::string Program;
793 if (Arg *A = Args.getLastArg(options::OPT_nvptx_arch_tool_EQ))
794 Program = A->getValue();
795 else
796 Program = GetProgramPath("nvptx-arch");
797
798 auto StdoutOrErr = executeToolChainProgram(Program, /*SecondsToWait=*/10);
799 if (!StdoutOrErr)
800 return StdoutOrErr.takeError();
801
803 for (StringRef Arch : llvm::split((*StdoutOrErr)->getBuffer(), "\n"))
804 if (!Arch.empty())
805 GPUArchs.push_back(Arch.str());
806
807 if (GPUArchs.empty())
808 return llvm::createStringError(std::error_code(),
809 "No NVIDIA GPU detected in the system");
810
811 return std::move(GPUArchs);
812}
813
814/// CUDA toolchain. Our assembler is ptxas, and our "linker" is fatbinary,
815/// which isn't properly a linker but nonetheless performs the step of stitching
816/// together object files from the assembler into a single blob.
817
818CudaToolChain::CudaToolChain(const Driver &D, const llvm::Triple &Triple,
819 const ToolChain &HostTC, const ArgList &Args)
820 : NVPTXToolChain(D, Triple, HostTC.getTriple(), Args), HostTC(HostTC) {}
821
823 const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
824 Action::OffloadKind DeviceOffloadingKind) const {
825 HostTC.addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadingKind);
826
827 StringRef GpuArch = DriverArgs.getLastArgValue(options::OPT_march_EQ);
828 assert(!GpuArch.empty() && "Must have an explicit GPU arch.");
829 assert((DeviceOffloadingKind == Action::OFK_OpenMP ||
830 DeviceOffloadingKind == Action::OFK_Cuda) &&
831 "Only OpenMP or CUDA offloading kinds are supported for NVIDIA GPUs.");
832
833 if (DeviceOffloadingKind == Action::OFK_Cuda) {
834 CC1Args.append(
835 {"-fcuda-is-device", "-mllvm", "-enable-memcpyopt-without-libcalls"});
836
837 // Unsized function arguments used for variadics were introduced in CUDA-9.0
838 // We still do not support generating code that actually uses variadic
839 // arguments yet, but we do need to allow parsing them as recent CUDA
840 // headers rely on that. https://github.com/llvm/llvm-project/issues/58410
842 CC1Args.push_back("-fcuda-allow-variadic-functions");
843 }
844
845 if (DriverArgs.hasArg(options::OPT_nogpulib))
846 return;
847
848 if (DeviceOffloadingKind == Action::OFK_OpenMP &&
849 DriverArgs.hasArg(options::OPT_S))
850 return;
851
852 std::string LibDeviceFile = CudaInstallation.getLibDeviceFile(GpuArch);
853 if (LibDeviceFile.empty()) {
854 getDriver().Diag(diag::err_drv_no_cuda_libdevice) << GpuArch;
855 return;
856 }
857
858 CC1Args.push_back("-mlink-builtin-bitcode");
859 CC1Args.push_back(DriverArgs.MakeArgString(LibDeviceFile));
860
861 clang::CudaVersion CudaInstallationVersion = CudaInstallation.version();
862
863 if (DriverArgs.hasFlag(options::OPT_fcuda_short_ptr,
864 options::OPT_fno_cuda_short_ptr, false))
865 CC1Args.append({"-mllvm", "--nvptx-short-ptr"});
866
867 if (CudaInstallationVersion >= CudaVersion::UNKNOWN)
868 CC1Args.push_back(
869 DriverArgs.MakeArgString(Twine("-target-sdk-version=") +
870 CudaVersionToString(CudaInstallationVersion)));
871
872 if (DeviceOffloadingKind == Action::OFK_OpenMP) {
873 if (CudaInstallationVersion < CudaVersion::CUDA_92) {
874 getDriver().Diag(
875 diag::err_drv_omp_offload_target_cuda_version_not_support)
876 << CudaVersionToString(CudaInstallationVersion);
877 return;
878 }
879
880 // Link the bitcode library late if we're using device LTO.
881 if (getDriver().isUsingLTO(/* IsOffload */ true))
882 return;
883
884 addOpenMPDeviceRTL(getDriver(), DriverArgs, CC1Args, GpuArch.str(),
885 getTriple(), HostTC);
886 }
887}
888
890 const llvm::opt::ArgList &DriverArgs, const JobAction &JA,
891 const llvm::fltSemantics *FPType) const {
893 if (FPType && FPType == &llvm::APFloat::IEEEsingle() &&
894 DriverArgs.hasFlag(options::OPT_fgpu_flush_denormals_to_zero,
895 options::OPT_fno_gpu_flush_denormals_to_zero, false))
896 return llvm::DenormalMode::getPreserveSign();
897 }
898
900 return llvm::DenormalMode::getIEEE();
901}
902
903void CudaToolChain::AddCudaIncludeArgs(const ArgList &DriverArgs,
904 ArgStringList &CC1Args) const {
905 // Check our CUDA version if we're going to include the CUDA headers.
906 if (!DriverArgs.hasArg(options::OPT_nogpuinc) &&
907 !DriverArgs.hasArg(options::OPT_no_cuda_version_check)) {
908 StringRef Arch = DriverArgs.getLastArgValue(options::OPT_march_EQ);
909 assert(!Arch.empty() && "Must have an explicit GPU arch.");
911 }
912 CudaInstallation.AddCudaIncludeArgs(DriverArgs, CC1Args);
913}
914
915std::string CudaToolChain::getInputFilename(const InputInfo &Input) const {
916 // Only object files are changed, for example assembly files keep their .s
917 // extensions. If the user requested device-only compilation don't change it.
918 if (Input.getType() != types::TY_Object || getDriver().offloadDeviceOnly())
919 return ToolChain::getInputFilename(Input);
920
921 return ToolChain::getInputFilename(Input);
922}
923
924llvm::opt::DerivedArgList *
925CudaToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
926 StringRef BoundArch,
927 Action::OffloadKind DeviceOffloadKind) const {
928 DerivedArgList *DAL =
929 HostTC.TranslateArgs(Args, BoundArch, DeviceOffloadKind);
930 if (!DAL)
931 DAL = new DerivedArgList(Args.getBaseArgs());
932
933 const OptTable &Opts = getDriver().getOpts();
934
935 // For OpenMP device offloading, append derived arguments. Make sure
936 // flags are not duplicated.
937 // Also append the compute capability.
938 if (DeviceOffloadKind == Action::OFK_OpenMP) {
939 for (Arg *A : Args)
940 if (!llvm::is_contained(*DAL, A))
941 DAL->append(A);
942
943 if (!DAL->hasArg(options::OPT_march_EQ)) {
944 StringRef Arch = BoundArch;
945 if (Arch.empty()) {
946 auto ArchsOrErr = getSystemGPUArchs(Args);
947 if (!ArchsOrErr) {
948 std::string ErrMsg =
949 llvm::formatv("{0}", llvm::fmt_consume(ArchsOrErr.takeError()));
950 getDriver().Diag(diag::err_drv_undetermined_gpu_arch)
951 << llvm::Triple::getArchTypeName(getArch()) << ErrMsg << "-march";
953 } else {
954 Arch = Args.MakeArgString(ArchsOrErr->front());
955 }
956 }
957 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ), Arch);
958 }
959
960 return DAL;
961 }
962
963 for (Arg *A : Args) {
964 // Make sure flags are not duplicated.
965 if (!llvm::is_contained(*DAL, A)) {
966 DAL->append(A);
967 }
968 }
969
970 if (!BoundArch.empty()) {
971 DAL->eraseArg(options::OPT_march_EQ);
972 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
973 BoundArch);
974 }
975 return DAL;
976}
977
979 return new tools::NVPTX::Assembler(*this);
980}
981
983 return new tools::NVPTX::Linker(*this);
984}
985
987 return new tools::NVPTX::Assembler(*this);
988}
989
991 return new tools::NVPTX::FatBinary(*this);
992}
993
994void CudaToolChain::addClangWarningOptions(ArgStringList &CC1Args) const {
996}
997
999CudaToolChain::GetCXXStdlibType(const ArgList &Args) const {
1000 return HostTC.GetCXXStdlibType(Args);
1001}
1002
1003void CudaToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
1004 ArgStringList &CC1Args) const {
1005 HostTC.AddClangSystemIncludeArgs(DriverArgs, CC1Args);
1006
1007 if (!DriverArgs.hasArg(options::OPT_nogpuinc) && CudaInstallation.isValid())
1008 CC1Args.append(
1009 {"-internal-isystem",
1010 DriverArgs.MakeArgString(CudaInstallation.getIncludePath())});
1011}
1012
1014 ArgStringList &CC1Args) const {
1015 HostTC.AddClangCXXStdlibIncludeArgs(Args, CC1Args);
1016}
1017
1018void CudaToolChain::AddIAMCUIncludeArgs(const ArgList &Args,
1019 ArgStringList &CC1Args) const {
1020 HostTC.AddIAMCUIncludeArgs(Args, CC1Args);
1021}
1022
1024 // The CudaToolChain only supports sanitizers in the sense that it allows
1025 // sanitizer arguments on the command line if they are supported by the host
1026 // toolchain. The CudaToolChain will actually ignore any command line
1027 // arguments for any of these "supported" sanitizers. That means that no
1028 // sanitization of device code is actually supported at this time.
1029 //
1030 // This behavior is necessary because the host and device toolchains
1031 // invocations often share the command line, so the device toolchain must
1032 // tolerate flags meant only for the host toolchain.
1034}
1035
1037 const ArgList &Args) const {
1038 return HostTC.computeMSVCVersion(D, Args);
1039}
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:1082
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:451
llvm::Triple::ArchType getArch() const
Definition: ToolChain.h:269
const Driver & getDriver() const
Definition: ToolChain.h:253
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:359
const llvm::Triple & getTriple() const
Definition: ToolChain.h:255
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:1250
virtual VersionTuple computeMSVCVersion(const Driver *D, const llvm::opt::ArgList &Args) const
On Windows, returns the MSVC compatibility version.
Definition: ToolChain.cpp:1424
virtual void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Add arguments to use MCU GCC toolchain includes.
Definition: ToolChain.cpp:1407
virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const
Definition: ToolChain.cpp:1154
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:1075
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:1070
virtual SanitizerMask getSupportedSanitizers() const
Return sanitizers which are available in this toolchain.
Definition: ToolChain.cpp:1371
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:915
void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add arguments to use system-specific CUDA includes.
Definition: Cuda.cpp:903
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:1013
void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const override
Add warning options that need to be passed to cc1 for this target.
Definition: Cuda.cpp:994
SanitizerMask getSupportedSanitizers() const override
Return sanitizers which are available in this toolchain.
Definition: Cuda.cpp:1023
void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add arguments to use MCU GCC toolchain includes.
Definition: Cuda.cpp:1018
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:822
VersionTuple computeMSVCVersion(const Driver *D, const llvm::opt::ArgList &Args) const override
On Windows, returns the MSVC compatibility version.
Definition: Cuda.cpp:1036
CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override
Definition: Cuda.cpp:999
CudaToolChain(const Driver &D, const llvm::Triple &Triple, const ToolChain &HostTC, const llvm::opt::ArgList &Args)
CUDA toolchain.
Definition: Cuda.cpp:818
Tool * buildLinker() const override
Definition: Cuda.cpp:990
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:1003
Tool * buildAssembler() const override
Definition: Cuda.cpp:986
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:889
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:925
CudaInstallationDetector CudaInstallation
Definition: Cuda.h:177
Tool * buildAssembler() const override
Definition: Cuda.cpp:978
Tool * buildLinker() const override
Definition: Cuda.cpp:982
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:715
bool supportsDebugInfoOption(const llvm::opt::Arg *A) const override
Does this toolchain supports given debug info option or not.
Definition: Cuda.cpp:761
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:790
void adjustDebugInfoKind(llvm::codegenoptions::DebugInfoKind &DebugInfoKind, const llvm::opt::ArgList &Args) const override
Adjust debug information kind considering all passed options.
Definition: Cuda.cpp:773
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:751
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:644
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
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30
#define true
Definition: stdbool.h:25