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
27#define GET_SUBTARGETINFO_HEADER
28#include "NVPTXGenSubtargetInfo.inc"
29
30namespace llvm {
31
33 virtual void anchor();
34
35 // PTX version x.y is represented as 10*x+y, e.g. 3.1 == 31
36 unsigned PTXVersion;
37
39
40 // Set by every architecture feature. Their bits are the point, so this is
41 // only here because a subtarget feature must name a field.
42 bool HasArchitecture = false;
43
44 NVPTXInstrInfo InstrInfo;
46 std::unique_ptr<const SelectionDAGTargetInfo> TSInfo;
47
48 // NVPTX does not have any call stack frame, but need a NVPTX specific
49 // FrameLowering class because TargetFrameLowering is abstract.
50 NVPTXFrameLowering FrameLowering;
51
52public:
53 /// This constructor initializes the data members to match that
54 /// of the specified module.
55 ///
56 NVPTXSubtarget(const Triple &TT, StringRef CPU, StringRef FS,
57 const NVPTXTargetMachine &TM);
58
59 ~NVPTXSubtarget() override;
60
61 const TargetFrameLowering *getFrameLowering() const override {
62 return &FrameLowering;
63 }
64 const NVPTXInstrInfo *getInstrInfo() const override { return &InstrInfo; }
65 const NVPTXRegisterInfo *getRegisterInfo() const override {
66 return &InstrInfo.getRegisterInfo();
67 }
68 const NVPTXTargetLowering *getTargetLowering() const override {
69 return &TLInfo;
70 }
71
73 return TSInfo.get();
74 }
75
76 // True when any of `Features` is enabled.
77 bool hasAnyFeature(ArrayRef<unsigned> Features) const {
78 return llvm::any_of(Features, [this](unsigned F) { return hasFeature(F); });
79 }
80
81 bool has256BitVectorLoadStore(unsigned AS) const {
82 return hasFeature(NVPTX::SM100) && hasFeature(NVPTX::PTX88) &&
84 }
86 return hasFeature(NVPTX::SM50) && hasFeature(NVPTX::PTX83);
87 }
88 bool hasAtomAddF64() const { return hasFeature(NVPTX::SM60); }
89 bool hasAtomScope() const { return hasFeature(NVPTX::SM60); }
90 bool hasAtomBitwise64() const { return hasFeature(NVPTX::SM32); }
91 bool hasAtomMinMax64() const { return hasFeature(NVPTX::SM32); }
92 bool hasAtomCas16() const {
93 return hasFeature(NVPTX::SM70) && hasFeature(NVPTX::PTX63);
94 }
95 bool hasAtomSwap128() const {
96 return hasFeature(NVPTX::SM90) && hasFeature(NVPTX::PTX83);
97 }
98 bool hasClusters() const { return hasFeature(NVPTX::SM90); }
99 bool hasLDG() const { return hasFeature(NVPTX::SM32); }
100 bool hasHWROT32() const { return hasFeature(NVPTX::SM32); }
101 bool hasBrx() const {
102 return hasFeature(NVPTX::SM30) && hasFeature(NVPTX::PTX60);
103 }
104 bool hasFP16Math() const { return hasFeature(NVPTX::SM53); }
105 bool hasBF16Math() const { return hasFeature(NVPTX::SM80); }
106 bool allowFP16Math() const;
107 bool hasMaskOperator() const { return hasFeature(NVPTX::PTX71); }
108 bool hasNoReturn() const {
109 return hasFeature(NVPTX::SM30) && hasFeature(NVPTX::PTX64);
110 }
111 // Does SM & PTX support memory orderings (weak and atomic: relaxed, acquire,
112 // release, acq_rel, sc) ?
113 bool hasMemoryOrdering() const { return hasFeature(NVPTX::SM70); }
114 // Does SM & PTX support .acquire and .release qualifiers for fence?
116 return hasFeature(NVPTX::SM90) && hasFeature(NVPTX::PTX86);
117 }
118 // Does SM & PTX support atomic relaxed MMIO operations ?
119 bool hasRelaxedMMIO() const {
120 return hasFeature(NVPTX::SM70) && hasFeature(NVPTX::PTX82);
121 }
122 bool hasLocalVolatile() const { return hasFeature(NVPTX::PTX91); }
123 bool hasDotInstructions() const { return hasFeature(NVPTX::SM61); }
124 bool hasCLMAD() const {
125 return hasFeature(NVPTX::SM80) && hasFeature(NVPTX::PTX93);
126 }
127 // Cache hint SM/PTX version requirements
128 bool hasL1EvictionHint() const {
129 return hasFeature(NVPTX::SM70) && hasFeature(NVPTX::PTX74);
130 }
131 bool hasL2EvictionHint() const {
132 return hasFeature(NVPTX::SM100) && hasFeature(NVPTX::PTX88);
133 }
134 bool hasL2Prefetch64B() const {
135 return hasFeature(NVPTX::SM75) && hasFeature(NVPTX::PTX74);
136 }
137 bool hasL2Prefetch128B() const {
138 return hasFeature(NVPTX::SM75) && hasFeature(NVPTX::PTX74);
139 }
140 bool hasL2Prefetch256B() const {
141 return hasFeature(NVPTX::SM80) && hasFeature(NVPTX::PTX74);
142 }
143 bool hasL2CacheHint() const {
144 return hasFeature(NVPTX::SM80) && hasFeature(NVPTX::PTX74);
145 }
146
147 // Checks following instructions support:
148 // - tcgen05.ld/st
149 // - tcgen05.alloc/dealloc/relinquish
150 // - tcgen05.cp
151 // - tcgen05.fence/wait
152 // - tcgen05.commit
153 // - tcgen05.mma
155 return hasAnyFeature({NVPTX::SM100f, NVPTX::SM110f});
156 }
157
158 // f32x2 instructions in Blackwell family
159 bool hasF32x2Instructions() const;
160
162 return hasAnyFeature({NVPTX::SM100f, NVPTX::SM110f, NVPTX::SM120f}) ||
163 (hasFeature(NVPTX::PTX83) && hasAnyFeature({NVPTX::SM90a}));
164 }
165
166 bool hasTensormapReplaceElemtypeSupport(unsigned ElemType) const {
167 if (ElemType >= static_cast<unsigned>(nvvm::TensormapElemType::B4x16))
168 return (hasFeature(NVPTX::PTX88) &&
169 hasAnyFeature({NVPTX::SM100f, NVPTX::SM110f, NVPTX::SM120f})) ||
170 (hasFeature(NVPTX::PTX87) &&
171 hasAnyFeature({NVPTX::SM100a, NVPTX::SM110a, NVPTX::SM120a}));
172
174 }
175
176 bool hasTensormapReplaceSwizzleModeSupport(unsigned SwizzleMode) const {
177 if (SwizzleMode ==
178 static_cast<unsigned>(nvvm::TensormapSwizzleMode::SWIZZLE_96B))
179 return hasAnyFeature({NVPTX::SM103a});
180
182 }
183
184 // Prior to CUDA 12.3 ptxas did not recognize that the trap instruction
185 // terminates a basic block. Instead, it would assume that control flow
186 // continued to the next instruction. The next instruction could be in the
187 // block that's lexically below it. This would lead to a phantom CFG edges
188 // being created within ptxas. This issue was fixed in CUDA 12.3. Thus, when
189 // PTX ISA versions 8.3+ we can confidently say that the bug will not be
190 // present.
191 bool hasPTXASUnreachableBug() const { return !hasFeature(NVPTX::PTX83); }
192 bool hasCvtaParam() const {
193 return hasFeature(NVPTX::SM70) && hasFeature(NVPTX::PTX77);
194 }
195 // The compute capability as a number, for __CUDA_ARCH__. This is the one
196 // place an architecture needs to be a number, and it is not an identity:
197 // sm_100, sm_100f and sm_100a all report 100.
198 unsigned getSmVersion() const { return NVPTX::getSmVersion(Arch) / 10; }
199
200 // Whether -mcpu named a target at all, as opposed to falling back to the
201 // default architecture.
202 bool hasTargetName() const { return !getCPU().empty(); }
203
204 // The architecture's name, which is what `.target` is emitted from.
205 StringRef getTargetName() const;
206
207 bool hasNativeBF16Support(unsigned Opcode) const;
208
209 // Get maximum value of required alignments among the supported data types.
210 // From the PTX ISA doc, section 8.2.3:
211 // The memory consistency model relates operations executed on memory
212 // locations with scalar data-types, which have a maximum size and alignment
213 // of 64 bits. Memory operations with a vector data-type are modelled as a
214 // set of equivalent memory operations with a scalar data-type, executed in
215 // an unspecified order on the elements in the vector.
216 unsigned getMaxRequiredAlignment() const { return 8; }
217 // Get the smallest cmpxchg word size that the hardware supports.
218 unsigned getMinCmpXchgSizeInBits() const { return 32; }
219
220 unsigned getPTXVersion() const { return PTXVersion; }
221
224};
225
226} // namespace llvm
227
228#endif
static bool hasFeature(StringRef Feature, const FeatureBitset &FeatureBits, ArrayRef< SubtargetFeatureKV > ProcFeatures)
#define F(x, y, z)
Definition MD5.cpp:54
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 hasTensormapReplaceSwizzleModeSupport(unsigned SwizzleMode) const
const SelectionDAGTargetInfo * getSelectionDAGInfo() const override
bool hasL2Prefetch256B() const
bool hasL2EvictionHint() const
unsigned getMaxRequiredAlignment() const
bool hasAtomMinMax64() const
bool hasTcgen05InstSupport() const
bool hasAtomAddF64() const
bool hasL2Prefetch64B() const
bool hasL2Prefetch128B() const
bool hasSplitAcquireAndReleaseFences() const
bool hasClusters() 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 hasCvtaParam() const
~NVPTXSubtarget() override
bool hasUsedBytesMaskPragma() const
const NVPTXRegisterInfo * getRegisterInfo() const override
bool hasTensormapReplaceSupport() const
bool hasDotInstructions() const
bool hasAtomBitwise64() 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