LLVM 24.0.0git
NVPTXSubtarget.h
Go to the documentation of this file.
1//=====-- NVPTXSubtarget.h - Define Subtarget for the NVPTX ---*- 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// This file declares the NVPTX specific subclass of TargetSubtarget.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_NVPTX_NVPTXSUBTARGET_H
14#define LLVM_LIB_TARGET_NVPTX_NVPTXSUBTARGET_H
15
16#include "NVPTX.h"
17#include "NVPTXFrameLowering.h"
18#include "NVPTXISelLowering.h"
19#include "NVPTXInstrInfo.h"
20#include "NVPTXRegisterInfo.h"
22#include "llvm/IR/DataLayout.h"
26#include <optional>
27
28#define OPTIONS_STRUCT_DECL
29#include "NVPTXOptions.inc"
30
31#define GET_SUBTARGETINFO_HEADER
32#include "NVPTXGenSubtargetInfo.inc"
33
34namespace llvm {
35
36class Function;
37class LLVMContext;
38class Module;
39
40const NVPTXOptions &getNVPTXOptions(const LLVMContext &C);
41const NVPTXOptions &getNVPTXOptions(const Module &M);
42const NVPTXOptions &getNVPTXOptions(const Function &F);
43
45 virtual void anchor();
46
47 const NVPTXOptions &CLOpts;
48
49 // PTX version x.y is represented as 10*x+y, e.g. 3.1 == 31
50 unsigned PTXVersion;
51
53
54 // Set by every architecture feature. Their bits are the point, so this is
55 // only here because a subtarget feature must name a field.
56 bool HasArchitecture = false;
57
58 NVPTXInstrInfo InstrInfo;
60 std::unique_ptr<const SelectionDAGTargetInfo> TSInfo;
61
62 // NVPTX does not have any call stack frame, but need a NVPTX specific
63 // FrameLowering class because TargetFrameLowering is abstract.
64 NVPTXFrameLowering FrameLowering;
65
66public:
67 /// This constructor initializes the data members to match that
68 /// of the specified module.
69 ///
70 NVPTXSubtarget(const Triple &TT, StringRef CPU, StringRef FS,
71 const NVPTXTargetMachine &TM);
72
73 ~NVPTXSubtarget() override;
74
75 const NVPTXOptions &getCLOpts() const { return CLOpts; }
76
77 const TargetFrameLowering *getFrameLowering() const override {
78 return &FrameLowering;
79 }
80 const NVPTXInstrInfo *getInstrInfo() const override { return &InstrInfo; }
81 const NVPTXRegisterInfo *getRegisterInfo() const override {
82 return &InstrInfo.getRegisterInfo();
83 }
84 const NVPTXTargetLowering *getTargetLowering() const override {
85 return &TLInfo;
86 }
87
89 return TSInfo.get();
90 }
91
92 // True when any of `Features` is enabled.
93 bool hasAnyFeature(ArrayRef<unsigned> Features) const {
94 return llvm::any_of(Features, [this](unsigned F) { return hasFeature(F); });
95 }
96
97 bool has256BitVectorLoadStore(unsigned AS) const {
98 return hasFeature(NVPTX::SM100) && hasFeature(NVPTX::PTX88) &&
100 }
102 return hasFeature(NVPTX::SM50) && hasFeature(NVPTX::PTX83);
103 }
104 bool hasABIPreserve() const {
105 return hasFeature(NVPTX::SM80) && hasFeature(NVPTX::PTX90);
106 }
107 bool hasAtomAddF64() const { return hasFeature(NVPTX::SM60); }
108 bool hasAtomScope() const { return hasFeature(NVPTX::SM60); }
109 bool hasAtomMinMaxAndOrXor() const { return hasFeature(NVPTX::SM32); }
110 bool hasAtomCas16() const {
111 return hasFeature(NVPTX::SM70) && hasFeature(NVPTX::PTX63);
112 }
113 bool hasAtomSwap128() const {
114 return hasFeature(NVPTX::SM90) && hasFeature(NVPTX::PTX83);
115 }
116 bool hasLdStB128() const {
117 return hasFeature(NVPTX::SM70) && hasFeature(NVPTX::PTX83);
118 }
119 bool hasSysScopeLdStB128() const {
120 return hasLdStB128() && hasFeature(NVPTX::PTX84);
121 }
122 bool hasClusters() const { return hasFeature(NVPTX::SM90); }
123 bool hasLDG() const { return hasFeature(NVPTX::SM32); }
124 bool hasHWROT32() const { return hasFeature(NVPTX::SM32); }
125 bool hasBrx() const {
126 return hasFeature(NVPTX::SM30) && hasFeature(NVPTX::PTX60);
127 }
128 bool hasFP16Math() const { return hasFeature(NVPTX::SM53); }
129 bool hasBF16Math() const { return hasFeature(NVPTX::SM80); }
130 bool allowFP16Math() const;
131 bool hasMaskOperator() const { return hasFeature(NVPTX::PTX71); }
132 bool hasNoReturn() const {
133 return hasFeature(NVPTX::SM30) && hasFeature(NVPTX::PTX64);
134 }
135 // Does SM & PTX support memory orderings (weak and atomic: relaxed, acquire,
136 // release, acq_rel, sc) ?
137 bool hasMemoryOrdering() const { return hasFeature(NVPTX::SM70); }
138 // Does SM & PTX support .acquire and .release qualifiers for fence?
140 return hasFeature(NVPTX::SM90) && hasFeature(NVPTX::PTX86);
141 }
142 // Does SM & PTX support atomic relaxed MMIO operations ?
143 bool hasRelaxedMMIO() const {
144 return hasFeature(NVPTX::SM70) && hasFeature(NVPTX::PTX82);
145 }
146 bool hasLocalVolatile() const { return hasFeature(NVPTX::PTX91); }
147 bool hasDotInstructions() const { return hasFeature(NVPTX::SM61); }
148 bool hasCLMAD() const {
149 return hasFeature(NVPTX::SM80) && hasFeature(NVPTX::PTX93);
150 }
151 // Cache hint SM/PTX version requirements
152 bool hasL1EvictionHint() const {
153 return hasFeature(NVPTX::SM70) && hasFeature(NVPTX::PTX74);
154 }
155 bool hasL2EvictionHint() const {
156 return hasFeature(NVPTX::SM100) && hasFeature(NVPTX::PTX88);
157 }
158 bool hasL2Prefetch64B() const {
159 return hasFeature(NVPTX::SM75) && hasFeature(NVPTX::PTX74);
160 }
161 bool hasL2Prefetch128B() const {
162 return hasFeature(NVPTX::SM75) && hasFeature(NVPTX::PTX74);
163 }
164 bool hasL2Prefetch256B() const {
165 return hasFeature(NVPTX::SM80) && hasFeature(NVPTX::PTX74);
166 }
167 bool hasL2CacheHint() const {
168 return hasFeature(NVPTX::SM80) && hasFeature(NVPTX::PTX74);
169 }
170
171 // Checks following instructions support:
172 // - tcgen05.ld/st
173 // - tcgen05.alloc/dealloc/relinquish
174 // - tcgen05.cp
175 // - tcgen05.fence/wait
176 // - tcgen05.commit
177 // - tcgen05.mma
179 return hasAnyFeature({NVPTX::SM100f, NVPTX::SM110f});
180 }
181
182 // f32x2 instructions in Blackwell family
183 bool hasF32x2Instructions() const;
184
186 return hasAnyFeature({NVPTX::SM100f, NVPTX::SM110f, NVPTX::SM120f}) ||
187 (hasFeature(NVPTX::PTX83) && hasAnyFeature({NVPTX::SM90a}));
188 }
189
190 bool hasTensormapReplaceElemtypeSupport(unsigned ElemType) const {
191 if (ElemType >= static_cast<unsigned>(nvvm::TensormapElemType::B4x16))
192 return (hasFeature(NVPTX::PTX88) &&
193 hasAnyFeature({NVPTX::SM100f, NVPTX::SM110f, NVPTX::SM120f})) ||
194 (hasFeature(NVPTX::PTX87) &&
195 hasAnyFeature({NVPTX::SM100a, NVPTX::SM110a, NVPTX::SM120a}));
196
198 }
199
200 bool hasTensormapReplaceSwizzleModeSupport(unsigned SwizzleMode) const {
201 if (SwizzleMode ==
202 static_cast<unsigned>(nvvm::TensormapSwizzleMode::SWIZZLE_96B))
203 return hasAnyFeature({NVPTX::SM103a});
204
206 }
207
208 // Prior to CUDA 12.3 ptxas did not recognize that the trap instruction
209 // terminates a basic block. Instead, it would assume that control flow
210 // continued to the next instruction. The next instruction could be in the
211 // block that's lexically below it. This would lead to a phantom CFG edges
212 // being created within ptxas. This issue was fixed in CUDA 12.3. Thus, when
213 // PTX ISA versions 8.3+ we can confidently say that the bug will not be
214 // present.
215 bool hasPTXASUnreachableBug() const { return !hasFeature(NVPTX::PTX83); }
216 bool hasCvtaParam() const {
217 return hasFeature(NVPTX::SM70) && hasFeature(NVPTX::PTX77);
218 }
219 // The compute capability as a number, for __CUDA_ARCH__. This is the one
220 // place an architecture needs to be a number, and it is not an identity:
221 // sm_100, sm_100f and sm_100a all report 100.
222 unsigned getSmVersion() const { return NVPTX::getSmVersion(Arch) / 10; }
223
224 // Whether -mcpu named a target at all, as opposed to falling back to the
225 // default architecture.
226 bool hasTargetName() const { return !getCPU().empty(); }
227
228 // The architecture's name, which is what `.target` is emitted from.
229 StringRef getTargetName() const;
230
231 bool hasNativeBF16Support(unsigned Opcode) const;
232
233 // Get maximum value of required alignments among the supported data types.
234 // From the PTX ISA doc, section 8.2.3:
235 // The memory consistency model relates operations executed on memory
236 // locations with scalar data-types, which have a maximum size and alignment
237 // of 64 bits. Memory operations with a vector data-type are modelled as a
238 // set of equivalent memory operations with a scalar data-type, executed in
239 // an unspecified order on the elements in the vector.
240 unsigned getMaxRequiredAlignment() const { return 8; }
241 // Get the smallest cmpxchg word size that the hardware supports.
242 unsigned getMinCmpXchgSizeInBits() const { return 32; }
243
244 unsigned getPTXVersion() const { return PTXVersion; }
245
248};
249
250} // namespace llvm
251
252#endif
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static bool hasFeature(StringRef Feature, const FeatureBitset &FeatureBits, ArrayRef< SubtargetFeatureKV > ProcFeatures)
#define F(x, y, z)
Definition MD5.cpp:54
Machine Check Debug Module
NVPTX address space definition.
This file contains the definitions of the enumerations and flags associated with NVVM Intrinsics,...
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
bool hasTensormapReplaceElemtypeSupport(unsigned ElemType) const
const NVPTXInstrInfo * getInstrInfo() const override
bool hasAtomMinMaxAndOrXor() const
bool hasSysScopeLdStB128() const
bool hasTensormapReplaceSwizzleModeSupport(unsigned SwizzleMode) const
const NVPTXOptions & getCLOpts() const
const SelectionDAGTargetInfo * getSelectionDAGInfo() const override
bool hasL2Prefetch256B() const
bool hasL2EvictionHint() const
unsigned getMaxRequiredAlignment() const
bool hasTcgen05InstSupport() const
bool hasAtomAddF64() const
bool hasL2Prefetch64B() const
bool hasL2Prefetch128B() const
bool hasSplitAcquireAndReleaseFences() const
bool hasNativeBF16Support(unsigned Opcode) const
StringRef getTargetName() const
bool hasL1EvictionHint() const
bool hasMaskOperator() const
const NVPTXTargetLowering * getTargetLowering() const override
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS)
unsigned getMinCmpXchgSizeInBits() const
unsigned getPTXVersion() const
bool hasABIPreserve() const
bool hasCvtaParam() const
~NVPTXSubtarget() override
bool hasUsedBytesMaskPragma() const
const NVPTXRegisterInfo * getRegisterInfo() const override
bool hasTensormapReplaceSupport() const
bool hasDotInstructions() const
bool hasRelaxedMMIO() const
bool hasTargetName() const
bool hasAtomSwap128() const
bool hasF32x2Instructions() const
const TargetFrameLowering * getFrameLowering() const override
bool hasAtomScope() const
bool hasL2CacheHint() const
unsigned getSmVersion() const
bool hasLocalVolatile() const
bool hasAnyFeature(ArrayRef< unsigned > Features) const
bool hasAtomCas16() const
bool hasMemoryOrdering() const
NVPTXSubtarget & initializeSubtargetDependencies(StringRef CPU, StringRef FS)
bool has256BitVectorLoadStore(unsigned AS) const
NVPTXSubtarget(const Triple &TT, StringRef CPU, StringRef FS, const NVPTXTargetMachine &TM)
This constructor initializes the data members to match that of the specified module.
bool hasPTXASUnreachableBug() const
Targets can subclass this to parameterize the SelectionDAG lowering and instruction selection process...
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
Information about stack frame layout on the target.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
GPUKind
GPU kinds supported by the NVPTX target.
LLVM_ABI unsigned getSmVersion(GPUKind Kind)
Return the numeric compute-capability id (e.g.
This is an optimization pass for GlobalISel generic memory operations.
static StringRef getCPU(StringRef CPU)
Processes a CPU name.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1762
const NVPTXOptions & getNVPTXOptions(const LLVMContext &C)