Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1 | //===----- CGOpenCLRuntime.h - Interface to OpenCL Runtimes -----*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 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 | |
Benjamin Kramer | 2f5db8b | 2014-08-13 16:25:19 +0000 | [diff] [blame] | 15 | #ifndef LLVM_CLANG_LIB_CODEGEN_CGOPENCLRUNTIME_H |
| 16 | #define LLVM_CLANG_LIB_CODEGEN_CGOPENCLRUNTIME_H |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 17 | |
Richard Trieu | f8b8b39 | 2019-01-11 01:32:35 +0000 | [diff] [blame] | 18 | #include "clang/AST/Expr.h" |
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 | fa13d01 | 2018-02-15 16:39:19 +0000 | [diff] [blame] | 26 | class BlockExpr; |
Yaxun Liu | c2a87a0 | 2017-10-14 12:23:50 +0000 | [diff] [blame] | 27 | class Expr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 28 | class VarDecl; |
| 29 | |
| 30 | namespace CodeGen { |
| 31 | |
| 32 | class CodeGenFunction; |
| 33 | class CodeGenModule; |
| 34 | |
| 35 | class CGOpenCLRuntime { |
| 36 | protected: |
| 37 | CodeGenModule &CGM; |
Sven van Haastregt | 4700faa | 2018-04-27 10:37:04 +0000 | [diff] [blame] | 38 | llvm::Type *PipeROTy; |
| 39 | llvm::Type *PipeWOTy; |
Yaxun Liu | 0bc4b2d | 2016-07-28 19:26:30 +0000 | [diff] [blame] | 40 | llvm::PointerType *SamplerTy; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 41 | |
Yaxun Liu | c2a87a0 | 2017-10-14 12:23:50 +0000 | [diff] [blame] | 42 | /// Structure for enqueued block information. |
| 43 | struct EnqueuedBlockInfo { |
Yaxun Liu | fa13d01 | 2018-02-15 16:39:19 +0000 | [diff] [blame] | 44 | llvm::Function *InvokeFunc; /// Block invoke function. |
| 45 | llvm::Function *Kernel; /// Enqueued block kernel. |
| 46 | llvm::Value *BlockArg; /// The first argument to enqueued block kernel. |
Yaxun Liu | c2a87a0 | 2017-10-14 12:23:50 +0000 | [diff] [blame] | 47 | }; |
| 48 | /// Maps block expression to block information. |
| 49 | llvm::DenseMap<const Expr *, EnqueuedBlockInfo> EnqueuedBlockMap; |
| 50 | |
Sven van Haastregt | 4700faa | 2018-04-27 10:37:04 +0000 | [diff] [blame] | 51 | virtual llvm::Type *getPipeType(const PipeType *T, StringRef Name, |
| 52 | llvm::Type *&PipeTy); |
| 53 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 54 | public: |
Sven van Haastregt | 4700faa | 2018-04-27 10:37:04 +0000 | [diff] [blame] | 55 | CGOpenCLRuntime(CodeGenModule &CGM) : CGM(CGM), |
| 56 | PipeROTy(nullptr), PipeWOTy(nullptr), SamplerTy(nullptr) {} |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 57 | virtual ~CGOpenCLRuntime(); |
| 58 | |
| 59 | /// Emit the IR required for a work-group-local variable declaration, and add |
| 60 | /// an entry to CGF's LocalDeclMap for D. The base class does this using |
| 61 | /// CodeGenFunction::EmitStaticVarDecl to emit an internal global for D. |
| 62 | virtual void EmitWorkGroupLocalVarDecl(CodeGenFunction &CGF, |
| 63 | const VarDecl &D); |
Guy Benyei | d8a08ea | 2012-12-18 14:38:23 +0000 | [diff] [blame] | 64 | |
| 65 | virtual llvm::Type *convertOpenCLSpecificType(const Type *T); |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 66 | |
Sven van Haastregt | efb4d4c | 2017-08-15 09:38:18 +0000 | [diff] [blame] | 67 | virtual llvm::Type *getPipeType(const PipeType *T); |
Yaxun Liu | 0bc4b2d | 2016-07-28 19:26:30 +0000 | [diff] [blame] | 68 | |
Sven van Haastregt | efb4d4c | 2017-08-15 09:38:18 +0000 | [diff] [blame] | 69 | llvm::PointerType *getSamplerType(const Type *T); |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 70 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 71 | // Returns a value which indicates the size in bytes of the pipe |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 72 | // element. |
| 73 | virtual llvm::Value *getPipeElemSize(const Expr *PipeArg); |
| 74 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 75 | // Returns a value which indicates the alignment in bytes of the pipe |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 76 | // element. |
| 77 | virtual llvm::Value *getPipeElemAlign(const Expr *PipeArg); |
Yaxun Liu | 10712d9 | 2017-10-04 20:32:17 +0000 | [diff] [blame] | 78 | |
| 79 | /// \return __generic void* type. |
| 80 | llvm::PointerType *getGenericVoidPointerType(); |
Yaxun Liu | c2a87a0 | 2017-10-14 12:23:50 +0000 | [diff] [blame] | 81 | |
| 82 | /// \return enqueued block information for enqueued block. |
| 83 | EnqueuedBlockInfo emitOpenCLEnqueuedBlock(CodeGenFunction &CGF, |
| 84 | const Expr *E); |
Yaxun Liu | fa13d01 | 2018-02-15 16:39:19 +0000 | [diff] [blame] | 85 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 86 | /// Record invoke function and block literal emitted during normal |
Yaxun Liu | fa13d01 | 2018-02-15 16:39:19 +0000 | [diff] [blame] | 87 | /// codegen for a block expression. The information is used by |
| 88 | /// emitOpenCLEnqueuedBlock to emit wrapper kernel. |
| 89 | /// |
| 90 | /// \param InvokeF invoke function emitted for the block expression. |
| 91 | /// \param Block block literal emitted for the block expression. |
| 92 | void recordBlockInfo(const BlockExpr *E, llvm::Function *InvokeF, |
| 93 | llvm::Value *Block); |
Andrew Savonichev | 43fceb2 | 2019-02-21 11:02:10 +0000 | [diff] [blame] | 94 | |
| 95 | /// \return LLVM block invoke function emitted for an expression derived from |
| 96 | /// the block expression. |
| 97 | llvm::Function *getInvokeFunction(const Expr *E); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 98 | }; |
| 99 | |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 100 | } |
| 101 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 102 | |
| 103 | #endif |