clang 23.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 llvm::StringRef BoundArch,
95 Action::OffloadKind DeviceOffloadKind) const override;
96 void
97 AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
98 llvm::opt::ArgStringList &CC1Args) const override;
99
100 // Never try to use the integrated assembler with CUDA; always fork out to
101 // ptxas.
102 bool useIntegratedAs() const override { return false; }
103 bool isCrossCompiling() const override { return true; }
104 bool isPICDefault() const override { return false; }
105 bool isPIEDefault(const llvm::opt::ArgList &Args) const override {
106 return false;
107 }
108 bool HasNativeLLVMSupport() const override { return true; }
109 bool isPICDefaultForced() const override { return false; }
110 bool SupportsProfiling() const override { return false; }
111
112 bool IsMathErrnoDefault() const override { return false; }
113
114 bool supportsDebugInfoOption(const llvm::opt::Arg *A) const override;
115 void adjustDebugInfoKind(llvm::codegenoptions::DebugInfoKind &DebugInfoKind,
116 const llvm::opt::ArgList &Args) const override;
117
118 // NVPTX supports only DWARF2.
119 unsigned GetDefaultDwarfVersion() const override { return 2; }
120 unsigned getMaxDwarfVersion() const override { return 2; }
121
122 /// Uses nvptx-arch tool to get arch of the system GPU. Will return error
123 /// if unable to find one.
125 getSystemGPUArchs(const llvm::opt::ArgList &Args) const override;
126
128
129protected:
130 Tool *buildAssembler() const override; // ptxas.
131 Tool *buildLinker() const override; // nvlink.
132};
133
134class LLVM_LIBRARY_VISIBILITY CudaToolChain : public NVPTXToolChain {
135public:
136 CudaToolChain(const Driver &D, const llvm::Triple &Triple,
137 const ToolChain &HostTC, const llvm::opt::ArgList &Args);
138
139 const llvm::Triple *getAuxTriple() const override {
140 return &HostTC.getTriple();
141 }
142
143 bool HasNativeLLVMSupport() const override { return false; }
144
145 std::string getInputFilename(const InputInfo &Input) const override;
146
147 llvm::opt::DerivedArgList *
148 TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
149 Action::OffloadKind DeviceOffloadKind) const override;
150 void
151 addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
152 llvm::opt::ArgStringList &CC1Args,
153 llvm::StringRef BoundArch,
154 Action::OffloadKind DeviceOffloadKind) const override;
155
156 llvm::DenormalMode getDefaultDenormalModeForType(
157 const llvm::opt::ArgList &DriverArgs, const JobAction &JA,
158 const llvm::fltSemantics *FPType = nullptr) const override;
159
160 void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,
161 llvm::opt::ArgStringList &CC1Args) const override;
162
163 void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const override;
164 CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
165 void
166 AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
167 llvm::opt::ArgStringList &CC1Args) const override;
168 void AddClangCXXStdlibIncludeArgs(
169 const llvm::opt::ArgList &Args,
170 llvm::opt::ArgStringList &CC1Args) const override;
171 void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs,
172 llvm::opt::ArgStringList &CC1Args) const override;
173
175 getSupportedSanitizers(StringRef BoundArch,
176 Action::OffloadKind DeviceOffloadKind) const override;
177
178 VersionTuple
179 computeMSVCVersion(const Driver *D,
180 const llvm::opt::ArgList &Args) const override;
181
183
184protected:
185 Tool *buildAssembler() const override; // ptxas
186 Tool *buildLinker() const override; // fatbinary (ok, not really a linker)
187};
188
189} // end namespace toolchains
190} // end namespace driver
191} // end namespace clang
192
193#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:94
InputInfo - Wrapper for information about an input source.
Definition InputInfo.h:22
ToolChain - Access to tools for a single platform.
Definition ToolChain.h:95
ToolChain(const Driver &D, const llvm::Triple &T, const llvm::opt::ArgList &Args)
Definition ToolChain.cpp:91
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:881
Tool * buildLinker() const override
Definition Cuda.cpp:1026
Tool * buildAssembler() const override
Definition Cuda.cpp:1022
const llvm::Triple * getAuxTriple() const override
Get the toolchain's aux triple, if it has one.
Definition Cuda.h:139
bool HasNativeLLVMSupport() const override
HasNativeLTOLinker - Check whether the linker and related tools have native LLVM support.
Definition Cuda.h:143
unsigned getMaxDwarfVersion() const override
Definition Cuda.h:120
CudaInstallationDetector CudaInstallation
Definition Cuda.h:127
bool isPICDefault() const override
Test whether this toolchain defaults to PIC.
Definition Cuda.h:104
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:802
bool isCrossCompiling() const override
Returns true if the toolchain is targeting a non-native architecture.
Definition Cuda.h:103
Tool * buildAssembler() const override
Definition Cuda.cpp:1014
Tool * buildLinker() const override
Definition Cuda.cpp:1018
bool IsMathErrnoDefault() const override
IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
Definition Cuda.h:112
void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, llvm::StringRef BoundArch, Action::OffloadKind DeviceOffloadKind) const override
Add options that need to be passed to cc1 for this target.
Definition Cuda.cpp:797
bool HasNativeLLVMSupport() const override
HasNativeLTOLinker - Check whether the linker and related tools have native LLVM support.
Definition Cuda.h:108
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:760
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:110
unsigned GetDefaultDwarfVersion() const override
Definition Cuda.h:119
bool useIntegratedAs() const override
Check if the toolchain should use the integrated assembler.
Definition Cuda.h:102
bool isPIEDefault(const llvm::opt::ArgList &Args) const override
Test whether this toolchain defaults to PIE.
Definition Cuda.h:105
NVPTXToolChain(const Driver &D, const llvm::Triple &Triple, const llvm::Triple &HostTriple, const llvm::opt::ArgList &Args)
bool isPICDefaultForced() const override
Tests whether this toolchain forces its default for PIC, PIE or non-PIC.
Definition Cuda.h:109
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:675
SmallVector< InputInfo, 4 > InputInfoList
Definition Driver.h:50
The JSON file list parser is used to communicate input to InstallAPI.