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 Hwreg { // Symbolic names for the hwreg(...) syntax.
88
89int64_t getHwregId(StringRef Name, const MCSubtargetInfo &STI);
90StringRef getHwreg(uint64_t Encoding, const MCSubtargetInfo &STI);
91
92} // namespace Hwreg
93
94namespace MTBUFFormat {
95
96extern StringLiteral const DfmtSymbolic[];
97extern StringLiteral const NfmtSymbolicGFX10[];
98extern StringLiteral const NfmtSymbolicSICI[];
99extern StringLiteral const NfmtSymbolicVI[];
100extern StringLiteral const UfmtSymbolicGFX10[];
101extern StringLiteral const UfmtSymbolicGFX11[];
102extern unsigned const DfmtNfmt2UFmtGFX10[];
103extern unsigned const DfmtNfmt2UFmtGFX11[];
104
105} // namespace MTBUFFormat
106
107namespace Swizzle { // Symbolic names for the swizzle(...) syntax.
108
109extern const char* const IdSymbolic[];
110
111} // namespace Swizzle
112
113namespace VGPRIndexMode { // Symbolic names for the gpr_idx(...) syntax.
114
115extern const char* const IdSymbolic[];
116
117} // namespace VGPRIndexMode
118
119namespace UCVersion {
120
121struct GFXVersion {
122 StringLiteral Symbol;
123 unsigned Code;
124};
125
126ArrayRef<GFXVersion> getGFXVersions();
127
128} // namespace UCVersion
129
130} // namespace AMDGPU
131} // namespace llvm
132
133#endif
134