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