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 15 #ifndef SOURCE_OPT_REFLECT_H_ 16 #define SOURCE_OPT_REFLECT_H_ 17 18 #include "source/latest_version_spirv_header.h" 19 20 namespace spvtools { 21 namespace opt { 22 23 // Note that as SPIR-V evolves over time, new opcodes may appear. So the 24 // following functions tend to be outdated and should be updated when SPIR-V 25 // version bumps. 26 IsDebug1Inst(spv::Op opcode)27inline bool IsDebug1Inst(spv::Op opcode) { 28 return (opcode >= spv::Op::OpSourceContinued && 29 opcode <= spv::Op::OpSourceExtension) || 30 opcode == spv::Op::OpString; 31 } IsDebug2Inst(spv::Op opcode)32inline bool IsDebug2Inst(spv::Op opcode) { 33 return opcode == spv::Op::OpName || opcode == spv::Op::OpMemberName; 34 } IsDebug3Inst(spv::Op opcode)35inline bool IsDebug3Inst(spv::Op opcode) { 36 return opcode == spv::Op::OpModuleProcessed; 37 } IsOpLineInst(spv::Op opcode)38inline bool IsOpLineInst(spv::Op opcode) { 39 return opcode == spv::Op::OpLine || opcode == spv::Op::OpNoLine; 40 } IsAnnotationInst(spv::Op opcode)41inline bool IsAnnotationInst(spv::Op opcode) { 42 return (opcode >= spv::Op::OpDecorate && 43 opcode <= spv::Op::OpGroupMemberDecorate) || 44 opcode == spv::Op::OpDecorateId || 45 opcode == spv::Op::OpDecorateStringGOOGLE || 46 opcode == spv::Op::OpMemberDecorateStringGOOGLE; 47 } IsTypeInst(spv::Op opcode)48inline bool IsTypeInst(spv::Op opcode) { 49 return (opcode >= spv::Op::OpTypeVoid && 50 opcode <= spv::Op::OpTypeForwardPointer) || 51 opcode == spv::Op::OpTypePipeStorage || 52 opcode == spv::Op::OpTypeNamedBarrier || 53 opcode == spv::Op::OpTypeAccelerationStructureNV || 54 opcode == spv::Op::OpTypeAccelerationStructureKHR || 55 opcode == spv::Op::OpTypeRayQueryKHR || 56 opcode == spv::Op::OpTypeCooperativeMatrixNV || 57 opcode == spv::Op::OpTypeHitObjectNV; 58 } IsConstantInst(spv::Op opcode)59inline bool IsConstantInst(spv::Op opcode) { 60 return (opcode >= spv::Op::OpConstantTrue && 61 opcode <= spv::Op::OpSpecConstantOp) || 62 opcode == spv::Op::OpConstantFunctionPointerINTEL; 63 } IsCompileTimeConstantInst(spv::Op opcode)64inline bool IsCompileTimeConstantInst(spv::Op opcode) { 65 return opcode >= spv::Op::OpConstantTrue && opcode <= spv::Op::OpConstantNull; 66 } IsSpecConstantInst(spv::Op opcode)67inline bool IsSpecConstantInst(spv::Op opcode) { 68 return opcode >= spv::Op::OpSpecConstantTrue && 69 opcode <= spv::Op::OpSpecConstantOp; 70 } 71 72 } // namespace opt 73 } // namespace spvtools 74 75 #endif // SOURCE_OPT_REFLECT_H_ 76