CapabilityVisitor.h 2.8 KB

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