clang  14.0.0git
CGOpenCLRuntime.h
Go to the documentation of this file.
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/IR/Type.h"
22 #include "llvm/IR/Value.h"
23 
24 namespace clang {
25 
26 class BlockExpr;
27 class Expr;
28 class VarDecl;
29 
30 namespace CodeGen {
31 
32 class CodeGenFunction;
33 class CodeGenModule;
34 
36 protected:
38  llvm::Type *PipeROTy;
39  llvm::Type *PipeWOTy;
40  llvm::PointerType *SamplerTy;
41 
42  /// Structure for enqueued block information.
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.
47  };
48  /// Maps block expression to block information.
49  llvm::DenseMap<const Expr *, EnqueuedBlockInfo> EnqueuedBlockMap;
50 
51  virtual llvm::Type *getPipeType(const PipeType *T, StringRef Name,
52  llvm::Type *&PipeTy);
53 
54 public:
56  PipeROTy(nullptr), PipeWOTy(nullptr), SamplerTy(nullptr) {}
57  virtual ~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.
63  const VarDecl &D);
64 
65  virtual llvm::Type *convertOpenCLSpecificType(const Type *T);
66 
67  virtual llvm::Type *getPipeType(const PipeType *T);
68 
69  llvm::PointerType *getSamplerType(const Type *T);
70 
71  // Returns a value which indicates the size in bytes of the pipe
72  // element.
73  virtual llvm::Value *getPipeElemSize(const Expr *PipeArg);
74 
75  // Returns a value which indicates the alignment in bytes of the pipe
76  // element.
77  virtual llvm::Value *getPipeElemAlign(const Expr *PipeArg);
78 
79  /// \return __generic void* type.
80  llvm::PointerType *getGenericVoidPointerType();
81 
82  /// \return enqueued block information for enqueued block.
83  EnqueuedBlockInfo emitOpenCLEnqueuedBlock(CodeGenFunction &CGF,
84  const Expr *E);
85 
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.
89  ///
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,
93  llvm::Value *Block);
94 
95  /// \return LLVM block invoke function emitted for an expression derived from
96  /// the block expression.
97  llvm::Function *getInvokeFunction(const Expr *E);
98 };
99 
100 }
101 }
102 
103 #endif
clang::CodeGen::CGOpenCLRuntime::EnqueuedBlockMap
llvm::DenseMap< const Expr *, EnqueuedBlockInfo > EnqueuedBlockMap
Maps block expression to block information.
Definition: CGOpenCLRuntime.h:49
clang::CodeGen::CGOpenCLRuntime::getSamplerType
llvm::PointerType * getSamplerType(const Type *T)
Definition: CGOpenCLRuntime.cpp:89
clang::CodeGen::CGOpenCLRuntime::emitOpenCLEnqueuedBlock
EnqueuedBlockInfo emitOpenCLEnqueuedBlock(CodeGenFunction &CGF, const Expr *E)
Definition: CGOpenCLRuntime.cpp:161
clang::CodeGen::CGOpenCLRuntime::getPipeElemSize
virtual llvm::Value * getPipeElemSize(const Expr *PipeArg)
Definition: CGOpenCLRuntime.cpp:98
clang::PipeType
PipeType - OpenCL20.
Definition: Type.h:6272
clang::Type
The base class of the type hierarchy.
Definition: Type.h:1490
clang::CodeGen::CGOpenCLRuntime::PipeWOTy
llvm::Type * PipeWOTy
Definition: CGOpenCLRuntime.h:39
clang::CodeGen::CGOpenCLRuntime::recordBlockInfo
void recordBlockInfo(const BlockExpr *E, llvm::Function *InvokeF, llvm::Value *Block)
Record invoke function and block literal emitted during normal codegen for a block expression.
Definition: CGOpenCLRuntime.cpp:144
clang::CodeGen::CGOpenCLRuntime::PipeROTy
llvm::Type * PipeROTy
Definition: CGOpenCLRuntime.h:38
clang::CodeGen::CGOpenCLRuntime::EnqueuedBlockInfo::Kernel
llvm::Function * Kernel
Block invoke function.
Definition: CGOpenCLRuntime.h:45
clang::CodeGen::CGOpenCLRuntime::SamplerTy
llvm::PointerType * SamplerTy
Definition: CGOpenCLRuntime.h:40
Type.h
clang::CodeGen::CGOpenCLRuntime::getPipeElemAlign
virtual llvm::Value * getPipeElemAlign(const Expr *PipeArg)
Definition: CGOpenCLRuntime.cpp:108
Expr.h
clang::CodeGen::CGOpenCLRuntime
Definition: CGOpenCLRuntime.h:35
clang::VarDecl
Represents a variable declaration or definition.
Definition: Decl.h:876
clang::CodeGen::CGOpenCLRuntime::EmitWorkGroupLocalVarDecl
virtual void EmitWorkGroupLocalVarDecl(CodeGenFunction &CGF, const VarDecl &D)
Emit the IR required for a work-group-local variable declaration, and add an entry to CGF's LocalDecl...
Definition: CGOpenCLRuntime.cpp:28
clang::CodeGen::CGOpenCLRuntime::EnqueuedBlockInfo::InvokeFunc
llvm::Function * InvokeFunc
Definition: CGOpenCLRuntime.h:44
clang::CodeGen::CGOpenCLRuntime::getInvokeFunction
llvm::Function * getInvokeFunction(const Expr *E)
Definition: CGOpenCLRuntime.cpp:156
clang::CodeGen::CodeGenFunction
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
Definition: CodeGenFunction.h:235
clang::CodeGen::CodeGenModule
This class organizes the cross-function state that is used while generating LLVM code.
Definition: CodeGenModule.h:284
clang::BlockExpr
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition: Expr.h:5965
clang::CodeGen::CGOpenCLRuntime::EnqueuedBlockInfo
Structure for enqueued block information.
Definition: CGOpenCLRuntime.h:43
Value
Value
Definition: UninitializedValues.cpp:102
clang::CodeGen::CGOpenCLRuntime::~CGOpenCLRuntime
virtual ~CGOpenCLRuntime()
Definition: CGOpenCLRuntime.cpp:26
clang::CodeGen::CGOpenCLRuntime::convertOpenCLSpecificType
virtual llvm::Type * convertOpenCLSpecificType(const Type *T)
Definition: CGOpenCLRuntime.cpp:33
clang::CodeGen::CGOpenCLRuntime::getPipeType
virtual llvm::Type * getPipeType(const PipeType *T, StringRef Name, llvm::Type *&PipeTy)
Definition: CGOpenCLRuntime.cpp:79
clang
Definition: CalledOnceCheck.h:17
clang::CodeGen::CGOpenCLRuntime::CGOpenCLRuntime
CGOpenCLRuntime(CodeGenModule &CGM)
Definition: CGOpenCLRuntime.h:55
clang::CodeGen::CGOpenCLRuntime::EnqueuedBlockInfo::BlockArg
llvm::Value * BlockArg
Enqueued block kernel.
Definition: CGOpenCLRuntime.h:46
clang::CodeGen::CGOpenCLRuntime::getGenericVoidPointerType
llvm::PointerType * getGenericVoidPointerType()
Definition: CGOpenCLRuntime.cpp:118
clang::Expr
This represents one expression.
Definition: Expr.h:109
clang::CodeGen::CGOpenCLRuntime::CGM
CodeGenModule & CGM
Definition: CGOpenCLRuntime.h:37