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