opcode.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. // Copyright (c) 2015-2016 The Khronos Group Inc.
  2. //
  3. // 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
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // 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.
  14. #include "source/opcode.h"
  15. #include <assert.h>
  16. #include <string.h>
  17. #include <algorithm>
  18. #include <cstdlib>
  19. #include "source/instruction.h"
  20. #include "source/macro.h"
  21. #include "source/spirv_constant.h"
  22. #include "source/spirv_endian.h"
  23. #include "source/spirv_target_env.h"
  24. #include "spirv-tools/libspirv.h"
  25. namespace {
  26. struct OpcodeDescPtrLen {
  27. const spv_opcode_desc_t* ptr;
  28. uint32_t len;
  29. };
  30. #include "core.insts-unified1.inc"
  31. static const spv_opcode_table_t kOpcodeTable = {ARRAY_SIZE(kOpcodeTableEntries),
  32. kOpcodeTableEntries};
  33. // Represents a vendor tool entry in the SPIR-V XML Regsitry.
  34. struct VendorTool {
  35. uint32_t value;
  36. const char* vendor;
  37. const char* tool; // Might be empty string.
  38. const char* vendor_tool; // Combiantion of vendor and tool.
  39. };
  40. const VendorTool vendor_tools[] = {
  41. #include "generators.inc"
  42. };
  43. } // anonymous namespace
  44. // TODO(dneto): Move this to another file. It doesn't belong with opcode
  45. // processing.
  46. const char* spvGeneratorStr(uint32_t generator) {
  47. auto where = std::find_if(
  48. std::begin(vendor_tools), std::end(vendor_tools),
  49. [generator](const VendorTool& vt) { return generator == vt.value; });
  50. if (where != std::end(vendor_tools)) return where->vendor_tool;
  51. return "Unknown";
  52. }
  53. uint32_t spvOpcodeMake(uint16_t wordCount, SpvOp opcode) {
  54. return ((uint32_t)opcode) | (((uint32_t)wordCount) << 16);
  55. }
  56. void spvOpcodeSplit(const uint32_t word, uint16_t* pWordCount,
  57. uint16_t* pOpcode) {
  58. if (pWordCount) {
  59. *pWordCount = (uint16_t)((0xffff0000 & word) >> 16);
  60. }
  61. if (pOpcode) {
  62. *pOpcode = 0x0000ffff & word;
  63. }
  64. }
  65. spv_result_t spvOpcodeTableGet(spv_opcode_table* pInstTable, spv_target_env) {
  66. if (!pInstTable) return SPV_ERROR_INVALID_POINTER;
  67. // Descriptions of each opcode. Each entry describes the format of the
  68. // instruction that follows a particular opcode.
  69. *pInstTable = &kOpcodeTable;
  70. return SPV_SUCCESS;
  71. }
  72. spv_result_t spvOpcodeTableNameLookup(spv_target_env env,
  73. const spv_opcode_table table,
  74. const char* name,
  75. spv_opcode_desc* pEntry) {
  76. if (!name || !pEntry) return SPV_ERROR_INVALID_POINTER;
  77. if (!table) return SPV_ERROR_INVALID_TABLE;
  78. // TODO: This lookup of the Opcode table is suboptimal! Binary sort would be
  79. // preferable but the table requires sorting on the Opcode name, but it's
  80. // static const initialized and matches the order of the spec.
  81. const size_t nameLength = strlen(name);
  82. const auto version = spvVersionForTargetEnv(env);
  83. for (uint64_t opcodeIndex = 0; opcodeIndex < table->count; ++opcodeIndex) {
  84. const spv_opcode_desc_t& entry = table->entries[opcodeIndex];
  85. // We considers the current opcode as available as long as
  86. // 1. The target environment satisfies the minimal requirement of the
  87. // opcode; or
  88. // 2. There is at least one extension enabling this opcode.
  89. //
  90. // Note that the second rule assumes the extension enabling this instruction
  91. // is indeed requested in the SPIR-V code; checking that should be
  92. // validator's work.
  93. if (((version >= entry.minVersion && version <= entry.lastVersion) ||
  94. entry.numExtensions > 0u || entry.numCapabilities > 0u) &&
  95. nameLength == strlen(entry.name) &&
  96. !strncmp(name, entry.name, nameLength)) {
  97. // NOTE: Found out Opcode!
  98. *pEntry = &entry;
  99. return SPV_SUCCESS;
  100. }
  101. }
  102. return SPV_ERROR_INVALID_LOOKUP;
  103. }
  104. spv_result_t spvOpcodeTableValueLookup(spv_target_env env,
  105. const spv_opcode_table table,
  106. const SpvOp opcode,
  107. spv_opcode_desc* pEntry) {
  108. if (!table) return SPV_ERROR_INVALID_TABLE;
  109. if (!pEntry) return SPV_ERROR_INVALID_POINTER;
  110. const auto beg = table->entries;
  111. const auto end = table->entries + table->count;
  112. spv_opcode_desc_t needle = {"", opcode, 0, nullptr, 0, {},
  113. false, false, 0, nullptr, ~0u, ~0u};
  114. auto comp = [](const spv_opcode_desc_t& lhs, const spv_opcode_desc_t& rhs) {
  115. return lhs.opcode < rhs.opcode;
  116. };
  117. // We need to loop here because there can exist multiple symbols for the same
  118. // opcode value, and they can be introduced in different target environments,
  119. // which means they can have different minimal version requirements.
  120. // Assumes the underlying table is already sorted ascendingly according to
  121. // opcode value.
  122. const auto version = spvVersionForTargetEnv(env);
  123. for (auto it = std::lower_bound(beg, end, needle, comp);
  124. it != end && it->opcode == opcode; ++it) {
  125. // We considers the current opcode as available as long as
  126. // 1. The target environment satisfies the minimal requirement of the
  127. // opcode; or
  128. // 2. There is at least one extension enabling this opcode.
  129. //
  130. // Note that the second rule assumes the extension enabling this instruction
  131. // is indeed requested in the SPIR-V code; checking that should be
  132. // validator's work.
  133. if ((version >= it->minVersion && version <= it->lastVersion) ||
  134. it->numExtensions > 0u || it->numCapabilities > 0u) {
  135. *pEntry = it;
  136. return SPV_SUCCESS;
  137. }
  138. }
  139. return SPV_ERROR_INVALID_LOOKUP;
  140. }
  141. void spvInstructionCopy(const uint32_t* words, const SpvOp opcode,
  142. const uint16_t wordCount, const spv_endianness_t endian,
  143. spv_instruction_t* pInst) {
  144. pInst->opcode = opcode;
  145. pInst->words.resize(wordCount);
  146. for (uint16_t wordIndex = 0; wordIndex < wordCount; ++wordIndex) {
  147. pInst->words[wordIndex] = spvFixWord(words[wordIndex], endian);
  148. if (!wordIndex) {
  149. uint16_t thisWordCount;
  150. uint16_t thisOpcode;
  151. spvOpcodeSplit(pInst->words[wordIndex], &thisWordCount, &thisOpcode);
  152. assert(opcode == static_cast<SpvOp>(thisOpcode) &&
  153. wordCount == thisWordCount && "Endianness failed!");
  154. }
  155. }
  156. }
  157. const char* spvOpcodeString(const SpvOp opcode) {
  158. const auto beg = kOpcodeTableEntries;
  159. const auto end = kOpcodeTableEntries + ARRAY_SIZE(kOpcodeTableEntries);
  160. spv_opcode_desc_t needle = {"", opcode, 0, nullptr, 0, {},
  161. false, false, 0, nullptr, ~0u, ~0u};
  162. auto comp = [](const spv_opcode_desc_t& lhs, const spv_opcode_desc_t& rhs) {
  163. return lhs.opcode < rhs.opcode;
  164. };
  165. auto it = std::lower_bound(beg, end, needle, comp);
  166. if (it != end && it->opcode == opcode) {
  167. return it->name;
  168. }
  169. assert(0 && "Unreachable!");
  170. return "unknown";
  171. }
  172. int32_t spvOpcodeIsScalarType(const SpvOp opcode) {
  173. switch (opcode) {
  174. case SpvOpTypeInt:
  175. case SpvOpTypeFloat:
  176. case SpvOpTypeBool:
  177. return true;
  178. default:
  179. return false;
  180. }
  181. }
  182. int32_t spvOpcodeIsSpecConstant(const SpvOp opcode) {
  183. switch (opcode) {
  184. case SpvOpSpecConstantTrue:
  185. case SpvOpSpecConstantFalse:
  186. case SpvOpSpecConstant:
  187. case SpvOpSpecConstantComposite:
  188. case SpvOpSpecConstantOp:
  189. return true;
  190. default:
  191. return false;
  192. }
  193. }
  194. int32_t spvOpcodeIsConstant(const SpvOp opcode) {
  195. switch (opcode) {
  196. case SpvOpConstantTrue:
  197. case SpvOpConstantFalse:
  198. case SpvOpConstant:
  199. case SpvOpConstantComposite:
  200. case SpvOpConstantSampler:
  201. case SpvOpConstantNull:
  202. case SpvOpSpecConstantTrue:
  203. case SpvOpSpecConstantFalse:
  204. case SpvOpSpecConstant:
  205. case SpvOpSpecConstantComposite:
  206. case SpvOpSpecConstantOp:
  207. return true;
  208. default:
  209. return false;
  210. }
  211. }
  212. bool spvOpcodeIsConstantOrUndef(const SpvOp opcode) {
  213. return opcode == SpvOpUndef || spvOpcodeIsConstant(opcode);
  214. }
  215. bool spvOpcodeIsScalarSpecConstant(const SpvOp opcode) {
  216. switch (opcode) {
  217. case SpvOpSpecConstantTrue:
  218. case SpvOpSpecConstantFalse:
  219. case SpvOpSpecConstant:
  220. return true;
  221. default:
  222. return false;
  223. }
  224. }
  225. int32_t spvOpcodeIsComposite(const SpvOp opcode) {
  226. switch (opcode) {
  227. case SpvOpTypeVector:
  228. case SpvOpTypeMatrix:
  229. case SpvOpTypeArray:
  230. case SpvOpTypeStruct:
  231. case SpvOpTypeCooperativeMatrixNV:
  232. return true;
  233. default:
  234. return false;
  235. }
  236. }
  237. bool spvOpcodeReturnsLogicalVariablePointer(const SpvOp opcode) {
  238. switch (opcode) {
  239. case SpvOpVariable:
  240. case SpvOpAccessChain:
  241. case SpvOpInBoundsAccessChain:
  242. case SpvOpFunctionParameter:
  243. case SpvOpImageTexelPointer:
  244. case SpvOpCopyObject:
  245. case SpvOpSelect:
  246. case SpvOpPhi:
  247. case SpvOpFunctionCall:
  248. case SpvOpPtrAccessChain:
  249. case SpvOpLoad:
  250. case SpvOpConstantNull:
  251. return true;
  252. default:
  253. return false;
  254. }
  255. }
  256. int32_t spvOpcodeReturnsLogicalPointer(const SpvOp opcode) {
  257. switch (opcode) {
  258. case SpvOpVariable:
  259. case SpvOpAccessChain:
  260. case SpvOpInBoundsAccessChain:
  261. case SpvOpFunctionParameter:
  262. case SpvOpImageTexelPointer:
  263. case SpvOpCopyObject:
  264. return true;
  265. default:
  266. return false;
  267. }
  268. }
  269. int32_t spvOpcodeGeneratesType(SpvOp op) {
  270. switch (op) {
  271. case SpvOpTypeVoid:
  272. case SpvOpTypeBool:
  273. case SpvOpTypeInt:
  274. case SpvOpTypeFloat:
  275. case SpvOpTypeVector:
  276. case SpvOpTypeMatrix:
  277. case SpvOpTypeImage:
  278. case SpvOpTypeSampler:
  279. case SpvOpTypeSampledImage:
  280. case SpvOpTypeArray:
  281. case SpvOpTypeRuntimeArray:
  282. case SpvOpTypeStruct:
  283. case SpvOpTypeOpaque:
  284. case SpvOpTypePointer:
  285. case SpvOpTypeFunction:
  286. case SpvOpTypeEvent:
  287. case SpvOpTypeDeviceEvent:
  288. case SpvOpTypeReserveId:
  289. case SpvOpTypeQueue:
  290. case SpvOpTypePipe:
  291. case SpvOpTypePipeStorage:
  292. case SpvOpTypeNamedBarrier:
  293. case SpvOpTypeAccelerationStructureNV:
  294. case SpvOpTypeCooperativeMatrixNV:
  295. return true;
  296. default:
  297. // In particular, OpTypeForwardPointer does not generate a type,
  298. // but declares a storage class for a pointer type generated
  299. // by a different instruction.
  300. break;
  301. }
  302. return 0;
  303. }
  304. bool spvOpcodeIsDecoration(const SpvOp opcode) {
  305. switch (opcode) {
  306. case SpvOpDecorate:
  307. case SpvOpDecorateId:
  308. case SpvOpMemberDecorate:
  309. case SpvOpGroupDecorate:
  310. case SpvOpGroupMemberDecorate:
  311. case SpvOpDecorateStringGOOGLE:
  312. case SpvOpMemberDecorateStringGOOGLE:
  313. return true;
  314. default:
  315. break;
  316. }
  317. return false;
  318. }
  319. bool spvOpcodeIsLoad(const SpvOp opcode) {
  320. switch (opcode) {
  321. case SpvOpLoad:
  322. case SpvOpImageSampleExplicitLod:
  323. case SpvOpImageSampleImplicitLod:
  324. case SpvOpImageSampleDrefImplicitLod:
  325. case SpvOpImageSampleDrefExplicitLod:
  326. case SpvOpImageSampleProjImplicitLod:
  327. case SpvOpImageSampleProjExplicitLod:
  328. case SpvOpImageSampleProjDrefImplicitLod:
  329. case SpvOpImageSampleProjDrefExplicitLod:
  330. case SpvOpImageFetch:
  331. case SpvOpImageGather:
  332. case SpvOpImageDrefGather:
  333. case SpvOpImageRead:
  334. case SpvOpImageSparseSampleImplicitLod:
  335. case SpvOpImageSparseSampleExplicitLod:
  336. case SpvOpImageSparseSampleDrefExplicitLod:
  337. case SpvOpImageSparseSampleDrefImplicitLod:
  338. case SpvOpImageSparseFetch:
  339. case SpvOpImageSparseGather:
  340. case SpvOpImageSparseDrefGather:
  341. case SpvOpImageSparseRead:
  342. return true;
  343. default:
  344. return false;
  345. }
  346. }
  347. bool spvOpcodeIsBranch(SpvOp opcode) {
  348. switch (opcode) {
  349. case SpvOpBranch:
  350. case SpvOpBranchConditional:
  351. case SpvOpSwitch:
  352. return true;
  353. default:
  354. return false;
  355. }
  356. }
  357. bool spvOpcodeIsAtomicWithLoad(const SpvOp opcode) {
  358. switch (opcode) {
  359. case SpvOpAtomicLoad:
  360. case SpvOpAtomicExchange:
  361. case SpvOpAtomicCompareExchange:
  362. case SpvOpAtomicCompareExchangeWeak:
  363. case SpvOpAtomicIIncrement:
  364. case SpvOpAtomicIDecrement:
  365. case SpvOpAtomicIAdd:
  366. case SpvOpAtomicISub:
  367. case SpvOpAtomicSMin:
  368. case SpvOpAtomicUMin:
  369. case SpvOpAtomicSMax:
  370. case SpvOpAtomicUMax:
  371. case SpvOpAtomicAnd:
  372. case SpvOpAtomicOr:
  373. case SpvOpAtomicXor:
  374. case SpvOpAtomicFlagTestAndSet:
  375. return true;
  376. default:
  377. return false;
  378. }
  379. }
  380. bool spvOpcodeIsAtomicOp(const SpvOp opcode) {
  381. return (spvOpcodeIsAtomicWithLoad(opcode) || opcode == SpvOpAtomicStore ||
  382. opcode == SpvOpAtomicFlagClear);
  383. }
  384. bool spvOpcodeIsReturn(SpvOp opcode) {
  385. switch (opcode) {
  386. case SpvOpReturn:
  387. case SpvOpReturnValue:
  388. return true;
  389. default:
  390. return false;
  391. }
  392. }
  393. bool spvOpcodeIsReturnOrAbort(SpvOp opcode) {
  394. return spvOpcodeIsReturn(opcode) || opcode == SpvOpKill ||
  395. opcode == SpvOpUnreachable;
  396. }
  397. bool spvOpcodeIsBlockTerminator(SpvOp opcode) {
  398. return spvOpcodeIsBranch(opcode) || spvOpcodeIsReturnOrAbort(opcode);
  399. }
  400. bool spvOpcodeIsBaseOpaqueType(SpvOp opcode) {
  401. switch (opcode) {
  402. case SpvOpTypeImage:
  403. case SpvOpTypeSampler:
  404. case SpvOpTypeSampledImage:
  405. case SpvOpTypeOpaque:
  406. case SpvOpTypeEvent:
  407. case SpvOpTypeDeviceEvent:
  408. case SpvOpTypeReserveId:
  409. case SpvOpTypeQueue:
  410. case SpvOpTypePipe:
  411. case SpvOpTypeForwardPointer:
  412. case SpvOpTypePipeStorage:
  413. case SpvOpTypeNamedBarrier:
  414. return true;
  415. default:
  416. return false;
  417. }
  418. }
  419. bool spvOpcodeIsNonUniformGroupOperation(SpvOp opcode) {
  420. switch (opcode) {
  421. case SpvOpGroupNonUniformElect:
  422. case SpvOpGroupNonUniformAll:
  423. case SpvOpGroupNonUniformAny:
  424. case SpvOpGroupNonUniformAllEqual:
  425. case SpvOpGroupNonUniformBroadcast:
  426. case SpvOpGroupNonUniformBroadcastFirst:
  427. case SpvOpGroupNonUniformBallot:
  428. case SpvOpGroupNonUniformInverseBallot:
  429. case SpvOpGroupNonUniformBallotBitExtract:
  430. case SpvOpGroupNonUniformBallotBitCount:
  431. case SpvOpGroupNonUniformBallotFindLSB:
  432. case SpvOpGroupNonUniformBallotFindMSB:
  433. case SpvOpGroupNonUniformShuffle:
  434. case SpvOpGroupNonUniformShuffleXor:
  435. case SpvOpGroupNonUniformShuffleUp:
  436. case SpvOpGroupNonUniformShuffleDown:
  437. case SpvOpGroupNonUniformIAdd:
  438. case SpvOpGroupNonUniformFAdd:
  439. case SpvOpGroupNonUniformIMul:
  440. case SpvOpGroupNonUniformFMul:
  441. case SpvOpGroupNonUniformSMin:
  442. case SpvOpGroupNonUniformUMin:
  443. case SpvOpGroupNonUniformFMin:
  444. case SpvOpGroupNonUniformSMax:
  445. case SpvOpGroupNonUniformUMax:
  446. case SpvOpGroupNonUniformFMax:
  447. case SpvOpGroupNonUniformBitwiseAnd:
  448. case SpvOpGroupNonUniformBitwiseOr:
  449. case SpvOpGroupNonUniformBitwiseXor:
  450. case SpvOpGroupNonUniformLogicalAnd:
  451. case SpvOpGroupNonUniformLogicalOr:
  452. case SpvOpGroupNonUniformLogicalXor:
  453. case SpvOpGroupNonUniformQuadBroadcast:
  454. case SpvOpGroupNonUniformQuadSwap:
  455. return true;
  456. default:
  457. return false;
  458. }
  459. }
  460. bool spvOpcodeIsScalarizable(SpvOp opcode) {
  461. switch (opcode) {
  462. case SpvOpPhi:
  463. case SpvOpCopyObject:
  464. case SpvOpConvertFToU:
  465. case SpvOpConvertFToS:
  466. case SpvOpConvertSToF:
  467. case SpvOpConvertUToF:
  468. case SpvOpUConvert:
  469. case SpvOpSConvert:
  470. case SpvOpFConvert:
  471. case SpvOpQuantizeToF16:
  472. case SpvOpVectorInsertDynamic:
  473. case SpvOpSNegate:
  474. case SpvOpFNegate:
  475. case SpvOpIAdd:
  476. case SpvOpFAdd:
  477. case SpvOpISub:
  478. case SpvOpFSub:
  479. case SpvOpIMul:
  480. case SpvOpFMul:
  481. case SpvOpUDiv:
  482. case SpvOpSDiv:
  483. case SpvOpFDiv:
  484. case SpvOpUMod:
  485. case SpvOpSRem:
  486. case SpvOpSMod:
  487. case SpvOpFRem:
  488. case SpvOpFMod:
  489. case SpvOpVectorTimesScalar:
  490. case SpvOpIAddCarry:
  491. case SpvOpISubBorrow:
  492. case SpvOpUMulExtended:
  493. case SpvOpSMulExtended:
  494. case SpvOpShiftRightLogical:
  495. case SpvOpShiftRightArithmetic:
  496. case SpvOpShiftLeftLogical:
  497. case SpvOpBitwiseOr:
  498. case SpvOpBitwiseAnd:
  499. case SpvOpNot:
  500. case SpvOpBitFieldInsert:
  501. case SpvOpBitFieldSExtract:
  502. case SpvOpBitFieldUExtract:
  503. case SpvOpBitReverse:
  504. case SpvOpBitCount:
  505. case SpvOpIsNan:
  506. case SpvOpIsInf:
  507. case SpvOpIsFinite:
  508. case SpvOpIsNormal:
  509. case SpvOpSignBitSet:
  510. case SpvOpLessOrGreater:
  511. case SpvOpOrdered:
  512. case SpvOpUnordered:
  513. case SpvOpLogicalEqual:
  514. case SpvOpLogicalNotEqual:
  515. case SpvOpLogicalOr:
  516. case SpvOpLogicalAnd:
  517. case SpvOpLogicalNot:
  518. case SpvOpSelect:
  519. case SpvOpIEqual:
  520. case SpvOpINotEqual:
  521. case SpvOpUGreaterThan:
  522. case SpvOpSGreaterThan:
  523. case SpvOpUGreaterThanEqual:
  524. case SpvOpSGreaterThanEqual:
  525. case SpvOpULessThan:
  526. case SpvOpSLessThan:
  527. case SpvOpULessThanEqual:
  528. case SpvOpSLessThanEqual:
  529. case SpvOpFOrdEqual:
  530. case SpvOpFUnordEqual:
  531. case SpvOpFOrdNotEqual:
  532. case SpvOpFUnordNotEqual:
  533. case SpvOpFOrdLessThan:
  534. case SpvOpFUnordLessThan:
  535. case SpvOpFOrdGreaterThan:
  536. case SpvOpFUnordGreaterThan:
  537. case SpvOpFOrdLessThanEqual:
  538. case SpvOpFUnordLessThanEqual:
  539. case SpvOpFOrdGreaterThanEqual:
  540. case SpvOpFUnordGreaterThanEqual:
  541. return true;
  542. default:
  543. return false;
  544. }
  545. }
  546. bool spvOpcodeIsDebug(SpvOp opcode) {
  547. switch (opcode) {
  548. case SpvOpName:
  549. case SpvOpMemberName:
  550. case SpvOpSource:
  551. case SpvOpSourceContinued:
  552. case SpvOpSourceExtension:
  553. case SpvOpString:
  554. case SpvOpLine:
  555. case SpvOpNoLine:
  556. return true;
  557. default:
  558. return false;
  559. }
  560. }
  561. std::vector<uint32_t> spvOpcodeMemorySemanticsOperandIndices(SpvOp opcode) {
  562. switch (opcode) {
  563. case SpvOpMemoryBarrier:
  564. return {1};
  565. case SpvOpAtomicStore:
  566. case SpvOpControlBarrier:
  567. case SpvOpAtomicFlagClear:
  568. case SpvOpMemoryNamedBarrier:
  569. return {2};
  570. case SpvOpAtomicLoad:
  571. case SpvOpAtomicExchange:
  572. case SpvOpAtomicIIncrement:
  573. case SpvOpAtomicIDecrement:
  574. case SpvOpAtomicIAdd:
  575. case SpvOpAtomicISub:
  576. case SpvOpAtomicSMin:
  577. case SpvOpAtomicUMin:
  578. case SpvOpAtomicSMax:
  579. case SpvOpAtomicUMax:
  580. case SpvOpAtomicAnd:
  581. case SpvOpAtomicOr:
  582. case SpvOpAtomicXor:
  583. case SpvOpAtomicFlagTestAndSet:
  584. return {4};
  585. case SpvOpAtomicCompareExchange:
  586. case SpvOpAtomicCompareExchangeWeak:
  587. return {4, 5};
  588. default:
  589. return {};
  590. }
  591. }