LLVM 24.0.0git
NVVMIntrinsicUtils.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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 implements functions associated with NVVM Intrinsics.
10//
11//===----------------------------------------------------------------------===//
12
14#include "llvm/ADT/StringRef.h"
15
16using namespace llvm;
17using namespace nvvm;
18
19void nvvm::printEvictPolicyType(raw_ostream &OS, const Constant *ImmArgVal) {
20 const auto *CI = dyn_cast<ConstantInt>(ImmArgVal);
21 if (!CI ||
22 CI->getZExtValue() > static_cast<uint64_t>(EvictPolicyType::EVICT_LAST)) {
23 OS << "Unsupported evict policy";
24 return;
25 }
26 OS << getEvictPolicyName(static_cast<EvictPolicyType>(CI->getZExtValue()));
27}
28
29void nvvm::printTMAReductionOp(raw_ostream &OS, const Constant *ImmArgVal) {
30 const auto *CI = dyn_cast<ConstantInt>(ImmArgVal);
31 if (!CI || CI->getZExtValue() > static_cast<uint64_t>(TMAReductionOp::XOR))
33 "printTMAReductionOp called with invalid value for immediate argument");
34
36 static_cast<TMAReductionOp>(CI->getZExtValue()));
37}
38
40 const Constant *ImmArgVal) {
41 const auto *CI = dyn_cast<ConstantInt>(ImmArgVal);
42 if (!CI || CI->getZExtValue() > static_cast<uint64_t>(
44 OS << "Unknown validate data pattern";
45 return;
46 }
47
49 static_cast<TMAValidateDataPattern>(CI->getZExtValue()));
50}
51
52void nvvm::printMBarrierLayout(raw_ostream &OS, const Constant *ImmArgVal) {
53 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
54 switch (static_cast<MBarrierLayout>(CI->getZExtValue())) {
56 OS << "v0";
57 return;
59 OS << "v1";
60 return;
61 }
62 }
63}
64
65void nvvm::printCompareAndSetOp(raw_ostream &OS, const Constant *ImmArgVal) {
66 const auto *CI = dyn_cast<ConstantInt>(ImmArgVal);
67 const int64_t Val = CI ? CI->getSExtValue() : -1;
68 if (Val < static_cast<int64_t>(CompareAndSetOp::First) ||
69 Val > static_cast<int64_t>(CompareAndSetOp::Last)) {
70 OS << "Unsupported compare and set operator";
71 return;
72 }
73 OS << getCompareAndSetOpName(static_cast<CompareAndSetOp>(Val));
74}
75
76void nvvm::printMemScope(raw_ostream &OS, const Constant *ImmArgVal) {
77 const auto *CI = dyn_cast<ConstantInt>(ImmArgVal);
78 if (!CI || CI->getZExtValue() > static_cast<uint64_t>(MemScope::SYS)) {
79 OS << "Unknown memory scope";
80 return;
81 }
82
83 OS << getMemScopeName(static_cast<MemScope>(CI->getZExtValue()));
84}
85
86void nvvm::printTcgen05MMAKind(raw_ostream &OS, const Constant *ImmArgVal) {
87 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
88 uint64_t Val = CI->getZExtValue();
89 switch (static_cast<Tcgen05MMAKind>(Val)) {
91 OS << "f16";
92 return;
94 OS << "tf32";
95 return;
97 OS << "f8f6f4";
98 return;
100 OS << "i8";
101 return;
103 OS << "ti16";
104 return;
105 }
106 }
107}
108
110 const Constant *ImmArgVal) {
111 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
112 uint64_t Val = CI->getZExtValue();
113 switch (static_cast<Tcgen05CollectorUsageOp>(Val)) {
115 OS << "discard";
116 return;
118 OS << "lastuse";
119 return;
121 OS << "fill";
122 return;
124 OS << "use";
125 return;
126 }
127 }
128}
129
131 const Constant *ImmArgVal) {
132 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
133 uint64_t Val = CI->getZExtValue();
134 switch (static_cast<Tcgen05MMACollectorBBuffer>(Val)) {
136 OS << "b0";
137 return;
139 OS << "b1";
140 return;
142 OS << "b2";
143 return;
145 OS << "b3";
146 return;
147 }
148 }
149}
150
152 static constexpr StringRef TensormapElemTypes[] = {
153 "u8", "u16", "u32", "s32", "u64", "s64",
154 "f16", "f32", "f32.ftz", "f64", "bf16", "tf32",
155 "tf32.ftz", "b4x16", "b4x16_p64", "b6x16_p32"};
156 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
157 uint64_t Val = CI->getZExtValue();
158 if (Val <= static_cast<uint64_t>(nvvm::TensormapElemType::B6x16_p32)) {
159 OS << TensormapElemTypes[Val];
160 return;
161 }
162 }
163}
164
166 const Constant *ImmArgVal) {
167 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
168 uint64_t Val = CI->getZExtValue();
169 switch (static_cast<TensormapInterleaveLayout>(Val)) {
171 OS << "No interleave";
172 return;
174 OS << "16B interleave";
175 return;
177 OS << "32B interleave";
178 return;
179 }
180 }
181}
182
184 const Constant *ImmArgVal) {
185 static constexpr StringRef TensormapSwizzleModes[] = {
186 "No swizzling", "32B swizzling", "64B swizzling", "128B swizzling",
187 "96B swizzling"};
188 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
189 uint64_t Val = CI->getZExtValue();
190 if (Val <= static_cast<uint64_t>(nvvm::TensormapSwizzleMode::SWIZZLE_96B)) {
191 OS << TensormapSwizzleModes[Val];
192 return;
193 }
194 }
195}
196
198 const Constant *ImmArgVal) {
199 static constexpr StringRef TensormapSwizzleAtomicities[] = {
200 "16B", "32B", "32B + 8B flip", "64B"};
201 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
202 uint64_t Val = CI->getZExtValue();
203 if (Val <= static_cast<uint64_t>(
205 OS << TensormapSwizzleAtomicities[Val];
206 return;
207 }
208 }
209}
210
211void nvvm::printFPRoundingMode(raw_ostream &OS, const Constant *ImmArgVal) {
212 if (isa<ConstantInt>(ImmArgVal))
214}
215
217 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
218 uint64_t Val = CI->getZExtValue();
219 OS << (Val == static_cast<uint64_t>(TensormapFillMode::ZERO_FILL)
220 ? "Zero fill"
221 : "OOB-NaN fill");
222 return;
223 }
224}
225
227 const Constant *ImmArgVal) {
228 static constexpr StringRef TensormapAllocClasses[] = {"small", "large",
229 "same"};
230 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
231 uint64_t Val = CI->getZExtValue();
232 if (Val <= static_cast<uint64_t>(nvvm::TensormapAllocClass::SAME)) {
233 OS << TensormapAllocClasses[Val];
234 return;
235 }
236 }
237}
This file contains the definitions of the enumerations and flags associated with NVVM Intrinsics,...
This is an important base class in LLVM.
Definition Constant.h:44
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
APFloat::roundingMode GetRoundingModeFromImmArg(const Value *ImmArgVal)
LLVM_ABI void printTcgen05MMACollectorBBuffer(raw_ostream &OS, const Constant *ImmArgVal)
StringRef GetRoundingModeName(APFloat::roundingMode RM)
LLVM_ABI void printTensormapSwizzleMode(raw_ostream &OS, const Constant *ImmArgVal)
LLVM_ABI void printFPRoundingMode(raw_ostream &OS, const Constant *ImmArgVal)
LLVM_ABI void printTMAReductionOp(raw_ostream &OS, const Constant *ImmArgVal)
LLVM_ABI void printTMAValidateDataPattern(raw_ostream &OS, const Constant *ImmArgVal)
LLVM_ABI void printTensormapAllocClass(raw_ostream &OS, const Constant *ImmArgVal)
LLVM_ABI void printTensormapInterleaveLayout(raw_ostream &OS, const Constant *ImmArgVal)
LLVM_ABI void printTensormapSwizzleAtomicity(raw_ostream &OS, const Constant *ImmArgVal)
LLVM_ABI void printCompareAndSetOp(raw_ostream &OS, const Constant *ImmArgVal)
StringRef getTMATensorReductionOpName(TMAReductionOp Op)
LLVM_ABI void printMemScope(raw_ostream &OS, const Constant *ImmArgVal)
StringRef getTMAValidateDataPatternName(TMAValidateDataPattern Pattern)
LLVM_ABI void printTcgen05MMAKind(raw_ostream &OS, const Constant *ImmArgVal)
LLVM_ABI void printTcgen05CollectorUsageOp(raw_ostream &OS, const Constant *ImmArgVal)
LLVM_ABI void printEvictPolicyType(raw_ostream &OS, const Constant *ImmArgVal)
LLVM_ABI void printMBarrierLayout(raw_ostream &OS, const Constant *ImmArgVal)
LLVM_ABI void printTensormapFillMode(raw_ostream &OS, const Constant *ImmArgVal)
LLVM_ABI void printTensormapElemType(raw_ostream &OS, const Constant *ImmArgVal)
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547