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::printTcgen05MMAKind(raw_ostream &OS, const Constant *ImmArgVal) {
53 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
54 uint64_t Val = CI->getZExtValue();
55 switch (static_cast<Tcgen05MMAKind>(Val)) {
57 OS << "f16";
58 return;
60 OS << "tf32";
61 return;
63 OS << "f8f6f4";
64 return;
66 OS << "i8";
67 return;
69 OS << "ti16";
70 return;
71 }
72 }
73}
74
76 const Constant *ImmArgVal) {
77 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
78 uint64_t Val = CI->getZExtValue();
79 switch (static_cast<Tcgen05CollectorUsageOp>(Val)) {
81 OS << "discard";
82 return;
84 OS << "lastuse";
85 return;
87 OS << "fill";
88 return;
90 OS << "use";
91 return;
92 }
93 }
94}
95
97 const Constant *ImmArgVal) {
98 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
99 uint64_t Val = CI->getZExtValue();
100 switch (static_cast<Tcgen05MMACollectorBBuffer>(Val)) {
102 OS << "b0";
103 return;
105 OS << "b1";
106 return;
108 OS << "b2";
109 return;
111 OS << "b3";
112 return;
113 }
114 }
115}
116
118 static constexpr StringRef TensormapElemTypes[] = {
119 "u8", "u16", "u32", "s32", "u64", "s64",
120 "f16", "f32", "f32.ftz", "f64", "bf16", "tf32",
121 "tf32.ftz", "b4x16", "b4x16_p64", "b6x16_p32"};
122 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
123 uint64_t Val = CI->getZExtValue();
124 if (Val <= static_cast<uint64_t>(nvvm::TensormapElemType::B6x16_p32)) {
125 OS << TensormapElemTypes[Val];
126 return;
127 }
128 }
129}
130
132 const Constant *ImmArgVal) {
133 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
134 uint64_t Val = CI->getZExtValue();
135 switch (static_cast<TensormapInterleaveLayout>(Val)) {
137 OS << "No interleave";
138 return;
140 OS << "16B interleave";
141 return;
143 OS << "32B interleave";
144 return;
145 }
146 }
147}
148
150 const Constant *ImmArgVal) {
151 static constexpr StringRef TensormapSwizzleModes[] = {
152 "No swizzling", "32B swizzling", "64B swizzling", "128B swizzling",
153 "96B swizzling"};
154 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
155 uint64_t Val = CI->getZExtValue();
156 if (Val <= static_cast<uint64_t>(nvvm::TensormapSwizzleMode::SWIZZLE_96B)) {
157 OS << TensormapSwizzleModes[Val];
158 return;
159 }
160 }
161}
162
164 const Constant *ImmArgVal) {
165 static constexpr StringRef TensormapSwizzleAtomicities[] = {
166 "16B", "32B", "32B + 8B flip", "64B"};
167 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
168 uint64_t Val = CI->getZExtValue();
169 if (Val <= static_cast<uint64_t>(
171 OS << TensormapSwizzleAtomicities[Val];
172 return;
173 }
174 }
175}
176
177void nvvm::printFPRoundingMode(raw_ostream &OS, const Constant *ImmArgVal) {
178 if (isa<ConstantInt>(ImmArgVal))
180}
181
183 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
184 uint64_t Val = CI->getZExtValue();
185 OS << (Val == static_cast<uint64_t>(TensormapFillMode::ZERO_FILL)
186 ? "Zero fill"
187 : "OOB-NaN fill");
188 return;
189 }
190}
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)
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 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