opcode.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. #ifndef SOURCE_OPCODE_H_
  15. #define SOURCE_OPCODE_H_
  16. #include "source/instruction.h"
  17. #include "source/latest_version_spirv_header.h"
  18. #include "source/table.h"
  19. #include "spirv-tools/libspirv.h"
  20. // Returns the name of a registered SPIR-V generator as a null-terminated
  21. // string. If the generator is not known, then returns the string "Unknown".
  22. // The generator parameter should be most significant 16-bits of the generator
  23. // word in the SPIR-V module header.
  24. //
  25. // See the registry at https://www.khronos.org/registry/spir-v/api/spir-v.xml.
  26. const char* spvGeneratorStr(uint32_t generator);
  27. // Combines word_count and opcode enumerant in single word.
  28. uint32_t spvOpcodeMake(uint16_t word_count, SpvOp opcode);
  29. // Splits word into into two constituent parts: word_count and opcode.
  30. void spvOpcodeSplit(const uint32_t word, uint16_t* word_count,
  31. uint16_t* opcode);
  32. // Finds the named opcode in the given opcode table. On success, returns
  33. // SPV_SUCCESS and writes a handle of the table entry into *entry.
  34. spv_result_t spvOpcodeTableNameLookup(spv_target_env,
  35. const spv_opcode_table table,
  36. const char* name, spv_opcode_desc* entry);
  37. // Finds the opcode by enumerant in the given opcode table. On success, returns
  38. // SPV_SUCCESS and writes a handle of the table entry into *entry.
  39. spv_result_t spvOpcodeTableValueLookup(spv_target_env,
  40. const spv_opcode_table table,
  41. const SpvOp opcode,
  42. spv_opcode_desc* entry);
  43. // Copies an instruction's word and fixes the endianness to host native. The
  44. // source instruction's stream/opcode/endianness is in the words/opcode/endian
  45. // parameter. The word_count parameter specifies the number of words to copy.
  46. // Writes copied instruction into *inst.
  47. void spvInstructionCopy(const uint32_t* words, const SpvOp opcode,
  48. const uint16_t word_count,
  49. const spv_endianness_t endian, spv_instruction_t* inst);
  50. // Gets the name of an instruction, without the "Op" prefix.
  51. const char* spvOpcodeString(const SpvOp opcode);
  52. // Determine if the given opcode is a scalar type. Returns zero if false,
  53. // non-zero otherwise.
  54. int32_t spvOpcodeIsScalarType(const SpvOp opcode);
  55. // Determines if the given opcode is a specialization constant. Returns zero if
  56. // false, non-zero otherwise.
  57. int32_t spvOpcodeIsSpecConstant(const SpvOp opcode);
  58. // Determines if the given opcode is a constant. Returns zero if false, non-zero
  59. // otherwise.
  60. int32_t spvOpcodeIsConstant(const SpvOp opcode);
  61. // Returns true if the given opcode is a constant or undef.
  62. bool spvOpcodeIsConstantOrUndef(const SpvOp opcode);
  63. // Returns true if the given opcode is a scalar specialization constant.
  64. bool spvOpcodeIsScalarSpecConstant(const SpvOp opcode);
  65. // Determines if the given opcode is a composite type. Returns zero if false,
  66. // non-zero otherwise.
  67. int32_t spvOpcodeIsComposite(const SpvOp opcode);
  68. // Determines if the given opcode results in a pointer when using the logical
  69. // addressing model. Returns zero if false, non-zero otherwise.
  70. int32_t spvOpcodeReturnsLogicalPointer(const SpvOp opcode);
  71. // Returns whether the given opcode could result in a pointer or a variable
  72. // pointer when using the logical addressing model.
  73. bool spvOpcodeReturnsLogicalVariablePointer(const SpvOp opcode);
  74. // Determines if the given opcode generates a type. Returns zero if false,
  75. // non-zero otherwise.
  76. int32_t spvOpcodeGeneratesType(SpvOp opcode);
  77. // Returns true if the opcode adds a decoration to an id.
  78. bool spvOpcodeIsDecoration(const SpvOp opcode);
  79. // Returns true if the opcode is a load from memory into a result id. This
  80. // function only considers core instructions.
  81. bool spvOpcodeIsLoad(const SpvOp opcode);
  82. // Returns true if the opcode is an atomic operation that uses the original
  83. // value.
  84. bool spvOpcodeIsAtomicWithLoad(const SpvOp opcode);
  85. // Returns true if the opcode is an atomic operation.
  86. bool spvOpcodeIsAtomicOp(const SpvOp opcode);
  87. // Returns true if the given opcode is a branch instruction.
  88. bool spvOpcodeIsBranch(SpvOp opcode);
  89. // Returns true if the given opcode is a return instruction.
  90. bool spvOpcodeIsReturn(SpvOp opcode);
  91. // Returns true if the given opcode is a return instruction or it aborts
  92. // execution.
  93. bool spvOpcodeIsReturnOrAbort(SpvOp opcode);
  94. // Returns true if the given opcode is a basic block terminator.
  95. bool spvOpcodeIsBlockTerminator(SpvOp opcode);
  96. // Returns true if the given opcode always defines an opaque type.
  97. bool spvOpcodeIsBaseOpaqueType(SpvOp opcode);
  98. // Returns true if the given opcode is a non-uniform group operation.
  99. bool spvOpcodeIsNonUniformGroupOperation(SpvOp opcode);
  100. // Returns true if the opcode with vector inputs could be divided into a series
  101. // of independent scalar operations that would give the same result.
  102. bool spvOpcodeIsScalarizable(SpvOp opcode);
  103. // Returns true if the given opcode is a debug instruction.
  104. bool spvOpcodeIsDebug(SpvOp opcode);
  105. #endif // SOURCE_OPCODE_H_