1//===-- SPIRVBaseInfo.h - Top level SPIRV definitions -----------*- 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// This file contains TableGen generated enum definitions, mnemonic lookup
10// functions, versioning/capabilities/extensions getters for symbolic/named
11// operands for various SPIR-V instructions.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_LIB_TARGET_SPIRV_SPIRVSYMBOLICOPERANDS_H
16#define LLVM_LIB_TARGET_SPIRV_SPIRVSYMBOLICOPERANDS_H
17
18#include "llvm/ADT/SmallVector.h"
19#include "llvm/ADT/StringRef.h"
20#include "llvm/Support/VersionTuple.h"
21#include <string>
22
23namespace llvm {
24namespace SPIRV {
25namespace OperandCategory {
26#define GET_OperandCategory_DECL
27#include "SPIRVGenTables.inc"
28} // namespace OperandCategory
29
30namespace Extension {
31#define GET_Extension_DECL
32#include "SPIRVGenTables.inc"
33} // namespace Extension
34
35namespace Capability {
36#define GET_Capability_DECL
37#include "SPIRVGenTables.inc"
38} // namespace Capability
39
40namespace SourceLanguage {
41#define GET_SourceLanguage_DECL
42#include "SPIRVGenTables.inc"
43} // namespace SourceLanguage
44
45namespace AddressingModel {
46#define GET_AddressingModel_DECL
47#include "SPIRVGenTables.inc"
48} // namespace AddressingModel
49
50namespace ExecutionModel {
51#define GET_ExecutionModel_DECL
52#include "SPIRVGenTables.inc"
53} // namespace ExecutionModel
54
55namespace MemoryModel {
56#define GET_MemoryModel_DECL
57#include "SPIRVGenTables.inc"
58} // namespace MemoryModel
59
60namespace MatrixMultiplyAccumulateOperands {
61#define GET_MatrixMultiplyAccumulateOperands_DECL
62#include "SPIRVGenTables.inc"
63} // namespace MatrixMultiplyAccumulateOperands
64
65namespace ExecutionMode {
66#define GET_ExecutionMode_DECL
67#include "SPIRVGenTables.inc"
68} // namespace ExecutionMode
69
70namespace StorageClass {
71#define GET_StorageClass_DECL
72#include "SPIRVGenTables.inc"
73} // namespace StorageClass
74
75namespace Dim {
76#define GET_Dim_DECL
77#include "SPIRVGenTables.inc"
78} // namespace Dim
79
80namespace SamplerAddressingMode {
81#define GET_SamplerAddressingMode_DECL
82#include "SPIRVGenTables.inc"
83} // namespace SamplerAddressingMode
84
85namespace SamplerFilterMode {
86#define GET_SamplerFilterMode_DECL
87#include "SPIRVGenTables.inc"
88} // namespace SamplerFilterMode
89
90namespace ImageFormat {
91#define GET_ImageFormat_DECL
92#include "SPIRVGenTables.inc"
93} // namespace ImageFormat
94
95namespace ImageChannelOrder {
96#define GET_ImageChannelOrder_DECL
97#include "SPIRVGenTables.inc"
98} // namespace ImageChannelOrder
99
100namespace ImageChannelDataType {
101#define GET_ImageChannelDataType_DECL
102#include "SPIRVGenTables.inc"
103} // namespace ImageChannelDataType
104
105namespace ImageOperand {
106#define GET_ImageOperand_DECL
107#include "SPIRVGenTables.inc"
108} // namespace ImageOperand
109
110namespace FPFastMathMode {
111#define GET_FPFastMathMode_DECL
112#include "SPIRVGenTables.inc"
113} // namespace FPFastMathMode
114
115namespace FPRoundingMode {
116#define GET_FPRoundingMode_DECL
117#include "SPIRVGenTables.inc"
118} // namespace FPRoundingMode
119
120namespace LinkageType {
121#define GET_LinkageType_DECL
122#include "SPIRVGenTables.inc"
123} // namespace LinkageType
124
125namespace AccessQualifier {
126#define GET_AccessQualifier_DECL
127#include "SPIRVGenTables.inc"
128} // namespace AccessQualifier
129
130namespace FunctionParameterAttribute {
131#define GET_FunctionParameterAttribute_DECL
132#include "SPIRVGenTables.inc"
133} // namespace FunctionParameterAttribute
134
135namespace Decoration {
136#define GET_Decoration_DECL
137#include "SPIRVGenTables.inc"
138} // namespace Decoration
139
140namespace BuiltIn {
141#define GET_BuiltIn_DECL
142#include "SPIRVGenTables.inc"
143} // namespace BuiltIn
144
145namespace SelectionControl {
146#define GET_SelectionControl_DECL
147#include "SPIRVGenTables.inc"
148} // namespace SelectionControl
149
150namespace LoopControl {
151#define GET_LoopControl_DECL
152#include "SPIRVGenTables.inc"
153} // namespace LoopControl
154
155namespace FunctionControl {
156#define GET_FunctionControl_DECL
157#include "SPIRVGenTables.inc"
158} // namespace FunctionControl
159
160namespace MemorySemantics {
161#define GET_MemorySemantics_DECL
162#include "SPIRVGenTables.inc"
163} // namespace MemorySemantics
164
165namespace MemoryOperand {
166#define GET_MemoryOperand_DECL
167#include "SPIRVGenTables.inc"
168} // namespace MemoryOperand
169
170namespace Scope {
171#define GET_Scope_DECL
172#include "SPIRVGenTables.inc"
173} // namespace Scope
174
175namespace GroupOperation {
176#define GET_GroupOperation_DECL
177#include "SPIRVGenTables.inc"
178} // namespace GroupOperation
179
180namespace KernelEnqueueFlags {
181#define GET_KernelEnqueueFlags_DECL
182#include "SPIRVGenTables.inc"
183} // namespace KernelEnqueueFlags
184
185namespace KernelProfilingInfo {
186#define GET_KernelProfilingInfo_DECL
187#include "SPIRVGenTables.inc"
188} // namespace KernelProfilingInfo
189
190namespace InstructionSet {
191#define GET_InstructionSet_DECL
192#include "SPIRVGenTables.inc"
193} // namespace InstructionSet
194
195namespace OpenCLExtInst {
196#define GET_OpenCLExtInst_DECL
197#include "SPIRVGenTables.inc"
198} // namespace OpenCLExtInst
199
200namespace GLSLExtInst {
201#define GET_GLSLExtInst_DECL
202#include "SPIRVGenTables.inc"
203} // namespace GLSLExtInst
204
205namespace NonSemanticExtInst {
206#define GET_NonSemanticExtInst_DECL
207#include "SPIRVGenTables.inc"
208} // namespace NonSemanticExtInst
209
210namespace Opcode {
211#define GET_Opcode_DECL
212#include "SPIRVGenTables.inc"
213} // namespace Opcode
214
215namespace CooperativeMatrixLayout {
216#define GET_CooperativeMatrixLayout_DECL
217#include "SPIRVGenTables.inc"
218} // namespace CooperativeMatrixLayout
219
220namespace CooperativeMatrixOperands {
221#define GET_CooperativeMatrixOperands_DECL
222#include "SPIRVGenTables.inc"
223} // namespace CooperativeMatrixOperands
224
225namespace SpecConstantOpOperands {
226#define GET_SpecConstantOpOperands_DECL
227#include "SPIRVGenTables.inc"
228} // namespace SpecConstantOpOperands
229
230struct ExtendedBuiltin {
231 StringRef Name;
232 InstructionSet::InstructionSet Set;
233 uint32_t Number;
234};
235
236enum InstFlags {
237 // It is a half type
238 INST_PRINTER_WIDTH16 = 1
239};
240} // namespace SPIRV
241
242using CapabilityList = SmallVector<SPIRV::Capability::Capability, 8>;
243using ExtensionList = SmallVector<SPIRV::Extension::Extension, 8>;
244
245std::string
246getSymbolicOperandMnemonic(SPIRV::OperandCategory::OperandCategory Category,
247 int32_t Value);
248VersionTuple
249getSymbolicOperandMinVersion(SPIRV::OperandCategory::OperandCategory Category,
250 uint32_t Value);
251VersionTuple
252getSymbolicOperandMaxVersion(SPIRV::OperandCategory::OperandCategory Category,
253 uint32_t Value);
254CapabilityList
255getSymbolicOperandCapabilities(SPIRV::OperandCategory::OperandCategory Category,
256 uint32_t Value);
257CapabilityList
258getCapabilitiesEnabledByExtension(SPIRV::Extension::Extension Extension);
259ExtensionList
260getSymbolicOperandExtensions(SPIRV::OperandCategory::OperandCategory Category,
261 uint32_t Value);
262std::string getLinkStringForBuiltIn(SPIRV::BuiltIn::BuiltIn BuiltInValue);
263
264bool getSpirvBuiltInIdByName(StringRef Name, SPIRV::BuiltIn::BuiltIn &BI);
265
266std::string getExtInstSetName(SPIRV::InstructionSet::InstructionSet Set);
267SPIRV::InstructionSet::InstructionSet
268getExtInstSetFromString(std::string SetName);
269std::string getExtInstName(SPIRV::InstructionSet::InstructionSet Set,
270 uint32_t InstructionNumber);
271
272// Return a string representation of the operands from startIndex onwards.
273// Templated to allow both MachineInstr and MCInst to use the same logic.
274template <class InstType>
275std::string getSPIRVStringOperand(const InstType &MI, unsigned StartIndex) {
276 std::string s; // Iteratively append to this string.
277
278 const unsigned NumOps = MI.getNumOperands();
279 bool IsFinished = false;
280 for (unsigned i = StartIndex; i < NumOps && !IsFinished; ++i) {
281 const auto &Op = MI.getOperand(i);
282 if (!Op.isImm()) // Stop if we hit a register operand.
283 break;
284 assert((Op.getImm() >> 32) == 0 && "Imm operand should be i32 word");
285 const uint32_t Imm = Op.getImm(); // Each i32 word is up to 4 characters.
286 for (unsigned ShiftAmount = 0; ShiftAmount < 32; ShiftAmount += 8) {
287 char c = (Imm >> ShiftAmount) & 0xff;
288 if (c == 0) { // Stop if we hit a null-terminator character.
289 IsFinished = true;
290 break;
291 }
292 s += c; // Otherwise, append the character to the result string.
293 }
294 }
295 return s;
296}
297} // namespace llvm
298#endif // LLVM_LIB_TARGET_SPIRV_SPIRVSYMBOLICOPERANDS_H
299