• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 LIBSPIRV_OPT_REFLECT_H_
16 #define LIBSPIRV_OPT_REFLECT_H_
17 
18 #include "spirv/1.2/spirv.h"
19 
20 namespace spvtools {
21 namespace ir {
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 
IsDebugInst(SpvOp opcode)27 inline bool IsDebugInst(SpvOp opcode) {
28   return (opcode >= SpvOpSourceContinued && opcode <= SpvOpLine) ||
29          opcode == SpvOpNoLine || opcode == SpvOpModuleProcessed;
30 }
IsDebugLineInst(SpvOp opcode)31 inline bool IsDebugLineInst(SpvOp opcode) {
32   return opcode == SpvOpLine || opcode == SpvOpNoLine;
33 }
IsAnnotationInst(SpvOp opcode)34 inline bool IsAnnotationInst(SpvOp opcode) {
35   return opcode >= SpvOpDecorate && opcode <= SpvOpGroupMemberDecorate;
36 }
IsTypeInst(SpvOp opcode)37 inline bool IsTypeInst(SpvOp opcode) {
38   return (opcode >= SpvOpTypeVoid && opcode <= SpvOpTypeForwardPointer) ||
39          opcode == SpvOpTypePipeStorage || opcode == SpvOpTypeNamedBarrier;
40 }
IsConstantInst(SpvOp opcode)41 inline bool IsConstantInst(SpvOp opcode) {
42   return opcode >= SpvOpConstantTrue && opcode <= SpvOpSpecConstantOp;
43 }
IsTerminatorInst(SpvOp opcode)44 inline bool IsTerminatorInst(SpvOp opcode) {
45   return opcode >= SpvOpBranch && opcode <= SpvOpUnreachable;
46 }
47 
48 }  // namespace ir
49 }  // namespace spvtools
50 
51 #endif  // LIBSPIRV_OPT_REFLECT_H_
52