blob: ead303d1d0d5edaf9e8726a690216540caa0556d [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 Liuc2a87a02017-10-14 12:23:50 +000026class Expr;
Guy Benyei11169dd2012-12-18 14:30:41 +000027class VarDecl;
28
29namespace CodeGen {
30
31class CodeGenFunction;
32class CodeGenModule;
33
34class CGOpenCLRuntime {
35protected:
36 CodeGenModule &CGM;
Xiuli Pan9c14e282016-01-09 12:53:17 +000037 llvm::Type *PipeTy;
Yaxun Liu0bc4b2d2016-07-28 19:26:30 +000038 llvm::PointerType *SamplerTy;
Guy Benyei11169dd2012-12-18 14:30:41 +000039
Yaxun Liuc2a87a02017-10-14 12:23:50 +000040 /// 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 Benyei11169dd2012-12-18 14:30:41 +000048public:
Yaxun Liu0bc4b2d2016-07-28 19:26:30 +000049 CGOpenCLRuntime(CodeGenModule &CGM) : CGM(CGM), PipeTy(nullptr),
50 SamplerTy(nullptr) {}
Guy Benyei11169dd2012-12-18 14:30:41 +000051 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 Benyeid8a08ea2012-12-18 14:38:23 +000058
59 virtual llvm::Type *convertOpenCLSpecificType(const Type *T);
Xiuli Pan9c14e282016-01-09 12:53:17 +000060
Sven van Haastregtefb4d4c2017-08-15 09:38:18 +000061 virtual llvm::Type *getPipeType(const PipeType *T);
Yaxun Liu0bc4b2d2016-07-28 19:26:30 +000062
Sven van Haastregtefb4d4c2017-08-15 09:38:18 +000063 llvm::PointerType *getSamplerType(const Type *T);
Alexey Bader465c1892016-09-23 14:20:00 +000064
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 Liu10712d92017-10-04 20:32:17 +000072
73 /// \return __generic void* type.
74 llvm::PointerType *getGenericVoidPointerType();
Yaxun Liuc2a87a02017-10-14 12:23:50 +000075
76 /// \return enqueued block information for enqueued block.
77 EnqueuedBlockInfo emitOpenCLEnqueuedBlock(CodeGenFunction &CGF,
78 const Expr *E);
Guy Benyei11169dd2012-12-18 14:30:41 +000079};
80
Alexander Kornienkoab9db512015-06-22 23:07:51 +000081}
82}
Guy Benyei11169dd2012-12-18 14:30:41 +000083
84#endif