CapabilityVisitor.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //===--- CapabilityVisitor.h - Capability 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_CAPABILITYVISITOR_H
  10. #define LLVM_CLANG_LIB_SPIRV_CAPABILITYVISITOR_H
  11. #include "clang/SPIRV/FeatureManager.h"
  12. #include "clang/SPIRV/SpirvContext.h"
  13. #include "clang/SPIRV/SpirvVisitor.h"
  14. namespace clang {
  15. namespace spirv {
  16. class SpirvBuilder;
  17. class CapabilityVisitor : public Visitor {
  18. public:
  19. CapabilityVisitor(ASTContext &astCtx, SpirvContext &spvCtx,
  20. const SpirvCodeGenOptions &opts, SpirvBuilder &builder)
  21. : Visitor(opts, spvCtx), spvBuilder(builder),
  22. shaderModel(spv::ExecutionModel::Max),
  23. featureManager(astCtx.getDiagnostics(), opts) {}
  24. bool visit(SpirvModule *, Phase) override;
  25. bool visit(SpirvDecoration *decor) override;
  26. bool visit(SpirvEntryPoint *) override;
  27. bool visit(SpirvExecutionMode *) override;
  28. bool visit(SpirvImageQuery *) override;
  29. bool visit(SpirvImageOp *) override;
  30. bool visit(SpirvImageSparseTexelsResident *) override;
  31. bool visit(SpirvExtInstImport *) override;
  32. bool visit(SpirvExtInst *) override;
  33. bool visit(SpirvAtomic *) override;
  34. bool visit(SpirvDemoteToHelperInvocationEXT *) override;
  35. bool visit(SpirvReadClock *) override;
  36. using Visitor::visit;
  37. /// The "sink" visit function for all instructions.
  38. ///
  39. /// By default, all other visit instructions redirect to this visit function.
  40. /// So that you want override this visit function to handle all instructions,
  41. /// regardless of their polymorphism.
  42. bool visitInstruction(SpirvInstruction *instr) override;
  43. private:
  44. /// Adds necessary capabilities for using the given type.
  45. /// The called may also provide the storage class for variable types, because
  46. /// in the case of variable types, the storage class may affect the capability
  47. /// that is used.
  48. void addCapabilityForType(const SpirvType *, SourceLocation loc,
  49. spv::StorageClass sc);
  50. /// Checks that the given extension is a valid extension for the target
  51. /// environment (e.g. Vulkan 1.0). And if so, utilizes the SpirvBuilder to add
  52. /// the given extension to the SPIR-V module in memory.
  53. void addExtension(Extension ext, llvm::StringRef target, SourceLocation loc);
  54. /// Checks that the given capability is a valid capability. And if so,
  55. /// utilizes the SpirvBuilder to add the given capability to the SPIR-V module
  56. /// in memory.
  57. void addCapability(spv::Capability, SourceLocation loc = {});
  58. /// Returns the capability required to non-uniformly index into the given
  59. /// type.
  60. spv::Capability getNonUniformCapability(const SpirvType *);
  61. private:
  62. SpirvBuilder &spvBuilder; ///< SPIR-V builder
  63. spv::ExecutionModel shaderModel; ///< Execution model
  64. FeatureManager featureManager; ///< SPIR-V version/extension manager.
  65. };
  66. } // end namespace spirv
  67. } // end namespace clang
  68. #endif // LLVM_CLANG_LIB_SPIRV_CAPABILITYVISITOR_H