1 // Copyright (c) 2021 Google LLC 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_DESC_SROA_UTIL_H_ 16 #define SOURCE_OPT_DESC_SROA_UTIL_H_ 17 18 #include "source/opt/ir_context.h" 19 20 namespace spvtools { 21 namespace opt { 22 23 // Provides functions for the descriptor array SROA. 24 namespace descsroautil { 25 26 // Returns true if |var| is an OpVariable instruction that represents a 27 // descriptor array. 28 bool IsDescriptorArray(IRContext* context, Instruction* var); 29 30 // Returns true if |type| is a type that could be used for a structured buffer 31 // as opposed to a type that would be used for a structure of resource 32 // descriptors. 33 bool IsTypeOfStructuredBuffer(IRContext* context, const Instruction* type); 34 35 // Returns the first index of the OpAccessChain instruction |access_chain| as 36 // a constant. Returns nullptr if it is not a constant. 37 const analysis::Constant* GetAccessChainIndexAsConst(IRContext* context, 38 Instruction* access_chain); 39 40 // Returns the number of elements of an OpVariable instruction |var| whose type 41 // must be a pointer to an array or a struct. 42 uint32_t GetNumberOfElementsForArrayOrStruct(IRContext* context, 43 Instruction* var); 44 45 // Returns the first Indexes operand id of the OpAccessChain or 46 // OpInBoundsAccessChain instruction |access_chain|. The access chain must have 47 // at least 1 index. 48 uint32_t GetFirstIndexOfAccessChain(Instruction* access_chain); 49 50 } // namespace descsroautil 51 } // namespace opt 52 } // namespace spvtools 53 54 #endif // SOURCE_OPT_DESC_SROA_UTIL_H_ 55