blob: c0088b5bcd8ee15570b8760245922c9be4180273 [file] [log] [blame]
Guy Benyei11169dd2012-12-18 14:30:41 +00001//===----- 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 Kramer2f5db8b2014-08-13 16:25:19 +000016#ifndef LLVM_CLANG_LIB_CODEGEN_CGOPENCLRUNTIME_H
17#define LLVM_CLANG_LIB_CODEGEN_CGOPENCLRUNTIME_H
Guy Benyei11169dd2012-12-18 14:30:41 +000018
Guy Benyeid8a08ea2012-12-18 14:38:23 +000019#include "clang/AST/Type.h"
Yaxun Liuc2a87a02017-10-14 12:23:50 +000020#include "llvm/ADT/DenseMap.h"
Chandler Carruthffd55512013-01-02 11:45:17 +000021#include "llvm/IR/Type.h"
22#include "llvm/IR/Value.h"
Guy Benyeid8a08ea2012-12-18 14:38:23 +000023
Guy Benyei11169dd2012-12-18 14:30:41 +000024namespace clang {
25
Yaxun Liufa13d012018-02-15 16:39:19 +000026class BlockExpr;
Yaxun Liuc2a87a02017-10-14 12:23:50 +000027class Expr;
Guy Benyei11169dd2012-12-18 14:30:41 +000028class VarDecl;
29
30namespace CodeGen {
31
32class CodeGenFunction;
33class CodeGenModule;
34
35class CGOpenCLRuntime {
36protected:
37 CodeGenModule &CGM;
Xiuli Pan9c14e282016-01-09 12:53:17 +000038 llvm::Type *PipeTy;
Yaxun Liu0bc4b2d2016-07-28 19:26:30 +000039 llvm::PointerType *SamplerTy;
Guy Benyei11169dd2012-12-18 14:30:41 +000040
Yaxun Liuc2a87a02017-10-14 12:23:50 +000041 /// Structure for enqueued block information.
42 struct EnqueuedBlockInfo {
Yaxun Liufa13d012018-02-15 16:39:19 +000043 llvm::Function *InvokeFunc; /// Block invoke function.
44 llvm::Function *Kernel; /// Enqueued block kernel.
45 llvm::Value *BlockArg; /// The first argument to enqueued block kernel.
Yaxun Liuc2a87a02017-10-14 12:23:50 +000046 };
47 /// Maps block expression to block information.
48 llvm::DenseMap<const Expr *, EnqueuedBlockInfo> EnqueuedBlockMap;
49
Guy Benyei11169dd2012-12-18 14:30:41 +000050public:
Yaxun Liu0bc4b2d2016-07-28 19:26:30 +000051 CGOpenCLRuntime(CodeGenModule &CGM) : CGM(CGM), PipeTy(nullptr),
52 SamplerTy(nullptr) {}
Guy Benyei11169dd2012-12-18 14:30:41 +000053 virtual ~CGOpenCLRuntime();
54
55 /// Emit the IR required for a work-group-local variable declaration, and add
56 /// an entry to CGF's LocalDeclMap for D. The base class does this using
57 /// CodeGenFunction::EmitStaticVarDecl to emit an internal global for D.
58 virtual void EmitWorkGroupLocalVarDecl(CodeGenFunction &CGF,
59 const VarDecl &D);
Guy Benyeid8a08ea2012-12-18 14:38:23 +000060
61 virtual llvm::Type *convertOpenCLSpecificType(const Type *T);
Xiuli Pan9c14e282016-01-09 12:53:17 +000062
Sven van Haastregtefb4d4c2017-08-15 09:38:18 +000063 virtual llvm::Type *getPipeType(const PipeType *T);
Yaxun Liu0bc4b2d2016-07-28 19:26:30 +000064
Sven van Haastregtefb4d4c2017-08-15 09:38:18 +000065 llvm::PointerType *getSamplerType(const Type *T);
Alexey Bader465c1892016-09-23 14:20:00 +000066
67 // \brief Returnes a value which indicates the size in bytes of the pipe
68 // element.
69 virtual llvm::Value *getPipeElemSize(const Expr *PipeArg);
70
71 // \brief Returnes a value which indicates the alignment in bytes of the pipe
72 // element.
73 virtual llvm::Value *getPipeElemAlign(const Expr *PipeArg);
Yaxun Liu10712d92017-10-04 20:32:17 +000074
75 /// \return __generic void* type.
76 llvm::PointerType *getGenericVoidPointerType();
Yaxun Liuc2a87a02017-10-14 12:23:50 +000077
78 /// \return enqueued block information for enqueued block.
79 EnqueuedBlockInfo emitOpenCLEnqueuedBlock(CodeGenFunction &CGF,
80 const Expr *E);
Yaxun Liufa13d012018-02-15 16:39:19 +000081
82 /// \brief Record invoke function and block literal emitted during normal
83 /// codegen for a block expression. The information is used by
84 /// emitOpenCLEnqueuedBlock to emit wrapper kernel.
85 ///
86 /// \param InvokeF invoke function emitted for the block expression.
87 /// \param Block block literal emitted for the block expression.
88 void recordBlockInfo(const BlockExpr *E, llvm::Function *InvokeF,
89 llvm::Value *Block);
Guy Benyei11169dd2012-12-18 14:30:41 +000090};
91
Alexander Kornienkoab9db512015-06-22 23:07:51 +000092}
93}
Guy Benyei11169dd2012-12-18 14:30:41 +000094
95#endif