1//===----- CGOpenCLRuntime.h - Interface to OpenCL Runtimes -----*- C++ -*-===//
2//
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
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
15#ifndef LLVM_CLANG_LIB_CODEGEN_CGOPENCLRUNTIME_H
16#define LLVM_CLANG_LIB_CODEGEN_CGOPENCLRUNTIME_H
17
18#include "clang/AST/Expr.h"
19#include "clang/AST/Type.h"
20#include "llvm/ADT/DenseMap.h"
21#include "llvm/ADT/StringMap.h"
22#include "llvm/IR/Type.h"
23#include "llvm/IR/Value.h"
24
25namespace clang {
26
27class BlockExpr;
28class Expr;
29class VarDecl;
30
31namespace CodeGen {
32
33class CodeGenFunction;
34class CodeGenModule;
35
36class CGOpenCLRuntime {
37protected:
38 CodeGenModule &CGM;
39 llvm::Type *PipeTy;
40 llvm::Type *SamplerTy;
41
42 /// Structure for enqueued block information.
43 struct EnqueuedBlockInfo {
44 llvm::Function *InvokeFunc; /// Block invoke function.
45 llvm::Value *KernelHandle; /// Enqueued block kernel reference.
46 llvm::Value *BlockArg; /// The first argument to enqueued block kernel.
47 llvm::Type *BlockTy; /// Type of the block argument.
48 };
49 /// Maps block expression to block information.
50 llvm::DenseMap<const Expr *, EnqueuedBlockInfo> EnqueuedBlockMap;
51
52 llvm::PointerType *getPointerType(const Type *T);
53
54public:
55 CGOpenCLRuntime(CodeGenModule &CGM)
56 : CGM(CGM), PipeTy(nullptr), SamplerTy(nullptr) {}
57 ~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 void EmitWorkGroupLocalVarDecl(CodeGenFunction &CGF, const VarDecl &D);
63
64 llvm::Type *convertOpenCLSpecificType(const Type *T);
65
66 llvm::Type *getPipeType(const PipeType *T);
67
68 llvm::Type *getSamplerType(const Type *T);
69
70 // Returns a value which indicates the size in bytes of the pipe
71 // element.
72 llvm::Value *getPipeElemSize(const Expr *PipeArg);
73
74 // Returns a value which indicates the alignment in bytes of the pipe
75 // element.
76 llvm::Value *getPipeElemAlign(const Expr *PipeArg);
77
78 /// \return __generic void* type.
79 llvm::PointerType *getGenericVoidPointerType();
80
81 /// \return enqueued block information for enqueued block.
82 EnqueuedBlockInfo emitOpenCLEnqueuedBlock(CodeGenFunction &CGF,
83 const Expr *E);
84
85 /// Record invoke function and block literal emitted during normal
86 /// codegen for a block expression. The information is used by
87 /// emitOpenCLEnqueuedBlock to emit wrapper kernel.
88 ///
89 /// \param InvokeF invoke function emitted for the block expression.
90 /// \param Block block literal emitted for the block expression.
91 void recordBlockInfo(const BlockExpr *E, llvm::Function *InvokeF,
92 llvm::Value *Block, llvm::Type *BlockTy);
93
94 /// \return LLVM block invoke function emitted for an expression derived from
95 /// the block expression.
96 llvm::Function *getInvokeFunction(const Expr *E);
97};
98
99}
100}
101
102#endif
103