2012-12-18 22:30:41 +08:00
|
|
|
//===----- CGOpenCLRuntime.h - Interface to OpenCL Runtimes -----*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This provides an abstract class for OpenCL code generation. Concrete
|
|
|
|
// subclasses of this implement code generation for specific OpenCL
|
|
|
|
// runtime libraries.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:25:19 +08:00
|
|
|
#ifndef LLVM_CLANG_LIB_CODEGEN_CGOPENCLRUNTIME_H
|
|
|
|
#define LLVM_CLANG_LIB_CODEGEN_CGOPENCLRUNTIME_H
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2012-12-18 22:38:23 +08:00
|
|
|
#include "clang/AST/Type.h"
|
2017-10-14 20:23:50 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2013-01-02 19:45:17 +08:00
|
|
|
#include "llvm/IR/Type.h"
|
|
|
|
#include "llvm/IR/Value.h"
|
2012-12-18 22:38:23 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
namespace clang {
|
|
|
|
|
2018-02-16 00:39:19 +08:00
|
|
|
class BlockExpr;
|
2017-10-14 20:23:50 +08:00
|
|
|
class Expr;
|
2012-12-18 22:30:41 +08:00
|
|
|
class VarDecl;
|
|
|
|
|
|
|
|
namespace CodeGen {
|
|
|
|
|
|
|
|
class CodeGenFunction;
|
|
|
|
class CodeGenModule;
|
|
|
|
|
|
|
|
class CGOpenCLRuntime {
|
|
|
|
protected:
|
|
|
|
CodeGenModule &CGM;
|
2018-04-27 18:37:04 +08:00
|
|
|
llvm::Type *PipeROTy;
|
|
|
|
llvm::Type *PipeWOTy;
|
2016-07-29 03:26:30 +08:00
|
|
|
llvm::PointerType *SamplerTy;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2017-10-14 20:23:50 +08:00
|
|
|
/// Structure for enqueued block information.
|
|
|
|
struct EnqueuedBlockInfo {
|
2018-02-16 00:39:19 +08:00
|
|
|
llvm::Function *InvokeFunc; /// Block invoke function.
|
|
|
|
llvm::Function *Kernel; /// Enqueued block kernel.
|
|
|
|
llvm::Value *BlockArg; /// The first argument to enqueued block kernel.
|
2017-10-14 20:23:50 +08:00
|
|
|
};
|
|
|
|
/// Maps block expression to block information.
|
|
|
|
llvm::DenseMap<const Expr *, EnqueuedBlockInfo> EnqueuedBlockMap;
|
|
|
|
|
2018-04-27 18:37:04 +08:00
|
|
|
virtual llvm::Type *getPipeType(const PipeType *T, StringRef Name,
|
|
|
|
llvm::Type *&PipeTy);
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
public:
|
2018-04-27 18:37:04 +08:00
|
|
|
CGOpenCLRuntime(CodeGenModule &CGM) : CGM(CGM),
|
|
|
|
PipeROTy(nullptr), PipeWOTy(nullptr), SamplerTy(nullptr) {}
|
2012-12-18 22:30:41 +08:00
|
|
|
virtual ~CGOpenCLRuntime();
|
|
|
|
|
|
|
|
/// Emit the IR required for a work-group-local variable declaration, and add
|
|
|
|
/// an entry to CGF's LocalDeclMap for D. The base class does this using
|
|
|
|
/// CodeGenFunction::EmitStaticVarDecl to emit an internal global for D.
|
|
|
|
virtual void EmitWorkGroupLocalVarDecl(CodeGenFunction &CGF,
|
|
|
|
const VarDecl &D);
|
2012-12-18 22:38:23 +08:00
|
|
|
|
|
|
|
virtual llvm::Type *convertOpenCLSpecificType(const Type *T);
|
2016-01-09 20:53:17 +08:00
|
|
|
|
2017-08-15 17:38:18 +08:00
|
|
|
virtual llvm::Type *getPipeType(const PipeType *T);
|
2016-07-29 03:26:30 +08:00
|
|
|
|
2017-08-15 17:38:18 +08:00
|
|
|
llvm::PointerType *getSamplerType(const Type *T);
|
2016-09-23 22:20:00 +08:00
|
|
|
|
2018-04-06 23:14:32 +08:00
|
|
|
// \brief Returns a value which indicates the size in bytes of the pipe
|
2016-09-23 22:20:00 +08:00
|
|
|
// element.
|
|
|
|
virtual llvm::Value *getPipeElemSize(const Expr *PipeArg);
|
|
|
|
|
2018-04-06 23:14:32 +08:00
|
|
|
// \brief Returns a value which indicates the alignment in bytes of the pipe
|
2016-09-23 22:20:00 +08:00
|
|
|
// element.
|
|
|
|
virtual llvm::Value *getPipeElemAlign(const Expr *PipeArg);
|
2017-10-05 04:32:17 +08:00
|
|
|
|
|
|
|
/// \return __generic void* type.
|
|
|
|
llvm::PointerType *getGenericVoidPointerType();
|
2017-10-14 20:23:50 +08:00
|
|
|
|
|
|
|
/// \return enqueued block information for enqueued block.
|
|
|
|
EnqueuedBlockInfo emitOpenCLEnqueuedBlock(CodeGenFunction &CGF,
|
|
|
|
const Expr *E);
|
2018-02-16 00:39:19 +08:00
|
|
|
|
|
|
|
/// \brief Record invoke function and block literal emitted during normal
|
|
|
|
/// codegen for a block expression. The information is used by
|
|
|
|
/// emitOpenCLEnqueuedBlock to emit wrapper kernel.
|
|
|
|
///
|
|
|
|
/// \param InvokeF invoke function emitted for the block expression.
|
|
|
|
/// \param Block block literal emitted for the block expression.
|
|
|
|
void recordBlockInfo(const BlockExpr *E, llvm::Function *InvokeF,
|
|
|
|
llvm::Value *Block);
|
2018-03-08 03:32:58 +08:00
|
|
|
|
|
|
|
/// \return LLVM block invoke function emitted for an expression derived from
|
|
|
|
/// the block expression.
|
|
|
|
llvm::Function *getInvokeFunction(const Expr *E);
|
2012-12-18 22:30:41 +08:00
|
|
|
};
|
|
|
|
|
2015-06-23 07:07:51 +08:00
|
|
|
}
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
#endif
|