blob: ae9d02407fadbb29eb22e0b43bf569f0fff1f970 [file] [log] [blame]
Dejan Mircevskib6fe02f2016-01-07 13:44:22 -05001// Copyright (c) 2015-2016 The Khronos Group Inc.
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01002//
David Neto9fc86582016-09-01 15:33:59 -04003// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01006//
David Neto9fc86582016-09-01 15:33:59 -04007// http://www.apache.org/licenses/LICENSE-2.0
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01008//
David Neto9fc86582016-09-01 15:33:59 -04009// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010014
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010015#include "opcode.h"
16
17#include <assert.h>
18#include <string.h>
19
David Neto5a0b5ca2016-12-09 14:01:43 -050020#include <algorithm>
Lei Zhang972788b2015-11-12 13:48:30 -050021#include <cstdlib>
22
Lei Zhang923f6c12015-11-11 12:45:23 -050023#include "instruction.h"
Lei Zhangca1bf942016-04-27 16:47:13 -040024#include "macro.h"
David Neto5a703352016-02-17 14:44:00 -050025#include "spirv-tools/libspirv.h"
Lei Zhangaa056cd2015-11-11 14:24:04 -050026#include "spirv_constant.h"
David Neto4c215712015-12-22 15:08:41 -050027#include "spirv_endian.h"
Lei Zhang923f6c12015-11-11 12:45:23 -050028
David Neto78c3b432015-08-27 13:03:52 -040029namespace {
Lei Zhang16981f82017-09-21 17:24:57 -040030struct OpcodeDescPtrLen {
31 const spv_opcode_desc_t* ptr;
32 uint32_t len;
33};
David Neto78c3b432015-08-27 13:03:52 -040034
Lei Zhang063dbea2017-10-25 12:15:51 -040035#include "core.insts-1.0.inc" // defines kOpcodeTableEntries_1_0
36#include "core.insts-1.1.inc" // defines kOpcodeTableEntries_1_1
37#include "core.insts-1.2.inc" // defines kOpcodeTableEntries_1_2
Lei Zhang16981f82017-09-21 17:24:57 -040038
Lei Zhang063dbea2017-10-25 12:15:51 -040039static const spv_opcode_table_t kTable_1_0 = {
40 ARRAY_SIZE(kOpcodeTableEntries_1_0), kOpcodeTableEntries_1_0};
41static const spv_opcode_table_t kTable_1_1 = {
42 ARRAY_SIZE(kOpcodeTableEntries_1_1), kOpcodeTableEntries_1_1};
43static const spv_opcode_table_t kTable_1_2 = {
44 ARRAY_SIZE(kOpcodeTableEntries_1_2), kOpcodeTableEntries_1_2};
David Neto78c3b432015-08-27 13:03:52 -040045
David Neto5a0b5ca2016-12-09 14:01:43 -050046// Represents a vendor tool entry in the SPIR-V XML Regsitry.
47struct VendorTool {
48 uint32_t value;
49 const char* vendor;
Lei Zhang16981f82017-09-21 17:24:57 -040050 const char* tool; // Might be empty string.
51 const char* vendor_tool; // Combiantion of vendor and tool.
David Neto5a0b5ca2016-12-09 14:01:43 -050052};
53
54const VendorTool vendor_tools[] = {
55#include "generators.inc"
56};
57
Lei Zhanga94701d2015-09-14 10:05:37 -040058} // anonymous namespace
David Neto78c3b432015-08-27 13:03:52 -040059
David Neto5a0b5ca2016-12-09 14:01:43 -050060// TODO(dneto): Move this to another file. It doesn't belong with opcode
61// processing.
Lei Zhang1a0334e2015-11-02 09:41:20 -050062const char* spvGeneratorStr(uint32_t generator) {
David Neto5a0b5ca2016-12-09 14:01:43 -050063 auto where = std::find_if(
64 std::begin(vendor_tools), std::end(vendor_tools),
65 [generator](const VendorTool& vt) { return generator == vt.value; });
66 if (where != std::end(vendor_tools)) return where->vendor_tool;
67 return "Unknown";
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010068}
69
Lei Zhangb36e7042015-10-28 13:40:52 -040070uint32_t spvOpcodeMake(uint16_t wordCount, SpvOp opcode) {
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010071 return ((uint32_t)opcode) | (((uint32_t)wordCount) << 16);
72}
73
Lei Zhang6fa3f8a2016-03-31 17:26:31 -040074void spvOpcodeSplit(const uint32_t word, uint16_t* pWordCount,
75 uint16_t* pOpcode) {
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010076 if (pWordCount) {
77 *pWordCount = (uint16_t)((0xffff0000 & word) >> 16);
78 }
79 if (pOpcode) {
Lei Zhang6fa3f8a2016-03-31 17:26:31 -040080 *pOpcode = 0x0000ffff & word;
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010081 }
82}
83
Dejan Mircevskicb3c49e2016-04-07 14:41:34 -040084spv_result_t spvOpcodeTableGet(spv_opcode_table* pInstTable,
85 spv_target_env env) {
Lei Zhang40056702015-09-11 14:31:27 -040086 if (!pInstTable) return SPV_ERROR_INVALID_POINTER;
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010087
Lei Zhang16981f82017-09-21 17:24:57 -040088 // Descriptions of each opcode. Each entry describes the format of the
89 // instruction that follows a particular opcode.
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010090
Dejan Mircevskicb3c49e2016-04-07 14:41:34 -040091 switch (env) {
92 case SPV_ENV_UNIVERSAL_1_0:
93 case SPV_ENV_VULKAN_1_0:
Pierre Moreau12447d82017-11-30 00:49:23 +010094 case SPV_ENV_OPENCL_1_2:
95 case SPV_ENV_OPENCL_EMBEDDED_1_2:
96 case SPV_ENV_OPENCL_2_0:
97 case SPV_ENV_OPENCL_EMBEDDED_2_0:
David Netoc2967012016-08-05 18:19:30 -040098 case SPV_ENV_OPENCL_2_1:
Pierre Moreau12447d82017-11-30 00:49:23 +010099 case SPV_ENV_OPENCL_EMBEDDED_2_1:
David Netoc2967012016-08-05 18:19:30 -0400100 case SPV_ENV_OPENGL_4_0:
101 case SPV_ENV_OPENGL_4_1:
102 case SPV_ENV_OPENGL_4_2:
103 case SPV_ENV_OPENGL_4_3:
104 case SPV_ENV_OPENGL_4_5:
Lei Zhang063dbea2017-10-25 12:15:51 -0400105 *pInstTable = &kTable_1_0;
Dejan Mircevskicb3c49e2016-04-07 14:41:34 -0400106 return SPV_SUCCESS;
107 case SPV_ENV_UNIVERSAL_1_1:
Lei Zhang063dbea2017-10-25 12:15:51 -0400108 *pInstTable = &kTable_1_1;
Dejan Mircevskicb3c49e2016-04-07 14:41:34 -0400109 return SPV_SUCCESS;
David Netodbc20492017-03-14 12:43:41 -0400110 case SPV_ENV_UNIVERSAL_1_2:
111 case SPV_ENV_OPENCL_2_2:
Pierre Moreau12447d82017-11-30 00:49:23 +0100112 case SPV_ENV_OPENCL_EMBEDDED_2_2:
Lei Zhang063dbea2017-10-25 12:15:51 -0400113 *pInstTable = &kTable_1_2;
David Netodbc20492017-03-14 12:43:41 -0400114 return SPV_SUCCESS;
Dejan Mircevskicb3c49e2016-04-07 14:41:34 -0400115 }
116 assert(0 && "Unknown spv_target_env in spvOpcodeTableGet()");
117 return SPV_ERROR_INVALID_TABLE;
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100118}
119
120spv_result_t spvOpcodeTableNameLookup(const spv_opcode_table table,
Lei Zhang1a0334e2015-11-02 09:41:20 -0500121 const char* name,
122 spv_opcode_desc* pEntry) {
Lei Zhang40056702015-09-11 14:31:27 -0400123 if (!name || !pEntry) return SPV_ERROR_INVALID_POINTER;
124 if (!table) return SPV_ERROR_INVALID_TABLE;
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100125
126 // TODO: This lookup of the Opcode table is suboptimal! Binary sort would be
127 // preferable but the table requires sorting on the Opcode name, but it's
128 // static
129 // const initialized and matches the order of the spec.
130 const size_t nameLength = strlen(name);
131 for (uint64_t opcodeIndex = 0; opcodeIndex < table->count; ++opcodeIndex) {
132 if (nameLength == strlen(table->entries[opcodeIndex].name) &&
133 !strncmp(name, table->entries[opcodeIndex].name, nameLength)) {
134 // NOTE: Found out Opcode!
135 *pEntry = &table->entries[opcodeIndex];
136 return SPV_SUCCESS;
137 }
138 }
139
140 return SPV_ERROR_INVALID_LOOKUP;
141}
142
143spv_result_t spvOpcodeTableValueLookup(const spv_opcode_table table,
Lei Zhangb36e7042015-10-28 13:40:52 -0400144 const SpvOp opcode,
Lei Zhang1a0334e2015-11-02 09:41:20 -0500145 spv_opcode_desc* pEntry) {
Lei Zhang40056702015-09-11 14:31:27 -0400146 if (!table) return SPV_ERROR_INVALID_TABLE;
147 if (!pEntry) return SPV_ERROR_INVALID_POINTER;
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100148
Jesus Carabanof063f912017-10-27 15:28:50 +0300149 const auto beg = table->entries;
150 const auto end = table->entries + table->count;
151 spv_opcode_desc_t value{"", opcode, 0, nullptr, 0, {}, 0, 0};
152 auto comp = [](const spv_opcode_desc_t& lhs, const spv_opcode_desc_t& rhs) {
153 return lhs.opcode < rhs.opcode;
154 };
155 auto it = std::lower_bound(beg, end, value, comp);
Diego Novillod2938e42017-11-08 12:40:02 -0500156 if (it != end && it->opcode == opcode) {
Jesus Carabanof063f912017-10-27 15:28:50 +0300157 *pEntry = it;
158 return SPV_SUCCESS;
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100159 }
160
161 return SPV_ERROR_INVALID_LOOKUP;
162}
163
Lei Zhang1a0334e2015-11-02 09:41:20 -0500164void spvInstructionCopy(const uint32_t* words, const SpvOp opcode,
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100165 const uint16_t wordCount, const spv_endianness_t endian,
Lei Zhang1a0334e2015-11-02 09:41:20 -0500166 spv_instruction_t* pInst) {
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100167 pInst->opcode = opcode;
David Netob5dc8fc2015-10-06 16:22:00 -0400168 pInst->words.resize(wordCount);
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100169 for (uint16_t wordIndex = 0; wordIndex < wordCount; ++wordIndex) {
170 pInst->words[wordIndex] = spvFixWord(words[wordIndex], endian);
171 if (!wordIndex) {
172 uint16_t thisWordCount;
Lei Zhang6fa3f8a2016-03-31 17:26:31 -0400173 uint16_t thisOpcode;
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100174 spvOpcodeSplit(pInst->words[wordIndex], &thisWordCount, &thisOpcode);
Lei Zhang6fa3f8a2016-03-31 17:26:31 -0400175 assert(opcode == static_cast<SpvOp>(thisOpcode) &&
176 wordCount == thisWordCount && "Endianness failed!");
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100177 }
178 }
179}
180
Lei Zhang1a0334e2015-11-02 09:41:20 -0500181const char* spvOpcodeString(const SpvOp opcode) {
Dejan Mircevskicb3c49e2016-04-07 14:41:34 -0400182 // Use the latest SPIR-V version, which should be backward-compatible with all
183 // previous ones.
Jesus Carabanof063f912017-10-27 15:28:50 +0300184
185 const auto beg = kOpcodeTableEntries_1_2;
Diego Novillod2938e42017-11-08 12:40:02 -0500186 const auto end =
187 kOpcodeTableEntries_1_2 + ARRAY_SIZE(kOpcodeTableEntries_1_2);
Jesus Carabanof063f912017-10-27 15:28:50 +0300188 spv_opcode_desc_t value{"", opcode, 0, nullptr, 0, {}, 0, 0};
189 auto comp = [](const spv_opcode_desc_t& lhs, const spv_opcode_desc_t& rhs) {
190 return lhs.opcode < rhs.opcode;
191 };
192 auto it = std::lower_bound(beg, end, value, comp);
Diego Novillod2938e42017-11-08 12:40:02 -0500193 if (it != end && it->opcode == opcode) {
Jesus Carabanof063f912017-10-27 15:28:50 +0300194 return it->name;
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100195 }
Lei Zhang16981f82017-09-21 17:24:57 -0400196
Lei Zhang4f293b72016-03-21 16:36:14 -0400197 assert(0 && "Unreachable!");
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100198 return "unknown";
199}
200
Lei Zhangb36e7042015-10-28 13:40:52 -0400201int32_t spvOpcodeIsScalarType(const SpvOp opcode) {
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100202 switch (opcode) {
Lei Zhangb36e7042015-10-28 13:40:52 -0400203 case SpvOpTypeInt:
204 case SpvOpTypeFloat:
Dejan Mircevski276a7242016-01-21 15:55:43 -0500205 case SpvOpTypeBool:
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100206 return true;
207 default:
208 return false;
209 }
210}
211
Lei Zhangb36e7042015-10-28 13:40:52 -0400212int32_t spvOpcodeIsConstant(const SpvOp opcode) {
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100213 switch (opcode) {
Lei Zhangb36e7042015-10-28 13:40:52 -0400214 case SpvOpConstantTrue:
215 case SpvOpConstantFalse:
216 case SpvOpConstant:
217 case SpvOpConstantComposite:
218 case SpvOpConstantSampler:
Lei Zhangb36e7042015-10-28 13:40:52 -0400219 case SpvOpConstantNull:
220 case SpvOpSpecConstantTrue:
221 case SpvOpSpecConstantFalse:
222 case SpvOpSpecConstant:
223 case SpvOpSpecConstantComposite:
Dejan Mircevski3fb26762016-04-04 15:55:05 -0400224 case SpvOpSpecConstantOp:
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100225 return true;
226 default:
227 return false;
228 }
229}
230
David Neto1f3fb502016-09-14 11:57:20 -0400231bool spvOpcodeIsConstantOrUndef(const SpvOp opcode) {
232 return opcode == SpvOpUndef || spvOpcodeIsConstant(opcode);
233}
234
Aliya Pazylbekovaedb52642017-02-24 20:43:28 -0500235bool spvOpcodeIsScalarSpecConstant(const SpvOp opcode) {
236 switch (opcode) {
237 case SpvOpSpecConstantTrue:
238 case SpvOpSpecConstantFalse:
239 case SpvOpSpecConstant:
240 return true;
241 default:
242 return false;
243 }
244}
245
Lei Zhangb36e7042015-10-28 13:40:52 -0400246int32_t spvOpcodeIsComposite(const SpvOp opcode) {
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100247 switch (opcode) {
Lei Zhangb36e7042015-10-28 13:40:52 -0400248 case SpvOpTypeVector:
249 case SpvOpTypeMatrix:
250 case SpvOpTypeArray:
251 case SpvOpTypeStruct:
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100252 return true;
253 default:
254 return false;
255 }
256}
257
Ehsan Nasiri23af06c2017-02-01 15:37:39 -0500258bool spvOpcodeReturnsLogicalVariablePointer(const SpvOp opcode) {
259 switch (opcode) {
260 case SpvOpVariable:
261 case SpvOpAccessChain:
262 case SpvOpInBoundsAccessChain:
263 case SpvOpFunctionParameter:
264 case SpvOpImageTexelPointer:
265 case SpvOpCopyObject:
266 case SpvOpSelect:
267 case SpvOpPhi:
268 case SpvOpFunctionCall:
269 case SpvOpPtrAccessChain:
270 case SpvOpLoad:
271 case SpvOpConstantNull:
272 return true;
273 default:
274 return false;
275 }
276}
277
Florian Ziesche66fcb452016-03-02 22:17:54 +0100278int32_t spvOpcodeReturnsLogicalPointer(const SpvOp opcode) {
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100279 switch (opcode) {
Lei Zhangb36e7042015-10-28 13:40:52 -0400280 case SpvOpVariable:
281 case SpvOpAccessChain:
282 case SpvOpInBoundsAccessChain:
283 case SpvOpFunctionParameter:
Florian Ziesche66fcb452016-03-02 22:17:54 +0100284 case SpvOpImageTexelPointer:
285 case SpvOpCopyObject:
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100286 return true;
287 default:
288 return false;
289 }
290}
291
Lei Zhangb36e7042015-10-28 13:40:52 -0400292int32_t spvOpcodeGeneratesType(SpvOp op) {
Lei Zhang1a0334e2015-11-02 09:41:20 -0500293 switch (op) {
Lei Zhangb36e7042015-10-28 13:40:52 -0400294 case SpvOpTypeVoid:
295 case SpvOpTypeBool:
296 case SpvOpTypeInt:
297 case SpvOpTypeFloat:
298 case SpvOpTypeVector:
299 case SpvOpTypeMatrix:
300 case SpvOpTypeImage:
301 case SpvOpTypeSampler:
302 case SpvOpTypeSampledImage:
303 case SpvOpTypeArray:
304 case SpvOpTypeRuntimeArray:
305 case SpvOpTypeStruct:
306 case SpvOpTypeOpaque:
307 case SpvOpTypePointer:
308 case SpvOpTypeFunction:
309 case SpvOpTypeEvent:
310 case SpvOpTypeDeviceEvent:
311 case SpvOpTypeReserveId:
312 case SpvOpTypeQueue:
313 case SpvOpTypePipe:
Andrey Tuganov4ef3b3e2017-02-28 11:53:47 -0500314 case SpvOpTypePipeStorage:
315 case SpvOpTypeNamedBarrier:
Andrew Woloszyn537e7762015-09-29 11:28:34 -0400316 return true;
David Netoaef608c2015-11-02 14:59:02 -0500317 default:
318 // In particular, OpTypeForwardPointer does not generate a type,
319 // but declares a storage class for a pointer type generated
320 // by a different instruction.
321 break;
Andrew Woloszyn537e7762015-09-29 11:28:34 -0400322 }
323 return 0;
324}
Steven Perroneb4653a2017-11-13 15:31:43 -0500325
326bool spvOpcodeIsDecoration(const SpvOp opcode) {
Steven Perron28c41552017-11-10 20:26:55 -0500327 switch (opcode) {
Steven Perroneb4653a2017-11-13 15:31:43 -0500328 case SpvOpDecorate:
329 case SpvOpDecorateId:
330 case SpvOpMemberDecorate:
331 case SpvOpGroupDecorate:
332 case SpvOpGroupMemberDecorate:
David Neto5f69f752018-03-05 13:34:13 -0500333 case SpvOpDecorateStringGOOGLE:
334 case SpvOpMemberDecorateStringGOOGLE:
Steven Perroneb4653a2017-11-13 15:31:43 -0500335 return true;
336 default:
337 break;
338 }
339 return false;
340}
Steven Perron28c41552017-11-10 20:26:55 -0500341
342bool spvOpcodeIsLoad(const SpvOp opcode) {
343 switch (opcode) {
344 case SpvOpLoad:
345 case SpvOpImageSampleExplicitLod:
346 case SpvOpImageSampleImplicitLod:
347 case SpvOpImageSampleDrefImplicitLod:
348 case SpvOpImageSampleDrefExplicitLod:
349 case SpvOpImageSampleProjImplicitLod:
350 case SpvOpImageSampleProjExplicitLod:
351 case SpvOpImageSampleProjDrefImplicitLod:
352 case SpvOpImageSampleProjDrefExplicitLod:
353 case SpvOpImageFetch:
354 case SpvOpImageGather:
355 case SpvOpImageDrefGather:
356 case SpvOpImageRead:
357 case SpvOpImageSparseSampleImplicitLod:
358 case SpvOpImageSparseSampleExplicitLod:
359 case SpvOpImageSparseSampleDrefExplicitLod:
360 case SpvOpImageSparseSampleDrefImplicitLod:
361 case SpvOpImageSparseFetch:
362 case SpvOpImageSparseGather:
363 case SpvOpImageSparseDrefGather:
364 case SpvOpImageSparseRead:
365 return true;
366 default:
367 return false;
368 }
369}
370
Diego Novillo74327842017-11-17 08:59:25 -0500371bool spvOpcodeIsBranch(SpvOp opcode) {
372 switch (opcode) {
373 case SpvOpBranch:
374 case SpvOpBranchConditional:
375 case SpvOpSwitch:
376 return true;
377 default:
378 return false;
379 }
380}
381
Steven Perron28c41552017-11-10 20:26:55 -0500382bool spvOpcodeIsAtomicOp(const SpvOp opcode) {
383 switch (opcode) {
384 case SpvOpAtomicLoad:
385 case SpvOpAtomicStore:
386 case SpvOpAtomicExchange:
387 case SpvOpAtomicCompareExchange:
388 case SpvOpAtomicCompareExchangeWeak:
389 case SpvOpAtomicIIncrement:
390 case SpvOpAtomicIDecrement:
391 case SpvOpAtomicIAdd:
392 case SpvOpAtomicISub:
393 case SpvOpAtomicSMin:
394 case SpvOpAtomicUMin:
395 case SpvOpAtomicSMax:
396 case SpvOpAtomicUMax:
397 case SpvOpAtomicAnd:
398 case SpvOpAtomicOr:
399 case SpvOpAtomicXor:
400 case SpvOpAtomicFlagTestAndSet:
401 case SpvOpAtomicFlagClear:
402 return true;
403 default:
404 return false;
405 }
406}
Diego Novillo74327842017-11-17 08:59:25 -0500407
408bool spvOpcodeIsReturn(SpvOp opcode) {
409 switch (opcode) {
410 case SpvOpReturn:
411 case SpvOpReturnValue:
412 return true;
413 default:
414 return false;
415 }
416}
417
Diego Novillo5f100782018-01-03 15:25:03 -0500418bool spvOpcodeIsReturnOrAbort(SpvOp opcode) {
419 return spvOpcodeIsReturn(opcode) || opcode == SpvOpKill ||
420 opcode == SpvOpUnreachable;
421}
422
Diego Novillo74327842017-11-17 08:59:25 -0500423bool spvOpcodeIsBlockTerminator(SpvOp opcode) {
Diego Novillo5f100782018-01-03 15:25:03 -0500424 return spvOpcodeIsBranch(opcode) || spvOpcodeIsReturnOrAbort(opcode);
Diego Novillo74327842017-11-17 08:59:25 -0500425}
Steven Perron79a00642017-12-11 13:10:24 -0500426
427bool spvOpcodeIsBaseOpaqueType(SpvOp opcode) {
428 switch (opcode) {
429 case SpvOpTypeImage:
430 case SpvOpTypeSampler:
431 case SpvOpTypeSampledImage:
432 case SpvOpTypeOpaque:
433 case SpvOpTypeEvent:
434 case SpvOpTypeDeviceEvent:
435 case SpvOpTypeReserveId:
436 case SpvOpTypeQueue:
437 case SpvOpTypePipe:
438 case SpvOpTypeForwardPointer:
439 case SpvOpTypePipeStorage:
440 case SpvOpTypeNamedBarrier:
441 return true;
442 default:
443 return false;
444 }
445}