File: SPIRVBaseInfo.h

package info (click to toggle)
llvm-toolchain-17 1%3A17.0.6-22
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,799,624 kB
  • sloc: cpp: 6,428,607; ansic: 1,383,196; asm: 793,408; python: 223,504; objc: 75,364; f90: 60,502; lisp: 33,869; pascal: 15,282; sh: 9,684; perl: 7,453; ml: 4,937; awk: 3,523; makefile: 2,889; javascript: 2,149; xml: 888; fortran: 619; cs: 573
file content (265 lines) | stat: -rw-r--r-- 7,632 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
//===-- SPIRVBaseInfo.h - Top level SPIRV definitions -----------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file contains TableGen generated enum definitions, mnemonic lookup
// functions, versioning/capabilities/extensions getters for symbolic/named
// operands for various SPIR-V instructions.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIB_TARGET_SPIRV_SPIRVSYMBOLICOPERANDS_H
#define LLVM_LIB_TARGET_SPIRV_SPIRVSYMBOLICOPERANDS_H

#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include <string>

namespace llvm {
namespace SPIRV {
namespace OperandCategory {
#define GET_OperandCategory_DECL
#include "SPIRVGenTables.inc"
} // namespace OperandCategory

namespace Extension {
#define GET_Extension_DECL
#include "SPIRVGenTables.inc"
} // namespace Extension

namespace Capability {
#define GET_Capability_DECL
#include "SPIRVGenTables.inc"
} // namespace Capability

namespace SourceLanguage {
#define GET_SourceLanguage_DECL
#include "SPIRVGenTables.inc"
} // namespace SourceLanguage

namespace AddressingModel {
#define GET_AddressingModel_DECL
#include "SPIRVGenTables.inc"
} // namespace AddressingModel

namespace ExecutionModel {
#define GET_ExecutionModel_DECL
#include "SPIRVGenTables.inc"
} // namespace ExecutionModel

namespace MemoryModel {
#define GET_MemoryModel_DECL
#include "SPIRVGenTables.inc"
} // namespace MemoryModel

namespace ExecutionMode {
#define GET_ExecutionMode_DECL
#include "SPIRVGenTables.inc"
} // namespace ExecutionMode

namespace StorageClass {
#define GET_StorageClass_DECL
#include "SPIRVGenTables.inc"
} // namespace StorageClass

namespace Dim {
#define GET_Dim_DECL
#include "SPIRVGenTables.inc"
} // namespace Dim

namespace SamplerAddressingMode {
#define GET_SamplerAddressingMode_DECL
#include "SPIRVGenTables.inc"
} // namespace SamplerAddressingMode

namespace SamplerFilterMode {
#define GET_SamplerFilterMode_DECL
#include "SPIRVGenTables.inc"
} // namespace SamplerFilterMode

namespace ImageFormat {
#define GET_ImageFormat_DECL
#include "SPIRVGenTables.inc"
} // namespace ImageFormat

namespace ImageChannelOrder {
#define GET_ImageChannelOrder_DECL
#include "SPIRVGenTables.inc"
} // namespace ImageChannelOrder

namespace ImageChannelDataType {
#define GET_ImageChannelDataType_DECL
#include "SPIRVGenTables.inc"
} // namespace ImageChannelDataType

namespace ImageOperand {
#define GET_ImageOperand_DECL
#include "SPIRVGenTables.inc"
} // namespace ImageOperand

namespace FPFastMathMode {
#define GET_FPFastMathMode_DECL
#include "SPIRVGenTables.inc"
} // namespace FPFastMathMode

namespace FPRoundingMode {
#define GET_FPRoundingMode_DECL
#include "SPIRVGenTables.inc"
} // namespace FPRoundingMode

namespace LinkageType {
#define GET_LinkageType_DECL
#include "SPIRVGenTables.inc"
} // namespace LinkageType

namespace AccessQualifier {
#define GET_AccessQualifier_DECL
#include "SPIRVGenTables.inc"
} // namespace AccessQualifier

namespace FunctionParameterAttribute {
#define GET_FunctionParameterAttribute_DECL
#include "SPIRVGenTables.inc"
} // namespace FunctionParameterAttribute

namespace Decoration {
#define GET_Decoration_DECL
#include "SPIRVGenTables.inc"
} // namespace Decoration

namespace BuiltIn {
#define GET_BuiltIn_DECL
#include "SPIRVGenTables.inc"
} // namespace BuiltIn

namespace SelectionControl {
#define GET_SelectionControl_DECL
#include "SPIRVGenTables.inc"
} // namespace SelectionControl

namespace LoopControl {
#define GET_LoopControl_DECL
#include "SPIRVGenTables.inc"
} // namespace LoopControl

namespace FunctionControl {
#define GET_FunctionControl_DECL
#include "SPIRVGenTables.inc"
} // namespace FunctionControl

namespace MemorySemantics {
#define GET_MemorySemantics_DECL
#include "SPIRVGenTables.inc"
} // namespace MemorySemantics

namespace MemoryOperand {
#define GET_MemoryOperand_DECL
#include "SPIRVGenTables.inc"
} // namespace MemoryOperand

namespace Scope {
#define GET_Scope_DECL
#include "SPIRVGenTables.inc"
} // namespace Scope

namespace GroupOperation {
#define GET_GroupOperation_DECL
#include "SPIRVGenTables.inc"
} // namespace GroupOperation

namespace KernelEnqueueFlags {
#define GET_KernelEnqueueFlags_DECL
#include "SPIRVGenTables.inc"
} // namespace KernelEnqueueFlags

namespace KernelProfilingInfo {
#define GET_KernelProfilingInfo_DECL
#include "SPIRVGenTables.inc"
} // namespace KernelProfilingInfo

namespace InstructionSet {
#define GET_InstructionSet_DECL
#include "SPIRVGenTables.inc"
} // namespace InstructionSet

namespace OpenCLExtInst {
#define GET_OpenCLExtInst_DECL
#include "SPIRVGenTables.inc"
} // namespace OpenCLExtInst

namespace GLSLExtInst {
#define GET_GLSLExtInst_DECL
#include "SPIRVGenTables.inc"
} // namespace GLSLExtInst

namespace Opcode {
#define GET_Opcode_DECL
#include "SPIRVGenTables.inc"
} // namespace Opcode

struct ExtendedBuiltin {
  StringRef Name;
  InstructionSet::InstructionSet Set;
  uint32_t Number;
};
} // namespace SPIRV

using CapabilityList = SmallVector<SPIRV::Capability::Capability, 8>;
using ExtensionList = SmallVector<SPIRV::Extension::Extension, 8>;

std::string
getSymbolicOperandMnemonic(SPIRV::OperandCategory::OperandCategory Category,
                           int32_t Value);
uint32_t
getSymbolicOperandMinVersion(SPIRV::OperandCategory::OperandCategory Category,
                             uint32_t Value);
uint32_t
getSymbolicOperandMaxVersion(SPIRV::OperandCategory::OperandCategory Category,
                             uint32_t Value);
CapabilityList
getSymbolicOperandCapabilities(SPIRV::OperandCategory::OperandCategory Category,
                               uint32_t Value);
ExtensionList
getSymbolicOperandExtensions(SPIRV::OperandCategory::OperandCategory Category,
                             uint32_t Value);
std::string getLinkStringForBuiltIn(SPIRV::BuiltIn::BuiltIn BuiltInValue);

bool getSpirvBuiltInIdByName(StringRef Name, SPIRV::BuiltIn::BuiltIn &BI);

std::string getExtInstSetName(SPIRV::InstructionSet::InstructionSet Set);
SPIRV::InstructionSet::InstructionSet
getExtInstSetFromString(std::string SetName);
std::string getExtInstName(SPIRV::InstructionSet::InstructionSet Set,
                           uint32_t InstructionNumber);

// Return a string representation of the operands from startIndex onwards.
// Templated to allow both MachineInstr and MCInst to use the same logic.
template <class InstType>
std::string getSPIRVStringOperand(const InstType &MI, unsigned StartIndex) {
  std::string s; // Iteratively append to this string.

  const unsigned NumOps = MI.getNumOperands();
  bool IsFinished = false;
  for (unsigned i = StartIndex; i < NumOps && !IsFinished; ++i) {
    const auto &Op = MI.getOperand(i);
    if (!Op.isImm()) // Stop if we hit a register operand.
      break;
    assert((Op.getImm() >> 32) == 0 && "Imm operand should be i32 word");
    const uint32_t Imm = Op.getImm(); // Each i32 word is up to 4 characters.
    for (unsigned ShiftAmount = 0; ShiftAmount < 32; ShiftAmount += 8) {
      char c = (Imm >> ShiftAmount) & 0xff;
      if (c == 0) { // Stop if we hit a null-terminator character.
        IsFinished = true;
        break;
      }
      s += c; // Otherwise, append the character to the result string.
    }
  }
  return s;
}
} // namespace llvm
#endif // LLVM_LIB_TARGET_SPIRV_SPIRVSYMBOLICOPERANDS_H