blob: 3f7aa9b0d8dc1977de927a4ea0568578c818b2e1 [file] [log] [blame]
Guy Benyei11169dd2012-12-18 14:30:41 +00001//===----- CGOpenCLRuntime.h - Interface to OpenCL Runtimes -----*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Benyei11169dd2012-12-18 14:30:41 +00006//
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 Kramer2f5db8b2014-08-13 16:25:19 +000015#ifndef LLVM_CLANG_LIB_CODEGEN_CGOPENCLRUNTIME_H
16#define LLVM_CLANG_LIB_CODEGEN_CGOPENCLRUNTIME_H
Guy Benyei11169dd2012-12-18 14:30:41 +000017
Richard Trieuf8b8b392019-01-11 01:32:35 +000018#include "clang/AST/Expr.h"
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;
Sven van Haastregt4700faa2018-04-27 10:37:04 +000038 llvm::Type *PipeROTy;
39 llvm::Type *PipeWOTy;
Yaxun Liu0bc4b2d2016-07-28 19:26:30 +000040 llvm::PointerType *SamplerTy;
Guy Benyei11169dd2012-12-18 14:30:41 +000041
Yaxun Liuc2a87a02017-10-14 12:23:50 +000042 /// Structure for enqueued block information.
43 struct EnqueuedBlockInfo {
Yaxun Liufa13d012018-02-15 16:39:19 +000044 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 Liuc2a87a02017-10-14 12:23:50 +000047 };
48 /// Maps block expression to block information.
49 llvm::DenseMap<const Expr *, EnqueuedBlockInfo> EnqueuedBlockMap;
50
Sven van Haastregt4700faa2018-04-27 10:37:04 +000051 virtual llvm::Type *getPipeType(const PipeType *T, StringRef Name,
52 llvm::Type *&PipeTy);
53
Guy Benyei11169dd2012-12-18 14:30:41 +000054public:
Sven van Haastregt4700faa2018-04-27 10:37:04 +000055 CGOpenCLRuntime(CodeGenModule &CGM) : CGM(CGM),
56 PipeROTy(nullptr), PipeWOTy(nullptr), SamplerTy(nullptr) {}
Guy Benyei11169dd2012-12-18 14:30:41 +000057 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 Benyeid8a08ea2012-12-18 14:38:23 +000064
65 virtual llvm::Type *convertOpenCLSpecificType(const Type *T);
Xiuli Pan9c14e282016-01-09 12:53:17 +000066
Sven van Haastregtefb4d4c2017-08-15 09:38:18 +000067 virtual llvm::Type *getPipeType(const PipeType *T);
Yaxun Liu0bc4b2d2016-07-28 19:26:30 +000068
Sven van Haastregtefb4d4c2017-08-15 09:38:18 +000069 llvm::PointerType *getSamplerType(const Type *T);
Alexey Bader465c1892016-09-23 14:20:00 +000070
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000071 // Returns a value which indicates the size in bytes of the pipe
Alexey Bader465c1892016-09-23 14:20:00 +000072 // element.
73 virtual llvm::Value *getPipeElemSize(const Expr *PipeArg);
74
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000075 // Returns a value which indicates the alignment in bytes of the pipe
Alexey Bader465c1892016-09-23 14:20:00 +000076 // element.
77 virtual llvm::Value *getPipeElemAlign(const Expr *PipeArg);
Yaxun Liu10712d92017-10-04 20:32:17 +000078
79 /// \return __generic void* type.
80 llvm::PointerType *getGenericVoidPointerType();
Yaxun Liuc2a87a02017-10-14 12:23:50 +000081
82 /// \return enqueued block information for enqueued block.
83 EnqueuedBlockInfo emitOpenCLEnqueuedBlock(CodeGenFunction &CGF,
84 const Expr *E);
Yaxun Liufa13d012018-02-15 16:39:19 +000085
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000086 /// Record invoke function and block literal emitted during normal
Yaxun Liufa13d012018-02-15 16:39:19 +000087 /// 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 Savonichev43fceb22019-02-21 11:02:10 +000094
95 /// \return LLVM block invoke function emitted for an expression derived from
96 /// the block expression.
97 llvm::Function *getInvokeFunction(const Expr *E);
Guy Benyei11169dd2012-12-18 14:30:41 +000098};
99
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000100}
101}
Guy Benyei11169dd2012-12-18 14:30:41 +0000102
103#endif