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