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 hasDotInstructions() const { return hasFeature(NVPTX::SM61); }
123 bool hasCLMAD() const {
124 return hasFeature(NVPTX::SM80) && hasFeature(NVPTX::PTX93);
125 }
126 // Cache hint SM/PTX version requirements
127 bool hasL1EvictionHint() const {
128 return hasFeature(NVPTX::SM70) && hasFeature(NVPTX::PTX74);
129 }
130 bool hasL2EvictionHint() const {
131 return hasFeature(NVPTX::SM100) && hasFeature(NVPTX::PTX88);
132 }
133 bool hasL2Prefetch64B() const {
134 return hasFeature(NVPTX::SM75) && hasFeature(NVPTX::PTX74);
135 }
136 bool hasL2Prefetch128B() const {
137 return hasFeature(NVPTX::SM75) && hasFeature(NVPTX::PTX74);
138 }
139 bool hasL2Prefetch256B() const {
140 return hasFeature(NVPTX::SM80) && hasFeature(NVPTX::PTX74);
141 }
142 bool hasL2CacheHint() const {
143 return hasFeature(NVPTX::SM80) && hasFeature(NVPTX::PTX74);
144 }
145
146 // Checks following instructions support:
147 // - tcgen05.ld/st
148 // - tcgen05.alloc/dealloc/relinquish
149 // - tcgen05.cp
150 // - tcgen05.fence/wait
151 // - tcgen05.commit
152 // - tcgen05.mma
154 return hasAnyFeature({NVPTX::SM100f, NVPTX::SM110f});
155 }
156
157 // f32x2 instructions in Blackwell family
158 bool hasF32x2Instructions() const;
159
161 return hasAnyFeature({NVPTX::SM100f, NVPTX::SM110f, NVPTX::SM120f}) ||
162 (hasFeature(NVPTX::PTX83) && hasAnyFeature({NVPTX::SM90a}));
163 }
164
165 bool hasTensormapReplaceElemtypeSupport(unsigned ElemType) const {
166 if (ElemType >= static_cast<unsigned>(nvvm::TensormapElemType::B4x16))
167 return (hasFeature(NVPTX::PTX88) &&
168 hasAnyFeature({NVPTX::SM100f, NVPTX::SM110f, NVPTX::SM120f})) ||
169 (hasFeature(NVPTX::PTX87) &&
170 hasAnyFeature({NVPTX::SM100a, NVPTX::SM110a, NVPTX::SM120a}));
171
173 }
174
175 bool hasTensormapReplaceSwizzleModeSupport(unsigned SwizzleMode) const {
176 if (SwizzleMode ==
177 static_cast<unsigned>(nvvm::TensormapSwizzleMode::SWIZZLE_96B))
178 return hasAnyFeature({NVPTX::SM103a});
179
181 }
182
183 // Prior to CUDA 12.3 ptxas did not recognize that the trap instruction
184 // terminates a basic block. Instead, it would assume that control flow
185 // continued to the next instruction. The next instruction could be in the
186 // block that's lexically below it. This would lead to a phantom CFG edges
187 // being created within ptxas. This issue was fixed in CUDA 12.3. Thus, when
188 // PTX ISA versions 8.3+ we can confidently say that the bug will not be
189 // present.
190 bool hasPTXASUnreachableBug() const { return !hasFeature(NVPTX::PTX83); }
191 bool hasCvtaParam() const {
192 return hasFeature(NVPTX::SM70) && hasFeature(NVPTX::PTX77);
193 }
194 // The compute capability as a number, for __CUDA_ARCH__. This is the one
195 // place an architecture needs to be a number, and it is not an identity:
196 // sm_100, sm_100f and sm_100a all report 100.
197 unsigned getSmVersion() const { return NVPTX::getSmVersion(Arch) / 10; }
198
199 // Whether -mcpu named a target at all, as opposed to falling back to the
200 // default architecture.
201 bool hasTargetName() const { return !getCPU().empty(); }
202
203 // The architecture's name, which is what `.target` is emitted from.
204 StringRef getTargetName() const;
205
206 bool hasNativeBF16Support(unsigned Opcode) const;
207
208 // Get maximum value of required alignments among the supported data types.
209 // From the PTX ISA doc, section 8.2.3:
210 // The memory consistency model relates operations executed on memory
211 // locations with scalar data-types, which have a maximum size and alignment
212 // of 64 bits. Memory operations with a vector data-type are modelled as a
213 // set of equivalent memory operations with a scalar data-type, executed in
214 // an unspecified order on the elements in the vector.
215 unsigned getMaxRequiredAlignment() const { return 8; }
216 // Get the smallest cmpxchg word size that the hardware supports.
217 unsigned getMinCmpXchgSizeInBits() const { return 32; }
218
219 unsigned getPTXVersion() const { return PTXVersion; }
220
223};
224
225} // namespace llvm
226
227#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 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