1 //===----- CGOpenCLRuntime.h - Interface to OpenCL Runtimes -----*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This provides an abstract class for OpenCL code generation. Concrete
10 // subclasses of this implement code generation for specific OpenCL
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_LIB_CODEGEN_CGOPENCLRUNTIME_H
16 #define LLVM_CLANG_LIB_CODEGEN_CGOPENCLRUNTIME_H
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"
33 class CodeGenFunction
;
36 class CGOpenCLRuntime
{
41 llvm::Type
*SamplerTy
;
42 llvm::StringMap
<llvm::PointerType
*> CachedTys
;
44 /// Structure for enqueued block information.
45 struct EnqueuedBlockInfo
{
46 llvm::Function
*InvokeFunc
; /// Block invoke function.
47 llvm::Value
*KernelHandle
; /// Enqueued block kernel reference.
48 llvm::Value
*BlockArg
; /// The first argument to enqueued block kernel.
49 llvm::Type
*BlockTy
; /// Type of the block argument.
51 /// Maps block expression to block information.
52 llvm::DenseMap
<const Expr
*, EnqueuedBlockInfo
> EnqueuedBlockMap
;
54 virtual llvm::Type
*getPipeType(const PipeType
*T
, StringRef Name
,
56 llvm::PointerType
*getPointerType(const Type
*T
, StringRef Name
);
59 CGOpenCLRuntime(CodeGenModule
&CGM
) : CGM(CGM
),
60 PipeROTy(nullptr), PipeWOTy(nullptr), SamplerTy(nullptr) {}
61 virtual ~CGOpenCLRuntime();
63 /// Emit the IR required for a work-group-local variable declaration, and add
64 /// an entry to CGF's LocalDeclMap for D. The base class does this using
65 /// CodeGenFunction::EmitStaticVarDecl to emit an internal global for D.
66 virtual void EmitWorkGroupLocalVarDecl(CodeGenFunction
&CGF
,
69 virtual llvm::Type
*convertOpenCLSpecificType(const Type
*T
);
71 virtual llvm::Type
*getPipeType(const PipeType
*T
);
73 llvm::Type
*getSamplerType(const Type
*T
);
75 // Returns a value which indicates the size in bytes of the pipe
77 virtual llvm::Value
*getPipeElemSize(const Expr
*PipeArg
);
79 // Returns a value which indicates the alignment in bytes of the pipe
81 virtual llvm::Value
*getPipeElemAlign(const Expr
*PipeArg
);
83 /// \return __generic void* type.
84 llvm::PointerType
*getGenericVoidPointerType();
86 /// \return enqueued block information for enqueued block.
87 EnqueuedBlockInfo
emitOpenCLEnqueuedBlock(CodeGenFunction
&CGF
,
90 /// Record invoke function and block literal emitted during normal
91 /// codegen for a block expression. The information is used by
92 /// emitOpenCLEnqueuedBlock to emit wrapper kernel.
94 /// \param InvokeF invoke function emitted for the block expression.
95 /// \param Block block literal emitted for the block expression.
96 void recordBlockInfo(const BlockExpr
*E
, llvm::Function
*InvokeF
,
97 llvm::Value
*Block
, llvm::Type
*BlockTy
);
99 /// \return LLVM block invoke function emitted for an expression derived from
100 /// the block expression.
101 llvm::Function
*getInvokeFunction(const Expr
*E
);