CGOpenCLRuntime.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //===----- CGOpenCLRuntime.h - Interface to OpenCL Runtimes -----*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This provides an abstract class for OpenCL code generation. Concrete
  10. // subclasses of this implement code generation for specific OpenCL
  11. // runtime libraries.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_CLANG_LIB_CODEGEN_CGOPENCLRUNTIME_H
  15. #define LLVM_CLANG_LIB_CODEGEN_CGOPENCLRUNTIME_H
  16. #include "clang/AST/Expr.h"
  17. #include "clang/AST/Type.h"
  18. #include "llvm/ADT/DenseMap.h"
  19. #include "llvm/IR/Type.h"
  20. #include "llvm/IR/Value.h"
  21. namespace clang {
  22. class BlockExpr;
  23. class Expr;
  24. class VarDecl;
  25. namespace CodeGen {
  26. class CodeGenFunction;
  27. class CodeGenModule;
  28. class CGOpenCLRuntime {
  29. protected:
  30. CodeGenModule &CGM;
  31. llvm::Type *PipeROTy;
  32. llvm::Type *PipeWOTy;
  33. llvm::PointerType *SamplerTy;
  34. /// Structure for enqueued block information.
  35. struct EnqueuedBlockInfo {
  36. llvm::Function *InvokeFunc; /// Block invoke function.
  37. llvm::Function *Kernel; /// Enqueued block kernel.
  38. llvm::Value *BlockArg; /// The first argument to enqueued block kernel.
  39. };
  40. /// Maps block expression to block information.
  41. llvm::DenseMap<const Expr *, EnqueuedBlockInfo> EnqueuedBlockMap;
  42. virtual llvm::Type *getPipeType(const PipeType *T, StringRef Name,
  43. llvm::Type *&PipeTy);
  44. public:
  45. CGOpenCLRuntime(CodeGenModule &CGM) : CGM(CGM),
  46. PipeROTy(nullptr), PipeWOTy(nullptr), SamplerTy(nullptr) {}
  47. virtual ~CGOpenCLRuntime();
  48. /// Emit the IR required for a work-group-local variable declaration, and add
  49. /// an entry to CGF's LocalDeclMap for D. The base class does this using
  50. /// CodeGenFunction::EmitStaticVarDecl to emit an internal global for D.
  51. virtual void EmitWorkGroupLocalVarDecl(CodeGenFunction &CGF,
  52. const VarDecl &D);
  53. virtual llvm::Type *convertOpenCLSpecificType(const Type *T);
  54. virtual llvm::Type *getPipeType(const PipeType *T);
  55. llvm::PointerType *getSamplerType(const Type *T);
  56. // Returns a value which indicates the size in bytes of the pipe
  57. // element.
  58. virtual llvm::Value *getPipeElemSize(const Expr *PipeArg);
  59. // Returns a value which indicates the alignment in bytes of the pipe
  60. // element.
  61. virtual llvm::Value *getPipeElemAlign(const Expr *PipeArg);
  62. /// \return __generic void* type.
  63. llvm::PointerType *getGenericVoidPointerType();
  64. /// \return enqueued block information for enqueued block.
  65. EnqueuedBlockInfo emitOpenCLEnqueuedBlock(CodeGenFunction &CGF,
  66. const Expr *E);
  67. /// Record invoke function and block literal emitted during normal
  68. /// codegen for a block expression. The information is used by
  69. /// emitOpenCLEnqueuedBlock to emit wrapper kernel.
  70. ///
  71. /// \param InvokeF invoke function emitted for the block expression.
  72. /// \param Block block literal emitted for the block expression.
  73. void recordBlockInfo(const BlockExpr *E, llvm::Function *InvokeF,
  74. llvm::Value *Block);
  75. /// \return LLVM block invoke function emitted for an expression derived from
  76. /// the block expression.
  77. llvm::Function *getInvokeFunction(const Expr *E);
  78. };
  79. }
  80. }
  81. #endif