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(SpvOp opcode)27inline bool IsDebug1Inst(SpvOp opcode) { 28 return (opcode >= SpvOpSourceContinued && opcode <= SpvOpSourceExtension) || 29 opcode == SpvOpString; 30 } IsDebug2Inst(SpvOp opcode)31inline bool IsDebug2Inst(SpvOp opcode) { 32 return opcode == SpvOpName || opcode == SpvOpMemberName; 33 } IsDebug3Inst(SpvOp opcode)34inline bool IsDebug3Inst(SpvOp opcode) { 35 return opcode == SpvOpModuleProcessed; 36 } IsDebugLineInst(SpvOp opcode)37inline bool IsDebugLineInst(SpvOp opcode) { 38 return opcode == SpvOpLine || opcode == SpvOpNoLine; 39 } IsAnnotationInst(SpvOp opcode)40inline bool IsAnnotationInst(SpvOp opcode) { 41 return (opcode >= SpvOpDecorate && opcode <= SpvOpGroupMemberDecorate) || 42 opcode == SpvOpDecorateId || opcode == SpvOpDecorateStringGOOGLE || 43 opcode == SpvOpMemberDecorateStringGOOGLE; 44 } IsTypeInst(SpvOp opcode)45inline bool IsTypeInst(SpvOp opcode) { 46 return (opcode >= SpvOpTypeVoid && opcode <= SpvOpTypeForwardPointer) || 47 opcode == SpvOpTypePipeStorage || opcode == SpvOpTypeNamedBarrier || 48 opcode == SpvOpTypeAccelerationStructureNV || 49 opcode == SpvOpTypeAccelerationStructureKHR || 50 opcode == SpvOpTypeRayQueryKHR || 51 opcode == SpvOpTypeCooperativeMatrixNV; 52 } IsConstantInst(SpvOp opcode)53inline bool IsConstantInst(SpvOp opcode) { 54 return opcode >= SpvOpConstantTrue && opcode <= SpvOpSpecConstantOp; 55 } IsCompileTimeConstantInst(SpvOp opcode)56inline bool IsCompileTimeConstantInst(SpvOp opcode) { 57 return opcode >= SpvOpConstantTrue && opcode <= SpvOpConstantNull; 58 } IsSpecConstantInst(SpvOp opcode)59inline bool IsSpecConstantInst(SpvOp opcode) { 60 return opcode >= SpvOpSpecConstantTrue && opcode <= SpvOpSpecConstantOp; 61 } 62 63 } // namespace opt 64 } // namespace spvtools 65 66 #endif // SOURCE_OPT_REFLECT_H_ 67