1 //===----- CGOpenCLRuntime.h - Interface to OpenCL Runtimes -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This provides an abstract class for OpenCL code generation. Concrete
11 // subclasses of this implement code generation for specific OpenCL
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_CLANG_LIB_CODEGEN_CGOPENCLRUNTIME_H
17 #define LLVM_CLANG_LIB_CODEGEN_CGOPENCLRUNTIME_H
19 #include "clang/AST/Type.h"
20 #include "llvm/ADT/DenseMap.h"
21 #include "llvm/IR/Type.h"
22 #include "llvm/IR/Value.h"
32 class CodeGenFunction;
35 class CGOpenCLRuntime {
40 llvm::PointerType *SamplerTy;
42 /// Structure for enqueued block information.
43 struct EnqueuedBlockInfo {
44 llvm::Function *InvokeFunc; /// Block invoke function.
45 llvm::Function *Kernel; /// Enqueued block kernel.
46 llvm::Value *BlockArg; /// The first argument to enqueued block kernel.
48 /// Maps block expression to block information.
49 llvm::DenseMap<const Expr *, EnqueuedBlockInfo> EnqueuedBlockMap;
51 virtual llvm::Type *getPipeType(const PipeType *T, StringRef Name,
55 CGOpenCLRuntime(CodeGenModule &CGM) : CGM(CGM),
56 PipeROTy(nullptr), PipeWOTy(nullptr), SamplerTy(nullptr) {}
57 virtual ~CGOpenCLRuntime();
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,
65 virtual llvm::Type *convertOpenCLSpecificType(const Type *T);
67 virtual llvm::Type *getPipeType(const PipeType *T);
69 llvm::PointerType *getSamplerType(const Type *T);
71 // Returns a value which indicates the size in bytes of the pipe
73 virtual llvm::Value *getPipeElemSize(const Expr *PipeArg);
75 // Returns a value which indicates the alignment in bytes of the pipe
77 virtual llvm::Value *getPipeElemAlign(const Expr *PipeArg);
79 /// \return __generic void* type.
80 llvm::PointerType *getGenericVoidPointerType();
82 /// \return enqueued block information for enqueued block.
83 EnqueuedBlockInfo emitOpenCLEnqueuedBlock(CodeGenFunction &CGF,
86 /// Record invoke function and block literal emitted during normal
87 /// codegen for a block expression. The information is used by
88 /// emitOpenCLEnqueuedBlock to emit wrapper kernel.
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,
95 /// \return LLVM block invoke function emitted for an expression derived from
96 /// the block expression.
97 llvm::Function *getInvokeFunction(const Expr *E);