CGOpenCLRuntime.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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/ADT/StringMap.h"
  20. #include "llvm/IR/Type.h"
  21. #include "llvm/IR/Value.h"
  22. namespace clang {
  23. class BlockExpr;
  24. class Expr;
  25. class VarDecl;
  26. namespace CodeGen {
  27. class CodeGenFunction;
  28. class CodeGenModule;
  29. class CGOpenCLRuntime {
  30. protected:
  31. CodeGenModule &CGM;
  32. llvm::Type *PipeROTy;
  33. llvm::Type *PipeWOTy;
  34. llvm::PointerType *SamplerTy;
  35. llvm::StringMap<llvm::PointerType *> CachedTys;
  36. /// Structure for enqueued block information.
  37. struct EnqueuedBlockInfo {
  38. llvm::Function *InvokeFunc; /// Block invoke function.
  39. llvm::Function *Kernel; /// Enqueued block kernel.
  40. llvm::Value *BlockArg; /// The first argument to enqueued block kernel.
  41. llvm::Type *BlockTy; /// Type of the block argument.
  42. };
  43. /// Maps block expression to block information.
  44. llvm::DenseMap<const Expr *, EnqueuedBlockInfo> EnqueuedBlockMap;
  45. virtual llvm::Type *getPipeType(const PipeType *T, StringRef Name,
  46. llvm::Type *&PipeTy);
  47. llvm::PointerType *getPointerType(const Type *T, StringRef Name);
  48. public:
  49. CGOpenCLRuntime(CodeGenModule &CGM) : CGM(CGM),
  50. PipeROTy(nullptr), PipeWOTy(nullptr), SamplerTy(nullptr) {}
  51. virtual ~CGOpenCLRuntime();
  52. /// Emit the IR required for a work-group-local variable declaration, and add
  53. /// an entry to CGF's LocalDeclMap for D. The base class does this using
  54. /// CodeGenFunction::EmitStaticVarDecl to emit an internal global for D.
  55. virtual void EmitWorkGroupLocalVarDecl(CodeGenFunction &CGF,
  56. const VarDecl &D);
  57. virtual llvm::Type *convertOpenCLSpecificType(const Type *T);
  58. virtual llvm::Type *getPipeType(const PipeType *T);
  59. llvm::PointerType *getSamplerType(const Type *T);
  60. // Returns a value which indicates the size in bytes of the pipe
  61. // element.
  62. virtual llvm::Value *getPipeElemSize(const Expr *PipeArg);
  63. // Returns a value which indicates the alignment in bytes of the pipe
  64. // element.
  65. virtual llvm::Value *getPipeElemAlign(const Expr *PipeArg);
  66. /// \return __generic void* type.
  67. llvm::PointerType *getGenericVoidPointerType();
  68. /// \return enqueued block information for enqueued block.
  69. EnqueuedBlockInfo emitOpenCLEnqueuedBlock(CodeGenFunction &CGF,
  70. const Expr *E);
  71. /// Record invoke function and block literal emitted during normal
  72. /// codegen for a block expression. The information is used by
  73. /// emitOpenCLEnqueuedBlock to emit wrapper kernel.
  74. ///
  75. /// \param InvokeF invoke function emitted for the block expression.
  76. /// \param Block block literal emitted for the block expression.
  77. void recordBlockInfo(const BlockExpr *E, llvm::Function *InvokeF,
  78. llvm::Value *Block, llvm::Type *BlockTy);
  79. /// \return LLVM block invoke function emitted for an expression derived from
  80. /// the block expression.
  81. llvm::Function *getInvokeFunction(const Expr *E);
  82. };
  83. }
  84. }
  85. #endif