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