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::printMemScope(raw_ostream &OS, const Constant *ImmArgVal) {
66 const auto *CI = dyn_cast<ConstantInt>(ImmArgVal);
67 if (!CI || CI->getZExtValue() > static_cast<uint64_t>(MemScope::SYS)) {
68 OS << "Unknown memory scope";
69 return;
70 }
71
72 OS << getMemScopeName(static_cast<MemScope>(CI->getZExtValue()));
73}
74
75void nvvm::printTcgen05MMAKind(raw_ostream &OS, const Constant *ImmArgVal) {
76 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
77 uint64_t Val = CI->getZExtValue();
78 switch (static_cast<Tcgen05MMAKind>(Val)) {
80 OS << "f16";
81 return;
83 OS << "tf32";
84 return;
86 OS << "f8f6f4";
87 return;
89 OS << "i8";
90 return;
92 OS << "ti16";
93 return;
94 }
95 }
96}
97
99 const Constant *ImmArgVal) {
100 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
101 uint64_t Val = CI->getZExtValue();
102 switch (static_cast<Tcgen05CollectorUsageOp>(Val)) {
104 OS << "discard";
105 return;
107 OS << "lastuse";
108 return;
110 OS << "fill";
111 return;
113 OS << "use";
114 return;
115 }
116 }
117}
118
120 const Constant *ImmArgVal) {
121 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
122 uint64_t Val = CI->getZExtValue();
123 switch (static_cast<Tcgen05MMACollectorBBuffer>(Val)) {
125 OS << "b0";
126 return;
128 OS << "b1";
129 return;
131 OS << "b2";
132 return;
134 OS << "b3";
135 return;
136 }
137 }
138}
139
141 static constexpr StringRef TensormapElemTypes[] = {
142 "u8", "u16", "u32", "s32", "u64", "s64",
143 "f16", "f32", "f32.ftz", "f64", "bf16", "tf32",
144 "tf32.ftz", "b4x16", "b4x16_p64", "b6x16_p32"};
145 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
146 uint64_t Val = CI->getZExtValue();
147 if (Val <= static_cast<uint64_t>(nvvm::TensormapElemType::B6x16_p32)) {
148 OS << TensormapElemTypes[Val];
149 return;
150 }
151 }
152}
153
155 const Constant *ImmArgVal) {
156 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
157 uint64_t Val = CI->getZExtValue();
158 switch (static_cast<TensormapInterleaveLayout>(Val)) {
160 OS << "No interleave";
161 return;
163 OS << "16B interleave";
164 return;
166 OS << "32B interleave";
167 return;
168 }
169 }
170}
171
173 const Constant *ImmArgVal) {
174 static constexpr StringRef TensormapSwizzleModes[] = {
175 "No swizzling", "32B swizzling", "64B swizzling", "128B swizzling",
176 "96B swizzling"};
177 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
178 uint64_t Val = CI->getZExtValue();
179 if (Val <= static_cast<uint64_t>(nvvm::TensormapSwizzleMode::SWIZZLE_96B)) {
180 OS << TensormapSwizzleModes[Val];
181 return;
182 }
183 }
184}
185
187 const Constant *ImmArgVal) {
188 static constexpr StringRef TensormapSwizzleAtomicities[] = {
189 "16B", "32B", "32B + 8B flip", "64B"};
190 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
191 uint64_t Val = CI->getZExtValue();
192 if (Val <= static_cast<uint64_t>(
194 OS << TensormapSwizzleAtomicities[Val];
195 return;
196 }
197 }
198}
199
200void nvvm::printFPRoundingMode(raw_ostream &OS, const Constant *ImmArgVal) {
201 if (isa<ConstantInt>(ImmArgVal))
203}
204
206 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
207 uint64_t Val = CI->getZExtValue();
208 OS << (Val == static_cast<uint64_t>(TensormapFillMode::ZERO_FILL)
209 ? "Zero fill"
210 : "OOB-NaN fill");
211 return;
212 }
213}
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:43
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 printTensormapInterleaveLayout(raw_ostream &OS, const Constant *ImmArgVal)
LLVM_ABI void printTensormapSwizzleAtomicity(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