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 28template <class T> struct CustomOperand { 29 StringLiteral Name; 30 int Encoding = 0; 31 bool (*Cond)(T Context) = 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 63namespace SendMsg { // Symbolic names for the sendmsg(...) syntax. 64 65extern const CustomOperand<const MCSubtargetInfo &> Msg[]; 66extern const int MSG_SIZE; 67 68extern const char *const OpSysSymbolic[OP_SYS_LAST_]; 69extern const char *const OpGsSymbolic[OP_GS_LAST_]; 70 71} // namespace SendMsg 72 73namespace Hwreg { // Symbolic names for the hwreg(...) syntax. 74 75extern const CustomOperand<const MCSubtargetInfo &> Opr[]; 76extern const int OPR_SIZE; 77 78} // namespace Hwreg 79 80namespace MTBUFFormat { 81 82extern StringLiteral const DfmtSymbolic[]; 83extern StringLiteral const NfmtSymbolicGFX10[]; 84extern StringLiteral const NfmtSymbolicSICI[]; 85extern StringLiteral const NfmtSymbolicVI[]; 86extern StringLiteral const UfmtSymbolicGFX10[]; 87extern StringLiteral const UfmtSymbolicGFX11[]; 88extern unsigned const DfmtNfmt2UFmtGFX10[]; 89extern unsigned const DfmtNfmt2UFmtGFX11[]; 90 91} // namespace MTBUFFormat 92 93namespace Swizzle { // Symbolic names for the swizzle(...) syntax. 94 95extern const char* const IdSymbolic[]; 96 97} // namespace Swizzle 98 99namespace VGPRIndexMode { // Symbolic names for the gpr_idx(...) syntax. 100 101extern const char* const IdSymbolic[]; 102 103} // namespace VGPRIndexMode 104 105} // namespace AMDGPU 106} // namespace llvm 107 108#endif 109