LLVM 22.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"
24#include <string>
25
26#define GET_SUBTARGETINFO_HEADER
27#include "NVPTXGenSubtargetInfo.inc"
28
29namespace llvm {
30
32 virtual void anchor();
33 std::string TargetName;
34
35 // PTX version x.y is represented as 10*x+y, e.g. 3.1 == 31
36 unsigned PTXVersion;
37
38 // Full SM version x.y is represented as 100*x+10*y+feature, e.g. 3.1 == 310
39 // sm_90a == 901
40 unsigned int FullSmVersion;
41
42 // SM version x.y is represented as 10*x+y, e.g. 3.1 == 31. Derived from
43 // FullSmVersion.
44 unsigned int SmVersion;
45
46 NVPTXInstrInfo InstrInfo;
48 std::unique_ptr<const SelectionDAGTargetInfo> TSInfo;
49
50 // NVPTX does not have any call stack frame, but need a NVPTX specific
51 // FrameLowering class because TargetFrameLowering is abstract.
52 NVPTXFrameLowering FrameLowering;
53
54public:
55 /// This constructor initializes the data members to match that
56 /// of the specified module.
57 ///
58 NVPTXSubtarget(const Triple &TT, const std::string &CPU,
59 const std::string &FS, const NVPTXTargetMachine &TM);
60
61 ~NVPTXSubtarget() override;
62
63 const TargetFrameLowering *getFrameLowering() const override {
64 return &FrameLowering;
65 }
66 const NVPTXInstrInfo *getInstrInfo() const override { return &InstrInfo; }
67 const NVPTXRegisterInfo *getRegisterInfo() const override {
68 return &InstrInfo.getRegisterInfo();
69 }
70 const NVPTXTargetLowering *getTargetLowering() const override {
71 return &TLInfo;
72 }
73
74 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override;
75
76 bool has256BitVectorLoadStore(unsigned AS) const {
77 return SmVersion >= 100 && PTXVersion >= 88 &&
79 }
80 bool hasAtomAddF64() const { return SmVersion >= 60; }
81 bool hasAtomScope() const { return SmVersion >= 60; }
82 bool hasAtomBitwise64() const { return SmVersion >= 32; }
83 bool hasAtomMinMax64() const { return SmVersion >= 32; }
84 bool hasAtomCas16() const { return SmVersion >= 70 && PTXVersion >= 63; }
85 bool hasAtomSwap128() const { return SmVersion >= 90 && PTXVersion >= 83; }
86 bool hasClusters() const { return SmVersion >= 90 && PTXVersion >= 78; }
87 bool hasLDG() const { return SmVersion >= 32; }
88 bool hasHWROT32() const { return SmVersion >= 32; }
89 bool hasFP16Math() const { return SmVersion >= 53; }
90 bool hasBF16Math() const { return SmVersion >= 80; }
91 bool allowFP16Math() const;
92 bool hasMaskOperator() const { return PTXVersion >= 71; }
93 bool hasNoReturn() const { return SmVersion >= 30 && PTXVersion >= 64; }
94 // Does SM & PTX support memory orderings (weak and atomic: relaxed, acquire,
95 // release, acq_rel, sc) ?
96 bool hasMemoryOrdering() const { return SmVersion >= 70 && PTXVersion >= 60; }
97 // Does SM & PTX support .acquire and .release qualifiers for fence?
99 return SmVersion >= 90 && PTXVersion >= 86;
100 }
101 // Does SM & PTX support atomic relaxed MMIO operations ?
102 bool hasRelaxedMMIO() const { return SmVersion >= 70 && PTXVersion >= 82; }
103 bool hasDotInstructions() const {
104 return SmVersion >= 61 && PTXVersion >= 50;
105 }
106 // Tcgen05 instructions in Blackwell family
108 bool HasTcgen05 = false;
109 switch (FullSmVersion) {
110 default:
111 break;
112 case 1003: // sm_100a
113 case 1013: // sm_101a
114 HasTcgen05 = true;
115 break;
116 }
117
118 return HasTcgen05 && PTXVersion >= 86;
119 }
120 // f32x2 instructions in Blackwell family
121 bool hasF32x2Instructions() const;
122
123 // TMA G2S copy with cta_group::1/2 support
125 // TODO: Update/tidy-up after the family-conditional support arrives
126 switch (FullSmVersion) {
127 case 1003:
128 case 1013:
129 return PTXVersion >= 86;
130 case 1033:
131 return PTXVersion >= 88;
132 default:
133 return false;
134 }
135 }
136
137 // Prior to CUDA 12.3 ptxas did not recognize that the trap instruction
138 // terminates a basic block. Instead, it would assume that control flow
139 // continued to the next instruction. The next instruction could be in the
140 // block that's lexically below it. This would lead to a phantom CFG edges
141 // being created within ptxas. This issue was fixed in CUDA 12.3. Thus, when
142 // PTX ISA versions 8.3+ we can confidently say that the bug will not be
143 // present.
144 bool hasPTXASUnreachableBug() const { return PTXVersion < 83; }
145 bool hasCvtaParam() const { return SmVersion >= 70 && PTXVersion >= 77; }
146 unsigned int getFullSmVersion() const { return FullSmVersion; }
147 unsigned int getSmVersion() const { return getFullSmVersion() / 10; }
148 // GPUs with "a" suffix have architecture-accelerated features that are
149 // supported on the specified architecture only, hence such targets do not
150 // follow the onion layer model. hasArchAccelFeatures() allows distinguishing
151 // such GPU variants from the base GPU architecture.
152 // - false represents non-accelerated architecture.
153 // - true represents architecture-accelerated variant.
154 bool hasArchAccelFeatures() const {
155 return (getFullSmVersion() & 1) && PTXVersion >= 80;
156 }
157 // GPUs with 'f' suffix have architecture-accelerated features which are
158 // portable across all future architectures under same SM major. For example,
159 // sm_100f features will work for sm_10X*f*/sm_10X*a* future architectures.
160 // - false represents non-family-specific architecture.
161 // - true represents family-specific variant.
163 return getFullSmVersion() % 10 == 2 ? PTXVersion >= 88
165 }
166 // If the user did not provide a target we default to the `sm_30` target.
167 std::string getTargetName() const {
168 return TargetName.empty() ? "sm_30" : TargetName;
169 }
170 bool hasTargetName() const { return !TargetName.empty(); }
171
172 bool hasNativeBF16Support(int Opcode) const;
173
174 // Get maximum value of required alignments among the supported data types.
175 // From the PTX ISA doc, section 8.2.3:
176 // The memory consistency model relates operations executed on memory
177 // locations with scalar data-types, which have a maximum size and alignment
178 // of 64 bits. Memory operations with a vector data-type are modelled as a
179 // set of equivalent memory operations with a scalar data-type, executed in
180 // an unspecified order on the elements in the vector.
181 unsigned getMaxRequiredAlignment() const { return 8; }
182 // Get the smallest cmpxchg word size that the hardware supports.
183 unsigned getMinCmpXchgSizeInBits() const { return 32; }
184
185 unsigned getPTXVersion() const { return PTXVersion; }
186
189
190 void failIfClustersUnsupported(std::string const &FailureMessage) const;
191};
192
193} // End llvm namespace
194
195#endif
NVPTX address space definition.
const NVPTXRegisterInfo & getRegisterInfo() const
bool hasCpAsyncBulkTensorCTAGroupSupport() const
const NVPTXInstrInfo * getInstrInfo() const override
void failIfClustersUnsupported(std::string const &FailureMessage) const
std::string getTargetName() const
unsigned getMaxRequiredAlignment() const
bool hasAtomMinMax64() const
bool hasAtomAddF64() const
bool hasHWROT32() const
bool hasSplitAcquireAndReleaseFences() const
bool hasClusters() 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 hasNativeBF16Support(int Opcode) const
const NVPTXRegisterInfo * getRegisterInfo() const override
unsigned int getFullSmVersion() const
unsigned int getSmVersion() const
bool hasDotInstructions() const
bool hasFamilySpecificFeatures() const
bool hasTcgen05Instructions() const
bool hasAtomBitwise64() const
bool hasRelaxedMMIO() const
bool hasTargetName() const
bool hasBF16Math() const
bool hasAtomSwap128() const
bool hasF32x2Instructions() const
bool allowFP16Math() const
const TargetFrameLowering * getFrameLowering() const override
bool hasAtomScope() const
bool hasAtomCas16() const
bool hasMemoryOrdering() const
bool hasArchAccelFeatures() const
NVPTXSubtarget & initializeSubtargetDependencies(StringRef CPU, StringRef FS)
const SelectionDAGTargetInfo * getSelectionDAGInfo() const override
bool has256BitVectorLoadStore(unsigned AS) const
bool hasPTXASUnreachableBug() const
bool hasFP16Math() const
bool hasNoReturn() const
Targets can subclass this to parameterize the SelectionDAG lowering and instruction selection process...
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
Information about stack frame layout on the target.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:47
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18