Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1 | //===----- CGOpenCLRuntime.h - Interface to OpenCL Runtimes -----*- 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 | // |
| 10 | // This provides an abstract class for OpenCL code generation. Concrete |
| 11 | // subclasses of this implement code generation for specific OpenCL |
| 12 | // runtime libraries. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
Benjamin Kramer | 2f5db8b | 2014-08-13 16:25:19 +0000 | [diff] [blame] | 16 | #ifndef LLVM_CLANG_LIB_CODEGEN_CGOPENCLRUNTIME_H |
| 17 | #define LLVM_CLANG_LIB_CODEGEN_CGOPENCLRUNTIME_H |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 18 | |
Guy Benyei | d8a08ea | 2012-12-18 14:38:23 +0000 | [diff] [blame] | 19 | #include "clang/AST/Type.h" |
Yaxun Liu | c2a87a0 | 2017-10-14 12:23:50 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/DenseMap.h" |
Chandler Carruth | ffd5551 | 2013-01-02 11:45:17 +0000 | [diff] [blame] | 21 | #include "llvm/IR/Type.h" |
| 22 | #include "llvm/IR/Value.h" |
Guy Benyei | d8a08ea | 2012-12-18 14:38:23 +0000 | [diff] [blame] | 23 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 24 | namespace clang { |
| 25 | |
Yaxun Liu | c2a87a0 | 2017-10-14 12:23:50 +0000 | [diff] [blame] | 26 | class Expr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 27 | class VarDecl; |
| 28 | |
| 29 | namespace CodeGen { |
| 30 | |
| 31 | class CodeGenFunction; |
| 32 | class CodeGenModule; |
| 33 | |
| 34 | class CGOpenCLRuntime { |
| 35 | protected: |
| 36 | CodeGenModule &CGM; |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 37 | llvm::Type *PipeTy; |
Yaxun Liu | 0bc4b2d | 2016-07-28 19:26:30 +0000 | [diff] [blame] | 38 | llvm::PointerType *SamplerTy; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 39 | |
Yaxun Liu | c2a87a0 | 2017-10-14 12:23:50 +0000 | [diff] [blame] | 40 | /// Structure for enqueued block information. |
| 41 | struct EnqueuedBlockInfo { |
| 42 | llvm::Function *Kernel; /// Enqueued block kernel. |
| 43 | llvm::Value *BlockArg; /// The first argument to enqueued block kernel. |
| 44 | }; |
| 45 | /// Maps block expression to block information. |
| 46 | llvm::DenseMap<const Expr *, EnqueuedBlockInfo> EnqueuedBlockMap; |
| 47 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 48 | public: |
Yaxun Liu | 0bc4b2d | 2016-07-28 19:26:30 +0000 | [diff] [blame] | 49 | CGOpenCLRuntime(CodeGenModule &CGM) : CGM(CGM), PipeTy(nullptr), |
| 50 | SamplerTy(nullptr) {} |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 51 | virtual ~CGOpenCLRuntime(); |
| 52 | |
| 53 | /// Emit the IR required for a work-group-local variable declaration, and add |
| 54 | /// an entry to CGF's LocalDeclMap for D. The base class does this using |
| 55 | /// CodeGenFunction::EmitStaticVarDecl to emit an internal global for D. |
| 56 | virtual void EmitWorkGroupLocalVarDecl(CodeGenFunction &CGF, |
| 57 | const VarDecl &D); |
Guy Benyei | d8a08ea | 2012-12-18 14:38:23 +0000 | [diff] [blame] | 58 | |
| 59 | virtual llvm::Type *convertOpenCLSpecificType(const Type *T); |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 60 | |
Sven van Haastregt | efb4d4c | 2017-08-15 09:38:18 +0000 | [diff] [blame] | 61 | virtual llvm::Type *getPipeType(const PipeType *T); |
Yaxun Liu | 0bc4b2d | 2016-07-28 19:26:30 +0000 | [diff] [blame] | 62 | |
Sven van Haastregt | efb4d4c | 2017-08-15 09:38:18 +0000 | [diff] [blame] | 63 | llvm::PointerType *getSamplerType(const Type *T); |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 64 | |
| 65 | // \brief Returnes a value which indicates the size in bytes of the pipe |
| 66 | // element. |
| 67 | virtual llvm::Value *getPipeElemSize(const Expr *PipeArg); |
| 68 | |
| 69 | // \brief Returnes a value which indicates the alignment in bytes of the pipe |
| 70 | // element. |
| 71 | virtual llvm::Value *getPipeElemAlign(const Expr *PipeArg); |
Yaxun Liu | 10712d9 | 2017-10-04 20:32:17 +0000 | [diff] [blame] | 72 | |
| 73 | /// \return __generic void* type. |
| 74 | llvm::PointerType *getGenericVoidPointerType(); |
Yaxun Liu | c2a87a0 | 2017-10-14 12:23:50 +0000 | [diff] [blame] | 75 | |
| 76 | /// \return enqueued block information for enqueued block. |
| 77 | EnqueuedBlockInfo emitOpenCLEnqueuedBlock(CodeGenFunction &CGF, |
| 78 | const Expr *E); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 79 | }; |
| 80 | |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 81 | } |
| 82 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 83 | |
| 84 | #endif |