RemoveBufferBlockVisitor.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //===--- RemoveBufferBlockVisitor.h - RemoveBufferBlock Visitor --*- C++ -*-==//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef LLVM_CLANG_LIB_SPIRV_REMOVEBUFFERBLOCKVISITOR_H
  10. #define LLVM_CLANG_LIB_SPIRV_REMOVEBUFFERBLOCKVISITOR_H
  11. #include "clang/AST/ASTContext.h"
  12. #include "clang/SPIRV/FeatureManager.h"
  13. #include "clang/SPIRV/SpirvVisitor.h"
  14. namespace clang {
  15. namespace spirv {
  16. class SpirvContext;
  17. class RemoveBufferBlockVisitor : public Visitor {
  18. public:
  19. RemoveBufferBlockVisitor(ASTContext &astCtx, SpirvContext &spvCtx,
  20. const SpirvCodeGenOptions &opts)
  21. : Visitor(opts, spvCtx), featureManager(astCtx.getDiagnostics(), opts) {}
  22. bool visit(SpirvModule *, Phase) override;
  23. bool visit(SpirvFunction *, Phase) override;
  24. using Visitor::visit;
  25. /// The "sink" visit function for all instructions.
  26. ///
  27. /// By default, all other visit instructions redirect to this visit function.
  28. /// So that you want override this visit function to handle all instructions,
  29. /// regardless of their polymorphism.
  30. bool visitInstruction(SpirvInstruction *instr) override;
  31. private:
  32. /// Returns true if |type| is a SPIR-V type whose interface type is
  33. /// StorageBuffer.
  34. bool hasStorageBufferInterfaceType(const SpirvType *type);
  35. /// Returns true if the BufferBlock decoration is deprecated (Vulkan 1.2 or
  36. /// above).
  37. bool isBufferBlockDecorationDeprecated();
  38. /// Transforms the given |type| if it is one of the following cases:
  39. ///
  40. /// 1- a pointer to a structure with StorageBuffer interface
  41. /// 2- a pointer to a pointer to a structure with StorageBuffer interface
  42. ///
  43. /// by updating the storage class of the pointer whose pointee is the struct.
  44. ///
  45. /// Example of case (1):
  46. /// type: _ptr_Uniform_SturcturedBuffer_float
  47. /// new type: _ptr_StorageBuffer_SturcturedBuffer_float
  48. /// new storage class: StorageBuffer
  49. ///
  50. /// Example of case (2):
  51. /// type: _ptr_Function__ptr_Uniform_SturcturedBuffer_float
  52. /// new type: _ptr_Function__ptr_StorageBuffer_SturcturedBuffer_float
  53. /// new storage class: Function
  54. ///
  55. /// If |type| is transformed, the |newType| and |newStorageClass| are
  56. /// returned by reference and the function returns true.
  57. ///
  58. /// If |type| is not transformed, |newType| and |newStorageClass| are
  59. /// untouched, and the function returns false.
  60. bool updateStorageClass(const SpirvType *type, const SpirvType **newType,
  61. spv::StorageClass *newStorageClass);
  62. FeatureManager featureManager;
  63. };
  64. } // end namespace spirv
  65. } // end namespace clang
  66. #endif // LLVM_CLANG_LIB_SPIRV_REMOVEBUFFERBLOCKVISITOR_H