clang 22.0.0git
Cuda.h
Go to the documentation of this file.
1//===--- Cuda.h - Cuda 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#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_CUDA_H
10#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_CUDA_H
11
12#include "clang/Basic/Cuda.h"
13#include "clang/Driver/Action.h"
16#include "clang/Driver/Tool.h"
18#include "llvm/Support/Compiler.h"
19#include "llvm/Support/VersionTuple.h"
20#include <bitset>
21#include <set>
22#include <vector>
23
24namespace clang {
25namespace driver {
26namespace tools {
27namespace NVPTX {
28
29// Run ptxas, the NVPTX assembler.
30class LLVM_LIBRARY_VISIBILITY Assembler final : public Tool {
31public:
32 Assembler(const ToolChain &TC) : Tool("NVPTX::Assembler", "ptxas", TC) {}
33
34 bool hasIntegratedCPP() const override { return false; }
35
36 void ConstructJob(Compilation &C, const JobAction &JA,
37 const InputInfo &Output, const InputInfoList &Inputs,
38 const llvm::opt::ArgList &TCArgs,
39 const char *LinkingOutput) const override;
40};
41
42// Runs fatbinary, which combines GPU object files ("cubin" files) and/or PTX
43// assembly into a single output file.
44class LLVM_LIBRARY_VISIBILITY FatBinary : public Tool {
45public:
46 FatBinary(const ToolChain &TC) : Tool("NVPTX::Linker", "fatbinary", TC) {}
47
48 bool hasIntegratedCPP() const override { return false; }
49
50 void ConstructJob(Compilation &C, const JobAction &JA,
51 const InputInfo &Output, const InputInfoList &Inputs,
52 const llvm::opt::ArgList &TCArgs,
53 const char *LinkingOutput) const override;
54};
55
56// Runs nvlink, which links GPU object files ("cubin" files) into a single file.
57class LLVM_LIBRARY_VISIBILITY Linker final : public Tool {
58public:
59 Linker(const ToolChain &TC) : Tool("NVPTX::Linker", "nvlink", TC) {}
60
61 bool hasIntegratedCPP() const override { return false; }
62
63 void ConstructJob(Compilation &C, const JobAction &JA,
64 const InputInfo &Output, const InputInfoList &Inputs,
65 const llvm::opt::ArgList &TCArgs,
66 const char *LinkingOutput) const override;
67};
68
69void getNVPTXTargetFeatures(const Driver &D, const llvm::Triple &Triple,
70 const llvm::opt::ArgList &Args,
71 std::vector<StringRef> &Features);
72
73} // end namespace NVPTX
74} // end namespace tools
75
76namespace toolchains {
77
78class LLVM_LIBRARY_VISIBILITY NVPTXToolChain : public ToolChain {
79public:
80 NVPTXToolChain(const Driver &D, const llvm::Triple &Triple,
81 const llvm::Triple &HostTriple,
82 const llvm::opt::ArgList &Args);
83
84 NVPTXToolChain(const Driver &D, const llvm::Triple &Triple,
85 const llvm::opt::ArgList &Args);
86
87 llvm::opt::DerivedArgList *
88 TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
89 Action::OffloadKind DeviceOffloadKind) const override;
90
91 void
92 addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
93 llvm::opt::ArgStringList &CC1Args,
94 Action::OffloadKind DeviceOffloadKind) const override;
95
96 // Never try to use the integrated assembler with CUDA; always fork out to
97 // ptxas.
98 bool useIntegratedAs() const override { return false; }
99 bool isCrossCompiling() const override { return true; }
100 bool isPICDefault() const override { return false; }
101 bool isPIEDefault(const llvm::opt::ArgList &Args) const override {
102 return false;
103 }
104 bool HasNativeLLVMSupport() const override { return true; }
105 bool isPICDefaultForced() const override { return false; }
106 bool SupportsProfiling() const override { return false; }
107
108 bool IsMathErrnoDefault() const override { return false; }
109
110 bool supportsDebugInfoOption(const llvm::opt::Arg *A) const override;
111 void adjustDebugInfoKind(llvm::codegenoptions::DebugInfoKind &DebugInfoKind,
112 const llvm::opt::ArgList &Args) const override;
113
114 // NVPTX supports only DWARF2.
115 unsigned GetDefaultDwarfVersion() const override { return 2; }
116 unsigned getMaxDwarfVersion() const override { return 2; }
117
118 /// Uses nvptx-arch tool to get arch of the system GPU. Will return error
119 /// if unable to find one.
121 getSystemGPUArchs(const llvm::opt::ArgList &Args) const override;
122
124
125protected:
126 Tool *buildAssembler() const override; // ptxas.
127 Tool *buildLinker() const override; // nvlink.
128};
129
130class LLVM_LIBRARY_VISIBILITY CudaToolChain : public NVPTXToolChain {
131public:
132 CudaToolChain(const Driver &D, const llvm::Triple &Triple,
133 const ToolChain &HostTC, const llvm::opt::ArgList &Args);
134
135 const llvm::Triple *getAuxTriple() const override {
136 return &HostTC.getTriple();
137 }
138
139 bool HasNativeLLVMSupport() const override { return false; }
140
141 std::string getInputFilename(const InputInfo &Input) const override;
142
143 llvm::opt::DerivedArgList *
144 TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
145 Action::OffloadKind DeviceOffloadKind) const override;
146 void
147 addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
148 llvm::opt::ArgStringList &CC1Args,
149 Action::OffloadKind DeviceOffloadKind) const override;
150
151 llvm::DenormalMode getDefaultDenormalModeForType(
152 const llvm::opt::ArgList &DriverArgs, const JobAction &JA,
153 const llvm::fltSemantics *FPType = nullptr) const override;
154
155 void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,
156 llvm::opt::ArgStringList &CC1Args) const override;
157
158 void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const override;
159 CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
160 void
161 AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
162 llvm::opt::ArgStringList &CC1Args) const override;
163 void AddClangCXXStdlibIncludeArgs(
164 const llvm::opt::ArgList &Args,
165 llvm::opt::ArgStringList &CC1Args) const override;
166 void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs,
167 llvm::opt::ArgStringList &CC1Args) const override;
168
169 SanitizerMask getSupportedSanitizers() const override;
170
171 VersionTuple
172 computeMSVCVersion(const Driver *D,
173 const llvm::opt::ArgList &Args) const override;
174
176
177protected:
178 Tool *buildAssembler() const override; // ptxas
179 Tool *buildLinker() const override; // fatbinary (ok, not really a linker)
180};
181
182} // end namespace toolchains
183} // end namespace driver
184} // end namespace clang
185
186#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_CUDA_H
Compilation - A set of tasks to perform for a single driver invocation.
Definition Compilation.h:45
A class to find a viable CUDA installation.
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition Driver.h:99
InputInfo - Wrapper for information about an input source.
Definition InputInfo.h:22
ToolChain - Access to tools for a single platform.
Definition ToolChain.h:92
ToolChain(const Driver &D, const llvm::Triple &T, const llvm::opt::ArgList &Args)
Definition ToolChain.cpp:89
Tool - Information on a specific compilation tool.
Definition Tool.h:32
Tool(const char *Name, const char *ShortName, const ToolChain &TC)
Definition Tool.cpp:14
CudaToolChain(const Driver &D, const llvm::Triple &Triple, const ToolChain &HostTC, const llvm::opt::ArgList &Args)
CUDA toolchain.
Definition Cuda.cpp:838
Tool * buildLinker() const override
Definition Cuda.cpp:989
Tool * buildAssembler() const override
Definition Cuda.cpp:985
const llvm::Triple * getAuxTriple() const override
Get the toolchain's aux triple, if it has one.
Definition Cuda.h:135
bool HasNativeLLVMSupport() const override
HasNativeLTOLinker - Check whether the linker and related tools have native LLVM support.
Definition Cuda.h:139
unsigned getMaxDwarfVersion() const override
Definition Cuda.h:116
CudaInstallationDetector CudaInstallation
Definition Cuda.h:123
bool isPICDefault() const override
Test whether this toolchain defaults to PIC.
Definition Cuda.h:100
bool isCrossCompiling() const override
Returns true if the toolchain is targeting a non-native architecture.
Definition Cuda.h:99
Tool * buildAssembler() const override
Definition Cuda.cpp:977
Tool * buildLinker() const override
Definition Cuda.cpp:981
bool IsMathErrnoDefault() const override
IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
Definition Cuda.h:108
bool HasNativeLLVMSupport() const override
HasNativeLTOLinker - Check whether the linker and related tools have native LLVM support.
Definition Cuda.h:104
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
NVPTXToolChain(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
bool SupportsProfiling() const override
SupportsProfiling - Does this tool chain support -pg.
Definition Cuda.h:106
unsigned GetDefaultDwarfVersion() const override
Definition Cuda.h:115
bool useIntegratedAs() const override
Check if the toolchain should use the integrated assembler.
Definition Cuda.h:98
bool isPIEDefault(const llvm::opt::ArgList &Args) const override
Test whether this toolchain defaults to PIE.
Definition Cuda.h:101
NVPTXToolChain(const Driver &D, const llvm::Triple &Triple, const llvm::Triple &HostTriple, const llvm::opt::ArgList &Args)
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
bool isPICDefaultForced() const override
Tests whether this toolchain forces its default for PIC, PIE or non-PIC.
Definition Cuda.h:105
bool hasIntegratedCPP() const override
Definition Cuda.h:34
Assembler(const ToolChain &TC)
Definition Cuda.h:32
FatBinary(const ToolChain &TC)
Definition Cuda.h:46
bool hasIntegratedCPP() const override
Definition Cuda.h:48
Linker(const ToolChain &TC)
Definition Cuda.h:59
bool hasIntegratedCPP() const override
Definition Cuda.h:61
void getNVPTXTargetFeatures(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args, std::vector< StringRef > &Features)
Definition Cuda.cpp:665
SmallVector< InputInfo, 4 > InputInfoList
Definition Driver.h:50
The JSON file list parser is used to communicate input to InstallAPI.