| 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 | |
| 16 | namespace llvm { |
| 17 | |
| 18 | class StringLiteral; |
| 19 | class MCSubtargetInfo; |
| 20 | |
| 21 | namespace AMDGPU { |
| 22 | |
| 23 | const int OPR_ID_UNKNOWN = -1; |
| 24 | const int OPR_ID_UNSUPPORTED = -2; |
| 25 | const int OPR_ID_DUPLICATE = -3; |
| 26 | const int OPR_VAL_INVALID = -4; |
| 27 | |
| 28 | struct CustomOperand { |
| 29 | StringLiteral Name; |
| 30 | unsigned Encoding = 0; |
| 31 | bool (*Cond)(const MCSubtargetInfo &STI) = nullptr; |
| 32 | }; |
| 33 | |
| 34 | struct 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 | |
| 56 | namespace DepCtr { |
| 57 | |
| 58 | extern const CustomOperandVal DepCtrInfo[]; |
| 59 | extern const int DEP_CTR_SIZE; |
| 60 | |
| 61 | } // namespace DepCtr |
| 62 | |
| 63 | // Symbolic names for the sendmsg(msg_id, operation, stream) syntax. |
| 64 | namespace 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. |
| 69 | int64_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(). |
| 73 | StringRef 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. |
| 78 | int64_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(). |
| 82 | StringRef getMsgOpName(int64_t MsgId, uint64_t Encoding, |
| 83 | const MCSubtargetInfo &STI); |
| 84 | |
| 85 | } // namespace SendMsg |
| 86 | |
| 87 | namespace WaitEvent { |
| 88 | int64_t getWaitEventMask(StringRef Name, const MCSubtargetInfo &STI); |
| 89 | StringRef getWaitEventMaskName(uint64_t Encoding, const MCSubtargetInfo &STI); |
| 90 | } // namespace WaitEvent |
| 91 | |
| 92 | namespace Hwreg { // Symbolic names for the hwreg(...) syntax. |
| 93 | |
| 94 | int64_t getHwregId(StringRef Name, const MCSubtargetInfo &STI); |
| 95 | StringRef getHwreg(uint64_t Encoding, const MCSubtargetInfo &STI); |
| 96 | |
| 97 | } // namespace Hwreg |
| 98 | |
| 99 | namespace MTBUFFormat { |
| 100 | |
| 101 | extern StringLiteral const DfmtSymbolic[]; |
| 102 | extern StringLiteral const NfmtSymbolicGFX10[]; |
| 103 | extern StringLiteral const NfmtSymbolicSICI[]; |
| 104 | extern StringLiteral const NfmtSymbolicVI[]; |
| 105 | extern StringLiteral const UfmtSymbolicGFX10[]; |
| 106 | extern StringLiteral const UfmtSymbolicGFX11[]; |
| 107 | extern unsigned const DfmtNfmt2UFmtGFX10[]; |
| 108 | extern unsigned const DfmtNfmt2UFmtGFX11[]; |
| 109 | |
| 110 | } // namespace MTBUFFormat |
| 111 | |
| 112 | namespace Swizzle { // Symbolic names for the swizzle(...) syntax. |
| 113 | |
| 114 | extern const char* const IdSymbolic[]; |
| 115 | |
| 116 | } // namespace Swizzle |
| 117 | |
| 118 | namespace VGPRIndexMode { // Symbolic names for the gpr_idx(...) syntax. |
| 119 | |
| 120 | extern const char* const IdSymbolic[]; |
| 121 | |
| 122 | } // namespace VGPRIndexMode |
| 123 | |
| 124 | namespace UCVersion { |
| 125 | |
| 126 | struct GFXVersion { |
| 127 | StringLiteral Symbol; |
| 128 | unsigned Code; |
| 129 | }; |
| 130 | |
| 131 | ArrayRef<GFXVersion> getGFXVersions(); |
| 132 | |
| 133 | } // namespace UCVersion |
| 134 | |
| 135 | namespace WMMAMods { |
| 136 | // These should match enum values in SIDefines.h |
| 137 | |
| 138 | constexpr const char *const ModMatrixFmt[] = { |
| 139 | "MATRIX_FMT_FP8" , "MATRIX_FMT_BF8" , "MATRIX_FMT_FP6" , "MATRIX_FMT_BF6" , |
| 140 | "MATRIX_FMT_FP4" }; |
| 141 | |
| 142 | constexpr const char *const ModMatrixScale[] = {"MATRIX_SCALE_ROW0" , |
| 143 | "MATRIX_SCALE_ROW1" }; |
| 144 | |
| 145 | constexpr 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 | |