desc_sroa_util.h 2.2 KB

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