Debian Codegraph @

llvm-project/llvm/projects/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVOpCode.h

raw
1 //===- SPIRVOpCode.h - Class to represent SPIR-V Operation Codes -*- C++ -*-==//
2 //
3 // The LLVM/SPIRV Translator
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 // Copyright (c) 2014 Advanced Micro Devices, Inc. All rights reserved.
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal with the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
16 //
17 // Redistributions of source code must retain the above copyright notice,
18 // this list of conditions and the following disclaimers.
19 // Redistributions in binary form must reproduce the above copyright notice,
20 // this list of conditions and the following disclaimers in the documentation
21 // and/or other materials provided with the distribution.
22 // Neither the names of Advanced Micro Devices, Inc., nor the names of its
23 // contributors may be used to endorse or promote products derived from this
24 // Software without specific prior written permission.
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28 // CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
31 // THE SOFTWARE.
32 //
33 //===----------------------------------------------------------------------===//
34 /// \file
35 ///
36 /// This file defines Operation Code class for SPIR-V.
37 ///
38 //===----------------------------------------------------------------------===//
39
40 #ifndef SPIRV_LIBSPIRV_SPIRVOPCODE_H
41 #define SPIRV_LIBSPIRV_SPIRVOPCODE_H
42
43 #include "SPIRVUtil.h"
44 #include "spirv/unified1/spirv.hpp"
45 #include "spirv_internal.hpp"
46 #include <string>
47
48 using namespace spv;
49 namespace SPIRV {
50
51 template <> inline void SPIRVMap<Op, std::string>::init() {
52 #define _SPIRV_OP(x, ...) add(Op##x, #x);
53 #define _SPIRV_OP_INTERNAL(x, ...) add(internal::Op##x, #x);
54 #include "SPIRVOpCodeEnum.h"
55 #include "SPIRVOpCodeEnumInternal.h"
56 #undef _SPIRV_OP_INTERNAL
57 #undef _SPIRV_OP
58 }
59 SPIRV_DEF_NAMEMAP(Op, OpCodeNameMap)
60
61 inline bool isFPAtomicOpCode(Op OpCode) {
62 return OpCode == OpAtomicFAddEXT || OpCode == OpAtomicFMinEXT ||
63 OpCode == OpAtomicFMaxEXT;
64 }
65 inline bool isAtomicOpCode(Op OpCode) {
66 static_assert(OpAtomicLoad < OpAtomicXor, "");
67 return ((unsigned)OpCode >= OpAtomicLoad &&
68 (unsigned)OpCode <= OpAtomicXor) ||
69 OpCode == OpAtomicFlagTestAndSet || OpCode == OpAtomicFlagClear ||
70 isFPAtomicOpCode(OpCode);
71 }
72 inline bool isBinaryOpCode(Op OpCode) {
73 return ((unsigned)OpCode >= OpIAdd && (unsigned)OpCode <= OpFMod) ||
74 OpCode == OpDot || OpCode == OpIAddCarry || OpCode == OpISubBorrow ||
75 OpCode == OpUMulExtended || OpCode == OpSMulExtended;
76 }
77
78 inline bool isBinaryPtrOpCode(Op OpCode) {
79 return (unsigned)OpCode >= OpPtrEqual && (unsigned)OpCode <= OpPtrDiff;
80 }
81
82 inline bool isShiftOpCode(Op OpCode) {
83 return (unsigned)OpCode >= OpShiftRightLogical &&
84 (unsigned)OpCode <= OpShiftLeftLogical;
85 }
86
87 inline bool isLogicalOpCode(Op OpCode) {
88 return (unsigned)OpCode >= OpLogicalEqual && (unsigned)OpCode <= OpLogicalNot;
89 }
90
91 inline bool isUnaryPredicateOpCode(Op OpCode) {
92 return (unsigned)OpCode >= OpAny && (unsigned)OpCode <= OpSignBitSet;
93 }
94
95 inline bool isBitwiseOpCode(Op OpCode) {
96 return (unsigned)OpCode >= OpBitwiseOr && (unsigned)OpCode <= OpBitwiseAnd;
97 }
98
99 inline bool isBinaryShiftLogicalBitwiseOpCode(Op OpCode) {
100 return (((unsigned)OpCode >= OpShiftRightLogical &&
101 (unsigned)OpCode <= OpBitwiseAnd) ||
102 isBinaryOpCode(OpCode));
103 }
104
105 inline bool isCmpOpCode(Op OpCode) {
106 return ((unsigned)OpCode >= OpIEqual &&
107 (unsigned)OpCode <= OpFUnordGreaterThanEqual) ||
108 (OpCode >= OpLessOrGreater && OpCode <= OpLogicalNotEqual);
109 }
110
111 inline bool isCvtOpCode(Op OpCode) {
112 return ((unsigned)OpCode >= OpConvertFToU && (unsigned)OpCode <= OpBitcast) ||
113 OpCode == OpSatConvertSToU || OpCode == OpSatConvertUToS ||
114 OpCode == OpPtrCastToCrossWorkgroupINTEL ||
115 OpCode == OpCrossWorkgroupCastToPtrINTEL;
116 }
117
118 inline bool isIntelCvtOpCode(Op OpCode) {
119 return OpCode == internal::OpClampConvertFToFINTEL ||
120 OpCode == internal::OpClampConvertFToSINTEL ||
121 OpCode == internal::OpStochasticRoundFToFINTEL ||
122 OpCode == internal::OpClampStochasticRoundFToFINTEL ||
123 OpCode == internal::OpClampStochasticRoundFToSINTEL;
124 }
125
126 inline bool isCvtToUnsignedOpCode(Op OpCode) {
127 return OpCode == OpConvertFToU || OpCode == OpUConvert ||
128 OpCode == OpSatConvertSToU;
129 }
130
131 inline bool isCvtFromUnsignedOpCode(Op OpCode) {
132 return OpCode == OpConvertUToF || OpCode == OpUConvert ||
133 OpCode == OpSatConvertUToS;
134 }
135
136 inline bool isSatCvtOpCode(Op OpCode) {
137 return OpCode == OpSatConvertUToS || OpCode == OpSatConvertSToU;
138 }
139
140 inline bool isOpaqueGenericTypeOpCode(Op OpCode) {
141 return ((unsigned)OpCode >= OpTypeEvent && (unsigned)OpCode <= OpTypeQueue) ||
142 OpCode == OpTypeSampler;
143 }
144
145 inline bool isGenericNegateOpCode(Op OpCode) {
146 return (unsigned)OpCode == OpSNegate || (unsigned)OpCode == OpFNegate ||
147 (unsigned)OpCode == OpNot;
148 }
149
150 inline bool isAccessChainOpCode(Op OpCode) {
151 return OpCode == OpAccessChain || OpCode == OpInBoundsAccessChain;
152 }
153
154 inline bool hasExecScope(Op OpCode) {
155 unsigned OC = OpCode;
156 return (OpGroupWaitEvents <= OC && OC <= OpGroupSMax) ||
157 (OpGroupReserveReadPipePackets <= OC &&
158 OC <= OpGroupCommitWritePipe) ||
159 (OC == OpGroupNonUniformRotateKHR);
160 }
161
162 inline bool hasGroupOperation(Op OpCode) {
163 unsigned OC = OpCode;
164 return (OpGroupIAdd <= OC && OC <= OpGroupSMax) ||
165 (OpGroupNonUniformBallotBitCount == OC) ||
166 (OpGroupNonUniformIAdd <= OC && OC <= OpGroupNonUniformLogicalXor) ||
167 (OpGroupIMulKHR <= OC && OC <= OpGroupLogicalXorKHR);
168 }
169
170 inline bool isUniformArithmeticOpCode(Op OpCode) {
171 unsigned OC = OpCode;
172 return (OpGroupIAdd <= OC && OC <= OpGroupSMax) ||
173 (OpGroupIMulKHR <= OC && OC <= OpGroupLogicalXorKHR);
174 }
175
176 inline bool isNonUniformArithmeticOpCode(Op OpCode) {
177 unsigned OC = OpCode;
178 return (OpGroupNonUniformIAdd <= OC && OC <= OpGroupNonUniformLogicalXor);
179 }
180
181 inline bool isGroupLogicalOpCode(Op OpCode) {
182 unsigned OC = OpCode;
183 return OC == OpGroupNonUniformLogicalAnd ||
184 OC == OpGroupNonUniformLogicalOr ||
185 OC == OpGroupNonUniformLogicalXor || OC == OpGroupLogicalAndKHR ||
186 OC == OpGroupLogicalOrKHR || OC == OpGroupLogicalXorKHR;
187 }
188
189 inline bool isGroupOpCode(Op OpCode) {
190 unsigned OC = OpCode;
191 return (OpGroupAll <= OC && OC <= OpGroupSMax) ||
192 (OpGroupIMulKHR <= OC && OC <= OpGroupLogicalXorKHR);
193 }
194
195 inline bool isGroupNonUniformOpcode(Op OpCode) {
196 unsigned OC = OpCode;
197 return (OpGroupNonUniformElect <= OC && OC <= OpGroupNonUniformQuadSwap) ||
198 (OC == OpGroupNonUniformRotateKHR);
199 }
200
201 inline bool isMediaBlockINTELOpcode(Op OpCode) {
202 return OpCode == OpSubgroupImageMediaBlockReadINTEL ||
203 OpCode == OpSubgroupImageMediaBlockWriteINTEL;
204 }
205
206 inline bool isPipeOpCode(Op OpCode) {
207 unsigned OC = OpCode;
208 return (OpReadPipe <= OC && OC <= OpGroupCommitWritePipe) ||
209 (OpReadPipeBlockingINTEL <= OC && OC <= OpWritePipeBlockingINTEL);
210 }
211
212 inline bool isSubgroupAvcINTELTypeOpCode(Op OpCode) {
213 unsigned OC = OpCode;
214 return OpTypeAvcImePayloadINTEL <= OC && OC <= OpTypeAvcSicResultINTEL;
215 }
216
217 inline bool isSubgroupAvcINTELInstructionOpCode(Op OpCode) {
218 unsigned OC = OpCode;
219 return OpSubgroupAvcMceGetDefaultInterBaseMultiReferencePenaltyINTEL <= OC &&
220 OC <= OpSubgroupAvcSicGetInterRawSadsINTEL;
221 }
222
223 inline bool isSubgroupAvcINTELEvaluateOpcode(Op OpCode) {
224 unsigned OC = OpCode;
225 return (OpSubgroupAvcImeEvaluateWithSingleReferenceINTEL <= OC &&
226 OC <= OpSubgroupAvcImeEvaluateWithDualReferenceStreaminoutINTEL) ||
227 (OpSubgroupAvcRefEvaluateWithSingleReferenceINTEL <= OC &&
228 OC <= OpSubgroupAvcRefEvaluateWithMultiReferenceInterlacedINTEL) ||
229 (OpSubgroupAvcSicEvaluateIpeINTEL <= OC &&
230 OC <= OpSubgroupAvcSicEvaluateWithMultiReferenceInterlacedINTEL);
231 }
232
233 inline bool isVCOpCode(Op OpCode) { return OpCode == OpTypeBufferSurfaceINTEL; }
234
235 inline bool isTypeOpCode(Op OpCode) {
236 unsigned OC = OpCode;
237 return (OpTypeVoid <= OC && OC <= OpTypePipe) || OC == OpTypePipeStorage ||
238 isSubgroupAvcINTELTypeOpCode(OpCode) || OC == OpTypeVmeImageINTEL ||
239 isVCOpCode(OpCode) || OC == internal::OpTypeTokenINTEL ||
240 OC == internal::OpTypeJointMatrixINTEL ||
241 OC == OpTypeCooperativeMatrixKHR;
242 }
243
244 inline bool isFnVarSpecConstINTEL(Op OpCode) {
245 unsigned OC = OpCode;
246 return OC == OpSpecConstantArchitectureINTEL ||
247 OC == OpSpecConstantTargetINTEL ||
248 OC == OpSpecConstantCapabilitiesINTEL;
249 }
250
251 inline bool isSpecConstantOpCode(Op OpCode) {
252 unsigned OC = OpCode;
253 return (OpSpecConstantTrue <= OC && OC <= OpSpecConstantOp) ||
254 isFnVarSpecConstINTEL(OpCode);
255 }
256
257 inline bool isConstantOpCode(Op OpCode) {
258 unsigned OC = OpCode;
259 return (OpConstantTrue <= OC && OC <= OpSpecConstantOp) || OC == OpUndef ||
260 OC == OpConstantPipeStorage || OC == OpConstantFunctionPointerINTEL ||
261 isSpecConstantOpCode(OpCode);
262 }
263
264 inline bool isModuleScopeAllowedOpCode(Op OpCode) {
265 return OpCode == OpVariable || OpCode == OpExtInst ||
266 isConstantOpCode(OpCode);
267 }
268
269 inline bool isIntelSubgroupOpCode(Op OpCode) {
270 unsigned OC = OpCode;
271 return OpSubgroupShuffleINTEL <= OC && OC <= OpSubgroupImageBlockWriteINTEL;
272 }
273
274 inline bool isEventOpCode(Op OpCode) {
275 return OpRetainEvent <= OpCode && OpCode <= OpCaptureEventProfilingInfo;
276 }
277
278 inline bool isSplitBarrierINTELOpCode(Op OpCode) {
279 return OpCode == OpControlBarrierArriveINTEL ||
280 OpCode == OpControlBarrierWaitINTEL;
281 }
282
283 } // namespace SPIRV
284
285 #endif // SPIRV_LIBSPIRV_SPIRVOPCODE_H