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