reflect.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright (c) 2016 Google 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_OPT_REFLECT_H_
  15. #define SOURCE_OPT_REFLECT_H_
  16. #include "source/latest_version_spirv_header.h"
  17. namespace spvtools {
  18. namespace opt {
  19. // Note that as SPIR-V evolves over time, new opcodes may appear. So the
  20. // following functions tend to be outdated and should be updated when SPIR-V
  21. // version bumps.
  22. inline bool IsDebug1Inst(SpvOp opcode) {
  23. return (opcode >= SpvOpSourceContinued && opcode <= SpvOpSourceExtension) ||
  24. opcode == SpvOpString;
  25. }
  26. inline bool IsDebug2Inst(SpvOp opcode) {
  27. return opcode == SpvOpName || opcode == SpvOpMemberName;
  28. }
  29. inline bool IsDebug3Inst(SpvOp opcode) {
  30. return opcode == SpvOpModuleProcessed;
  31. }
  32. inline bool IsDebugLineInst(SpvOp opcode) {
  33. return opcode == SpvOpLine || opcode == SpvOpNoLine;
  34. }
  35. inline bool IsAnnotationInst(SpvOp opcode) {
  36. return (opcode >= SpvOpDecorate && opcode <= SpvOpGroupMemberDecorate) ||
  37. opcode == SpvOpDecorateId || opcode == SpvOpDecorateStringGOOGLE ||
  38. opcode == SpvOpMemberDecorateStringGOOGLE;
  39. }
  40. inline bool IsTypeInst(SpvOp opcode) {
  41. return (opcode >= SpvOpTypeVoid && opcode <= SpvOpTypeForwardPointer) ||
  42. opcode == SpvOpTypePipeStorage || opcode == SpvOpTypeNamedBarrier ||
  43. opcode == SpvOpTypeAccelerationStructureNV ||
  44. opcode == SpvOpTypeAccelerationStructureKHR ||
  45. opcode == SpvOpTypeRayQueryKHR ||
  46. opcode == SpvOpTypeCooperativeMatrixNV;
  47. }
  48. inline bool IsConstantInst(SpvOp opcode) {
  49. return opcode >= SpvOpConstantTrue && opcode <= SpvOpSpecConstantOp;
  50. }
  51. inline bool IsCompileTimeConstantInst(SpvOp opcode) {
  52. return opcode >= SpvOpConstantTrue && opcode <= SpvOpConstantNull;
  53. }
  54. inline bool IsSpecConstantInst(SpvOp opcode) {
  55. return opcode >= SpvOpSpecConstantTrue && opcode <= SpvOpSpecConstantOp;
  56. }
  57. } // namespace opt
  58. } // namespace spvtools
  59. #endif // SOURCE_OPT_REFLECT_H_