reflect.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #include "source/opcode.h"
  18. namespace spvtools {
  19. namespace opt {
  20. // Note that as SPIR-V evolves over time, new opcodes may appear. So the
  21. // following functions tend to be outdated and should be updated when SPIR-V
  22. // version bumps.
  23. inline bool IsDebug1Inst(spv::Op opcode) {
  24. return (opcode >= spv::Op::OpSourceContinued &&
  25. opcode <= spv::Op::OpSourceExtension) ||
  26. opcode == spv::Op::OpString;
  27. }
  28. inline bool IsDebug2Inst(spv::Op opcode) {
  29. return opcode == spv::Op::OpName || opcode == spv::Op::OpMemberName;
  30. }
  31. inline bool IsDebug3Inst(spv::Op opcode) {
  32. return opcode == spv::Op::OpModuleProcessed;
  33. }
  34. inline bool IsOpLineInst(spv::Op opcode) {
  35. return opcode == spv::Op::OpLine || opcode == spv::Op::OpNoLine;
  36. }
  37. inline bool IsAnnotationInst(spv::Op opcode) {
  38. return (opcode >= spv::Op::OpDecorate &&
  39. opcode <= spv::Op::OpGroupMemberDecorate) ||
  40. opcode == spv::Op::OpDecorateId ||
  41. opcode == spv::Op::OpDecorateStringGOOGLE ||
  42. opcode == spv::Op::OpMemberDecorateStringGOOGLE;
  43. }
  44. inline bool IsTypeInst(spv::Op opcode) {
  45. return spvOpcodeGeneratesType(opcode) ||
  46. opcode == spv::Op::OpTypeForwardPointer;
  47. }
  48. inline bool IsConstantInst(spv::Op opcode) {
  49. return spvOpcodeIsConstant(opcode);
  50. }
  51. inline bool IsSpecConstantInst(spv::Op opcode) {
  52. return spvOpcodeIsSpecConstant(opcode);
  53. }
  54. } // namespace opt
  55. } // namespace spvtools
  56. #endif // SOURCE_OPT_REFLECT_H_