xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AMDGPU/Utils/AMDGPUAsmUtils.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
10b57cec5SDimitry Andric //===-- AMDGPUAsmUtils.h - AsmParser/InstPrinter common ---------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #ifndef LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPUASMUTILS_H
100b57cec5SDimitry Andric #define LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPUASMUTILS_H
110b57cec5SDimitry Andric 
12fe6060f1SDimitry Andric #include "SIDefines.h"
13fe6060f1SDimitry Andric 
1481ad6265SDimitry Andric #include "llvm/ADT/StringRef.h"
1581ad6265SDimitry Andric 
160b57cec5SDimitry Andric namespace llvm {
17e8d8bef9SDimitry Andric 
18e8d8bef9SDimitry Andric class StringLiteral;
1981ad6265SDimitry Andric class MCSubtargetInfo;
20e8d8bef9SDimitry Andric 
210b57cec5SDimitry Andric namespace AMDGPU {
22e8d8bef9SDimitry Andric 
2381ad6265SDimitry Andric const int OPR_ID_UNKNOWN = -1;
2481ad6265SDimitry Andric const int OPR_ID_UNSUPPORTED = -2;
2581ad6265SDimitry Andric const int OPR_ID_DUPLICATE = -3;
2681ad6265SDimitry Andric const int OPR_VAL_INVALID = -4;
2781ad6265SDimitry Andric 
28*0fca6ea1SDimitry Andric struct CustomOperand {
2981ad6265SDimitry Andric   StringLiteral Name;
30*0fca6ea1SDimitry Andric   unsigned Encoding = 0;
31*0fca6ea1SDimitry Andric   bool (*Cond)(const MCSubtargetInfo &STI) = nullptr;
3281ad6265SDimitry Andric };
3381ad6265SDimitry Andric 
3481ad6265SDimitry Andric struct CustomOperandVal {
3581ad6265SDimitry Andric   StringLiteral Name;
3681ad6265SDimitry Andric   unsigned Max;
3781ad6265SDimitry Andric   unsigned Default;
3881ad6265SDimitry Andric   unsigned Shift;
3981ad6265SDimitry Andric   unsigned Width;
4081ad6265SDimitry Andric   bool (*Cond)(const MCSubtargetInfo &STI) = nullptr;
4181ad6265SDimitry Andric   unsigned Mask = (1 << Width) - 1;
4281ad6265SDimitry Andric 
decodeCustomOperandVal4381ad6265SDimitry Andric   unsigned decode(unsigned Code) const { return (Code >> Shift) & Mask; }
4481ad6265SDimitry Andric 
encodeCustomOperandVal4581ad6265SDimitry Andric   unsigned encode(unsigned Val) const { return (Val & Mask) << Shift; }
4681ad6265SDimitry Andric 
getMaskCustomOperandVal4781ad6265SDimitry Andric   unsigned getMask() const { return Mask << Shift; }
4881ad6265SDimitry Andric 
isValidCustomOperandVal4981ad6265SDimitry Andric   bool isValid(unsigned Val) const { return Val <= Max; }
5081ad6265SDimitry Andric 
isSupportedCustomOperandVal5181ad6265SDimitry Andric   bool isSupported(const MCSubtargetInfo &STI) const {
5281ad6265SDimitry Andric     return !Cond || Cond(STI);
5381ad6265SDimitry Andric   }
5481ad6265SDimitry Andric };
5581ad6265SDimitry Andric 
5681ad6265SDimitry Andric namespace DepCtr {
5781ad6265SDimitry Andric 
5881ad6265SDimitry Andric extern const CustomOperandVal DepCtrInfo[];
5981ad6265SDimitry Andric extern const int DEP_CTR_SIZE;
6081ad6265SDimitry Andric 
6181ad6265SDimitry Andric } // namespace DepCtr
6281ad6265SDimitry Andric 
63*0fca6ea1SDimitry Andric // Symbolic names for the sendmsg(msg_id, operation, stream) syntax.
64*0fca6ea1SDimitry Andric namespace SendMsg {
650b57cec5SDimitry Andric 
66*0fca6ea1SDimitry Andric /// Map from a symbolic name for a msg_id to the message portion of the
67*0fca6ea1SDimitry Andric /// immediate encoding. A negative return value indicates that the Name was
68*0fca6ea1SDimitry Andric /// unknown or unsupported on this target.
69*0fca6ea1SDimitry Andric int64_t getMsgId(StringRef Name, const MCSubtargetInfo &STI);
7081ad6265SDimitry Andric 
71*0fca6ea1SDimitry Andric /// Map from an encoding to the symbolic name for a msg_id immediate. This is
72*0fca6ea1SDimitry Andric /// doing opposite of getMsgId().
73*0fca6ea1SDimitry Andric StringRef getMsgName(uint64_t Encoding, const MCSubtargetInfo &STI);
74*0fca6ea1SDimitry Andric 
75*0fca6ea1SDimitry Andric /// Map from a symbolic name for a sendmsg operation to the operation portion of
76*0fca6ea1SDimitry Andric /// the immediate encoding. A negative return value indicates that the Name was
77*0fca6ea1SDimitry Andric /// unknown or unsupported on this target.
78*0fca6ea1SDimitry Andric int64_t getMsgOpId(int64_t MsgId, StringRef Name, const MCSubtargetInfo &STI);
79*0fca6ea1SDimitry Andric 
80*0fca6ea1SDimitry Andric /// Map from an encoding to the symbolic name for a sendmsg operation. This is
81*0fca6ea1SDimitry Andric /// doing opposite of getMsgOpId().
82*0fca6ea1SDimitry Andric StringRef getMsgOpName(int64_t MsgId, uint64_t Encoding,
83*0fca6ea1SDimitry Andric                        const MCSubtargetInfo &STI);
840b57cec5SDimitry Andric 
850b57cec5SDimitry Andric } // namespace SendMsg
860b57cec5SDimitry Andric 
870b57cec5SDimitry Andric namespace Hwreg { // Symbolic names for the hwreg(...) syntax.
880b57cec5SDimitry Andric 
89*0fca6ea1SDimitry Andric int64_t getHwregId(StringRef Name, const MCSubtargetInfo &STI);
90*0fca6ea1SDimitry Andric StringRef getHwreg(uint64_t Encoding, const MCSubtargetInfo &STI);
910b57cec5SDimitry Andric 
920b57cec5SDimitry Andric } // namespace Hwreg
930b57cec5SDimitry Andric 
94e8d8bef9SDimitry Andric namespace MTBUFFormat {
95e8d8bef9SDimitry Andric 
96e8d8bef9SDimitry Andric extern StringLiteral const DfmtSymbolic[];
97e8d8bef9SDimitry Andric extern StringLiteral const NfmtSymbolicGFX10[];
98e8d8bef9SDimitry Andric extern StringLiteral const NfmtSymbolicSICI[];
99e8d8bef9SDimitry Andric extern StringLiteral const NfmtSymbolicVI[];
10081ad6265SDimitry Andric extern StringLiteral const UfmtSymbolicGFX10[];
10181ad6265SDimitry Andric extern StringLiteral const UfmtSymbolicGFX11[];
10281ad6265SDimitry Andric extern unsigned const DfmtNfmt2UFmtGFX10[];
10381ad6265SDimitry Andric extern unsigned const DfmtNfmt2UFmtGFX11[];
104e8d8bef9SDimitry Andric 
105e8d8bef9SDimitry Andric } // namespace MTBUFFormat
106e8d8bef9SDimitry Andric 
1070b57cec5SDimitry Andric namespace Swizzle { // Symbolic names for the swizzle(...) syntax.
1080b57cec5SDimitry Andric 
1090b57cec5SDimitry Andric extern const char* const IdSymbolic[];
1100b57cec5SDimitry Andric 
1110b57cec5SDimitry Andric } // namespace Swizzle
1120b57cec5SDimitry Andric 
1130b57cec5SDimitry Andric namespace VGPRIndexMode { // Symbolic names for the gpr_idx(...) syntax.
1140b57cec5SDimitry Andric 
1150b57cec5SDimitry Andric extern const char* const IdSymbolic[];
1160b57cec5SDimitry Andric 
1170b57cec5SDimitry Andric } // namespace VGPRIndexMode
1180b57cec5SDimitry Andric 
119*0fca6ea1SDimitry Andric namespace UCVersion {
120*0fca6ea1SDimitry Andric 
121*0fca6ea1SDimitry Andric struct GFXVersion {
122*0fca6ea1SDimitry Andric   StringLiteral Symbol;
123*0fca6ea1SDimitry Andric   unsigned Code;
124*0fca6ea1SDimitry Andric };
125*0fca6ea1SDimitry Andric 
126*0fca6ea1SDimitry Andric ArrayRef<GFXVersion> getGFXVersions();
127*0fca6ea1SDimitry Andric 
128*0fca6ea1SDimitry Andric } // namespace UCVersion
129*0fca6ea1SDimitry Andric 
1300b57cec5SDimitry Andric } // namespace AMDGPU
1310b57cec5SDimitry Andric } // namespace llvm
1320b57cec5SDimitry Andric 
1330b57cec5SDimitry Andric #endif
134