blob: 750721f1b80ff18eedbdbfa820825dc50450560c [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
Richard Trieuf8b8b392019-01-11 01:32:35 +000019#include "clang/AST/Expr.h"
Guy Benyeid8a08ea2012-12-18 14:38:23 +000020#include "clang/AST/Type.h"
Yaxun Liuc2a87a02017-10-14 12:23:50 +000021#include "llvm/ADT/DenseMap.h"
Chandler Carruthffd55512013-01-02 11:45:17 +000022#include "llvm/IR/Type.h"
23#include "llvm/IR/Value.h"
Guy Benyeid8a08ea2012-12-18 14:38:23 +000024
Guy Benyei11169dd2012-12-18 14:30:41 +000025namespace clang {
26
Yaxun Liufa13d012018-02-15 16:39:19 +000027class BlockExpr;
Yaxun Liuc2a87a02017-10-14 12:23:50 +000028class Expr;
Guy Benyei11169dd2012-12-18 14:30:41 +000029class VarDecl;
30
31namespace CodeGen {
32
33class CodeGenFunction;
34class CodeGenModule;
35
36class CGOpenCLRuntime {
37protected:
38 CodeGenModule &CGM;
Sven van Haastregt4700faa2018-04-27 10:37:04 +000039 llvm::Type *PipeROTy;
40 llvm::Type *PipeWOTy;
Yaxun Liu0bc4b2d2016-07-28 19:26:30 +000041 llvm::PointerType *SamplerTy;
Guy Benyei11169dd2012-12-18 14:30:41 +000042
Yaxun Liuc2a87a02017-10-14 12:23:50 +000043 /// Structure for enqueued block information.
44 struct EnqueuedBlockInfo {
Yaxun Liufa13d012018-02-15 16:39:19 +000045 llvm::Function *InvokeFunc; /// Block invoke function.
46 llvm::Function *Kernel; /// Enqueued block kernel.
47 llvm::Value *BlockArg; /// The first argument to enqueued block kernel.
Yaxun Liuc2a87a02017-10-14 12:23:50 +000048 };
49 /// Maps block expression to block information.
50 llvm::DenseMap<const Expr *, EnqueuedBlockInfo> EnqueuedBlockMap;
51
Sven van Haastregt4700faa2018-04-27 10:37:04 +000052 virtual llvm::Type *getPipeType(const PipeType *T, StringRef Name,
53 llvm::Type *&PipeTy);
54
Guy Benyei11169dd2012-12-18 14:30:41 +000055public:
Sven van Haastregt4700faa2018-04-27 10:37:04 +000056 CGOpenCLRuntime(CodeGenModule &CGM) : CGM(CGM),
57 PipeROTy(nullptr), PipeWOTy(nullptr), SamplerTy(nullptr) {}
Guy Benyei11169dd2012-12-18 14:30:41 +000058 virtual ~CGOpenCLRuntime();
59
60 /// Emit the IR required for a work-group-local variable declaration, and add
61 /// an entry to CGF's LocalDeclMap for D. The base class does this using
62 /// CodeGenFunction::EmitStaticVarDecl to emit an internal global for D.
63 virtual void EmitWorkGroupLocalVarDecl(CodeGenFunction &CGF,
64 const VarDecl &D);
Guy Benyeid8a08ea2012-12-18 14:38:23 +000065
66 virtual llvm::Type *convertOpenCLSpecificType(const Type *T);
Xiuli Pan9c14e282016-01-09 12:53:17 +000067
Sven van Haastregtefb4d4c2017-08-15 09:38:18 +000068 virtual llvm::Type *getPipeType(const PipeType *T);
Yaxun Liu0bc4b2d2016-07-28 19:26:30 +000069
Sven van Haastregtefb4d4c2017-08-15 09:38:18 +000070 llvm::PointerType *getSamplerType(const Type *T);
Alexey Bader465c1892016-09-23 14:20:00 +000071
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000072 // Returns a value which indicates the size in bytes of the pipe
Alexey Bader465c1892016-09-23 14:20:00 +000073 // element.
74 virtual llvm::Value *getPipeElemSize(const Expr *PipeArg);
75
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000076 // Returns a value which indicates the alignment in bytes of the pipe
Alexey Bader465c1892016-09-23 14:20:00 +000077 // element.
78 virtual llvm::Value *getPipeElemAlign(const Expr *PipeArg);
Yaxun Liu10712d92017-10-04 20:32:17 +000079
80 /// \return __generic void* type.
81 llvm::PointerType *getGenericVoidPointerType();
Yaxun Liuc2a87a02017-10-14 12:23:50 +000082
83 /// \return enqueued block information for enqueued block.
84 EnqueuedBlockInfo emitOpenCLEnqueuedBlock(CodeGenFunction &CGF,
85 const Expr *E);
Yaxun Liufa13d012018-02-15 16:39:19 +000086
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000087 /// Record invoke function and block literal emitted during normal
Yaxun Liufa13d012018-02-15 16:39:19 +000088 /// codegen for a block expression. The information is used by
89 /// emitOpenCLEnqueuedBlock to emit wrapper kernel.
90 ///
91 /// \param InvokeF invoke function emitted for the block expression.
92 /// \param Block block literal emitted for the block expression.
93 void recordBlockInfo(const BlockExpr *E, llvm::Function *InvokeF,
94 llvm::Value *Block);
Guy Benyei11169dd2012-12-18 14:30:41 +000095};
96
Alexander Kornienkoab9db512015-06-22 23:07:51 +000097}
98}
Guy Benyei11169dd2012-12-18 14:30:41 +000099
100#endif