1//===-- AMDGPUAsmUtils.h - AsmParser/InstPrinter common ---------*- 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#ifndef LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPUASMUTILS_H
10#define LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPUASMUTILS_H
11
12#include "SIDefines.h"
13
14#include "llvm/ADT/StringRef.h"
15
16namespace llvm {
17
18class StringLiteral;
19class MCSubtargetInfo;
20
21namespace AMDGPU {
22
23const int OPR_ID_UNKNOWN = -1;
24const int OPR_ID_UNSUPPORTED = -2;
25const int OPR_ID_DUPLICATE = -3;
26const int OPR_VAL_INVALID = -4;
27
28struct CustomOperand {
29 StringLiteral Name;
30 unsigned Encoding = 0;
31 bool (*Cond)(const MCSubtargetInfo &STI) = nullptr;
32};
33
34struct CustomOperandVal {
35 StringLiteral Name;
36 unsigned Max;
37 unsigned Default;
38 unsigned Shift;
39 unsigned Width;
40 bool (*Cond)(const MCSubtargetInfo &STI) = nullptr;
41 unsigned Mask = (1 << Width) - 1;
42
43 unsigned decode(unsigned Code) const { return (Code >> Shift) & Mask; }
44
45 unsigned encode(unsigned Val) const { return (Val & Mask) << Shift; }
46
47 unsigned getMask() const { return Mask << Shift; }
48
49 bool isValid(unsigned Val) const { return Val <= Max; }
50
51 bool isSupported(const MCSubtargetInfo &STI) const {
52 return !Cond || Cond(STI);
53 }
54};
55
56namespace DepCtr {
57
58extern const CustomOperandVal DepCtrInfo[];
59extern const int DEP_CTR_SIZE;
60
61} // namespace DepCtr
62
63// Symbolic names for the sendmsg(msg_id, operation, stream) syntax.
64namespace SendMsg {
65
66/// Map from a symbolic name for a msg_id to the message portion of the
67/// immediate encoding. A negative return value indicates that the Name was
68/// unknown or unsupported on this target.
69int64_t getMsgId(StringRef Name, const MCSubtargetInfo &STI);
70
71/// Map from an encoding to the symbolic name for a msg_id immediate. This is
72/// doing opposite of getMsgId().
73StringRef getMsgName(uint64_t Encoding, const MCSubtargetInfo &STI);
74
75/// Map from a symbolic name for a sendmsg operation to the operation portion of
76/// the immediate encoding. A negative return value indicates that the Name was
77/// unknown or unsupported on this target.
78int64_t getMsgOpId(int64_t MsgId, StringRef Name, const MCSubtargetInfo &STI);
79
80/// Map from an encoding to the symbolic name for a sendmsg operation. This is
81/// doing opposite of getMsgOpId().
82StringRef getMsgOpName(int64_t MsgId, uint64_t Encoding,
83 const MCSubtargetInfo &STI);
84
85} // namespace SendMsg
86
87namespace WaitEvent {
88int64_t getWaitEventMask(StringRef Name, const MCSubtargetInfo &STI);
89StringRef getWaitEventMaskName(uint64_t Encoding, const MCSubtargetInfo &STI);
90} // namespace WaitEvent
91
92namespace Hwreg { // Symbolic names for the hwreg(...) syntax.
93
94int64_t getHwregId(StringRef Name, const MCSubtargetInfo &STI);
95StringRef getHwreg(uint64_t Encoding, const MCSubtargetInfo &STI);
96
97} // namespace Hwreg
98
99namespace MTBUFFormat {
100
101extern StringLiteral const DfmtSymbolic[];
102extern StringLiteral const NfmtSymbolicGFX10[];
103extern StringLiteral const NfmtSymbolicSICI[];
104extern StringLiteral const NfmtSymbolicVI[];
105extern StringLiteral const UfmtSymbolicGFX10[];
106extern StringLiteral const UfmtSymbolicGFX11[];
107extern unsigned const DfmtNfmt2UFmtGFX10[];
108extern unsigned const DfmtNfmt2UFmtGFX11[];
109
110} // namespace MTBUFFormat
111
112namespace Swizzle { // Symbolic names for the swizzle(...) syntax.
113
114extern const char* const IdSymbolic[];
115
116} // namespace Swizzle
117
118namespace VGPRIndexMode { // Symbolic names for the gpr_idx(...) syntax.
119
120extern const char* const IdSymbolic[];
121
122} // namespace VGPRIndexMode
123
124namespace UCVersion {
125
126struct GFXVersion {
127 StringLiteral Symbol;
128 unsigned Code;
129};
130
131ArrayRef<GFXVersion> getGFXVersions();
132
133} // namespace UCVersion
134
135namespace WMMAMods {
136// These should match enum values in SIDefines.h
137
138constexpr const char *const ModMatrixFmt[] = {
139 "MATRIX_FMT_FP8", "MATRIX_FMT_BF8", "MATRIX_FMT_FP6", "MATRIX_FMT_BF6",
140 "MATRIX_FMT_FP4"};
141
142constexpr const char *const ModMatrixScale[] = {"MATRIX_SCALE_ROW0",
143 "MATRIX_SCALE_ROW1"};
144
145constexpr const char *const ModMatrixScaleFmt[] = {
146 "MATRIX_SCALE_FMT_E8", "MATRIX_SCALE_FMT_E5M3", "MATRIX_SCALE_FMT_E4M3"};
147} // namespace WMMAMods
148
149} // namespace AMDGPU
150} // namespace llvm
151
152#endif
153