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::printTMAReductionOp(raw_ostream &OS, const Constant *ImmArgVal) {
20 const auto *CI = dyn_cast<ConstantInt>(ImmArgVal);
21 if (!CI || CI->getZExtValue() > static_cast<uint64_t>(TMAReductionOp::XOR))
23 "printTMAReductionOp called with invalid value for immediate argument");
24
26 static_cast<TMAReductionOp>(CI->getZExtValue()));
27}
28
29void nvvm::printTcgen05MMAKind(raw_ostream &OS, const Constant *ImmArgVal) {
30 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
31 uint64_t Val = CI->getZExtValue();
32 switch (static_cast<Tcgen05MMAKind>(Val)) {
34 OS << "f16";
35 return;
37 OS << "tf32";
38 return;
40 OS << "f8f6f4";
41 return;
43 OS << "i8";
44 return;
46 OS << "ti16";
47 return;
48 }
49 }
50}
51
53 const Constant *ImmArgVal) {
54 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
55 uint64_t Val = CI->getZExtValue();
56 switch (static_cast<Tcgen05CollectorUsageOp>(Val)) {
58 OS << "discard";
59 return;
61 OS << "lastuse";
62 return;
64 OS << "fill";
65 return;
67 OS << "use";
68 return;
69 }
70 }
71}
72
74 const Constant *ImmArgVal) {
75 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
76 uint64_t Val = CI->getZExtValue();
77 switch (static_cast<Tcgen05MMACollectorBBuffer>(Val)) {
79 OS << "b0";
80 return;
82 OS << "b1";
83 return;
85 OS << "b2";
86 return;
88 OS << "b3";
89 return;
90 }
91 }
92}
93
95 static constexpr StringRef TensormapElemTypes[] = {
96 "u8", "u16", "u32", "s32", "u64", "s64",
97 "f16", "f32", "f32.ftz", "f64", "bf16", "tf32",
98 "tf32.ftz", "b4x16", "b4x16_p64", "b6x16_p32"};
99 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
100 uint64_t Val = CI->getZExtValue();
101 if (Val <= static_cast<uint64_t>(nvvm::TensormapElemType::B6x16_p32)) {
102 OS << TensormapElemTypes[Val];
103 return;
104 }
105 }
106}
107
109 const Constant *ImmArgVal) {
110 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
111 uint64_t Val = CI->getZExtValue();
112 switch (static_cast<TensormapInterleaveLayout>(Val)) {
114 OS << "No interleave";
115 return;
117 OS << "16B interleave";
118 return;
120 OS << "32B interleave";
121 return;
122 }
123 }
124}
125
127 const Constant *ImmArgVal) {
128 static constexpr StringRef TensormapSwizzleModes[] = {
129 "No swizzling", "32B swizzling", "64B swizzling", "128B swizzling",
130 "96B swizzling"};
131 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
132 uint64_t Val = CI->getZExtValue();
133 if (Val <= static_cast<uint64_t>(nvvm::TensormapSwizzleMode::SWIZZLE_96B)) {
134 OS << TensormapSwizzleModes[Val];
135 return;
136 }
137 }
138}
139
141 const Constant *ImmArgVal) {
142 static constexpr StringRef TensormapSwizzleAtomicities[] = {
143 "16B", "32B", "32B + 8B flip", "64B"};
144 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
145 uint64_t Val = CI->getZExtValue();
146 if (Val <= static_cast<uint64_t>(
148 OS << TensormapSwizzleAtomicities[Val];
149 return;
150 }
151 }
152}
153
155 if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
156 uint64_t Val = CI->getZExtValue();
157 OS << (Val == static_cast<uint64_t>(TensormapFillMode::ZERO_FILL)
158 ? "Zero fill"
159 : "OOB-NaN fill");
160 return;
161 }
162}
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.
LLVM_ABI void printTcgen05MMACollectorBBuffer(raw_ostream &OS, const Constant *ImmArgVal)
LLVM_ABI void printTensormapSwizzleMode(raw_ostream &OS, const Constant *ImmArgVal)
LLVM_ABI void printTMAReductionOp(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 printTcgen05MMAKind(raw_ostream &OS, const Constant *ImmArgVal)
LLVM_ABI void printTcgen05CollectorUsageOp(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