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