xref: /aosp_15_r20/external/swiftshader/src/Pipeline/SpirvShaderInstructions.cpp (revision 03ce13f70fcc45d86ee91b7ee4cab1936a95046e)
1 // Copyright 2020 The SwiftShader Authors. All Rights Reserved.
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 #include "SpirvShader.hpp"
16 
17 #include "spirv-tools/libspirv.h"
18 
19 #include <spirv/unified1/spirv.hpp>
20 
21 namespace sw {
22 
OpcodeName(spv::Op opcode)23 const char *Spirv::OpcodeName(spv::Op opcode)
24 {
25 	return spvOpcodeString(opcode);
26 }
27 
28 // This function is used by the shader debugger to determine whether an instruction is steppable.
IsStatement(spv::Op opcode)29 bool Spirv::IsStatement(spv::Op opcode)
30 {
31 	switch(opcode)
32 	{
33 	default:
34 		// Most statement-like instructions produce a result which has a type.
35 		// Note OpType* instructions have a result but it is a type itself.
36 		{
37 			bool hasResult = false;
38 			bool hasResultType = false;
39 			spv::HasResultAndType(opcode, &hasResult, &hasResultType);
40 
41 			return hasResult && hasResultType;
42 		}
43 		break;
44 
45 	// Instructions without a result but potential side-effects.
46 	case spv::OpNop:
47 	case spv::OpStore:
48 	case spv::OpCopyMemory:
49 	case spv::OpCopyMemorySized:
50 	case spv::OpImageWrite:
51 	case spv::OpEmitVertex:
52 	case spv::OpEndPrimitive:
53 	case spv::OpEmitStreamVertex:
54 	case spv::OpEndStreamPrimitive:
55 	case spv::OpControlBarrier:
56 	case spv::OpMemoryBarrier:
57 	case spv::OpAtomicStore:
58 	case spv::OpBranch:
59 	case spv::OpBranchConditional:
60 	case spv::OpSwitch:
61 	case spv::OpKill:
62 	case spv::OpReturn:
63 	case spv::OpReturnValue:
64 	case spv::OpLifetimeStart:
65 	case spv::OpLifetimeStop:
66 	case spv::OpGroupWaitEvents:
67 	case spv::OpCommitReadPipe:
68 	case spv::OpCommitWritePipe:
69 	case spv::OpGroupCommitReadPipe:
70 	case spv::OpGroupCommitWritePipe:
71 	case spv::OpRetainEvent:
72 	case spv::OpReleaseEvent:
73 	case spv::OpSetUserEventStatus:
74 	case spv::OpCaptureEventProfilingInfo:
75 	case spv::OpAtomicFlagClear:
76 	case spv::OpMemoryNamedBarrier:
77 	case spv::OpTerminateInvocation:
78 	case spv::OpTraceRayKHR:
79 	case spv::OpExecuteCallableKHR:
80 	case spv::OpIgnoreIntersectionKHR:
81 	case spv::OpTerminateRayKHR:
82 	case spv::OpRayQueryInitializeKHR:
83 	case spv::OpRayQueryTerminateKHR:
84 	case spv::OpRayQueryGenerateIntersectionKHR:
85 	case spv::OpRayQueryConfirmIntersectionKHR:
86 	case spv::OpBeginInvocationInterlockEXT:
87 	case spv::OpEndInvocationInterlockEXT:
88 	case spv::OpDemoteToHelperInvocationEXT:
89 	case spv::OpAssumeTrueKHR:
90 		return true;
91 	}
92 }
93 
IsTerminator(spv::Op opcode)94 bool Spirv::IsTerminator(spv::Op opcode)
95 {
96 	switch(opcode)
97 	{
98 	// Branch instructions
99 	case spv::OpBranch:
100 	case spv::OpBranchConditional:
101 	case spv::OpSwitch:
102 	// Function termination instructions
103 	case spv::OpReturn:
104 	case spv::OpReturnValue:
105 	case spv::OpKill:
106 	case spv::OpUnreachable:
107 	case spv::OpTerminateInvocation:
108 		return true;
109 	default:
110 		return false;
111 	}
112 }
113 
114 }  // namespace sw