clang  16.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/ADT/StringMap.h"
22 #include "llvm/IR/Type.h"
23 #include "llvm/IR/Value.h"
24 
25 namespace clang {
26 
27 class BlockExpr;
28 class Expr;
29 class VarDecl;
30 
31 namespace CodeGen {
32 
33 class CodeGenFunction;
34 class CodeGenModule;
35 
37 protected:
39  llvm::Type *PipeROTy;
40  llvm::Type *PipeWOTy;
41  llvm::PointerType *SamplerTy;
42  llvm::StringMap<llvm::PointerType *> CachedTys;
43 
44  /// Structure for enqueued block information.
46  llvm::Function *InvokeFunc; /// Block invoke function.
47  llvm::Function *Kernel; /// Enqueued block kernel.
48  llvm::Value *BlockArg; /// The first argument to enqueued block kernel.
49  llvm::Type *BlockTy; /// Type of the block argument.
50  };
51  /// Maps block expression to block information.
52  llvm::DenseMap<const Expr *, EnqueuedBlockInfo> EnqueuedBlockMap;
53 
54  virtual llvm::Type *getPipeType(const PipeType *T, StringRef Name,
55  llvm::Type *&PipeTy);
56  llvm::PointerType *getPointerType(const Type *T, StringRef Name);
57 
58 public:
60  PipeROTy(nullptr), PipeWOTy(nullptr), SamplerTy(nullptr) {}
61  virtual ~CGOpenCLRuntime();
62 
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.
67  const VarDecl &D);
68 
69  virtual llvm::Type *convertOpenCLSpecificType(const Type *T);
70 
71  virtual llvm::Type *getPipeType(const PipeType *T);
72 
73  llvm::PointerType *getSamplerType(const Type *T);
74 
75  // Returns a value which indicates the size in bytes of the pipe
76  // element.
77  virtual llvm::Value *getPipeElemSize(const Expr *PipeArg);
78 
79  // Returns a value which indicates the alignment in bytes of the pipe
80  // element.
81  virtual llvm::Value *getPipeElemAlign(const Expr *PipeArg);
82 
83  /// \return __generic void* type.
84  llvm::PointerType *getGenericVoidPointerType();
85 
86  /// \return enqueued block information for enqueued block.
87  EnqueuedBlockInfo emitOpenCLEnqueuedBlock(CodeGenFunction &CGF,
88  const Expr *E);
89 
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.
93  ///
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);
98 
99  /// \return LLVM block invoke function emitted for an expression derived from
100  /// the block expression.
101  llvm::Function *getInvokeFunction(const Expr *E);
102 };
103 
104 }
105 }
106 
107 #endif
clang::CodeGen::CGOpenCLRuntime::EnqueuedBlockMap
llvm::DenseMap< const Expr *, EnqueuedBlockInfo > EnqueuedBlockMap
Maps block expression to block information.
Definition: CGOpenCLRuntime.h:52
clang::CodeGen::CGOpenCLRuntime::getSamplerType
llvm::PointerType * getSamplerType(const Type *T)
Definition: CGOpenCLRuntime.cpp:94
clang::CodeGen::CGOpenCLRuntime::emitOpenCLEnqueuedBlock
EnqueuedBlockInfo emitOpenCLEnqueuedBlock(CodeGenFunction &CGF, const Expr *E)
Definition: CGOpenCLRuntime.cpp:167
clang::CodeGen::CGOpenCLRuntime::getPipeElemSize
virtual llvm::Value * getPipeElemSize(const Expr *PipeArg)
Definition: CGOpenCLRuntime.cpp:103
clang::PipeType
PipeType - OpenCL20.
Definition: Type.h:6431
clang::CodeGen::CGOpenCLRuntime::EnqueuedBlockInfo::BlockTy
llvm::Type * BlockTy
The first argument to enqueued block kernel.
Definition: CGOpenCLRuntime.h:49
clang::Type
The base class of the type hierarchy.
Definition: Type.h:1559
clang::CodeGen::CGOpenCLRuntime::PipeWOTy
llvm::Type * PipeWOTy
Definition: CGOpenCLRuntime.h:40
clang::CodeGen::CGOpenCLRuntime::PipeROTy
llvm::Type * PipeROTy
Definition: CGOpenCLRuntime.h:39
clang::CodeGen::CGOpenCLRuntime::EnqueuedBlockInfo::Kernel
llvm::Function * Kernel
Block invoke function.
Definition: CGOpenCLRuntime.h:47
clang::CodeGen::CGOpenCLRuntime::SamplerTy
llvm::PointerType * SamplerTy
Definition: CGOpenCLRuntime.h:41
Type.h
clang::CodeGen::CGOpenCLRuntime::getPipeElemAlign
virtual llvm::Value * getPipeElemAlign(const Expr *PipeArg)
Definition: CGOpenCLRuntime.cpp:113
Expr.h
clang::CodeGen::CGOpenCLRuntime
Definition: CGOpenCLRuntime.h:36
clang::VarDecl
Represents a variable declaration or definition.
Definition: Decl.h:879
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:46
clang::CodeGen::CGOpenCLRuntime::recordBlockInfo
void recordBlockInfo(const BlockExpr *E, llvm::Function *InvokeF, llvm::Value *Block, llvm::Type *BlockTy)
Record invoke function and block literal emitted during normal codegen for a block expression.
Definition: CGOpenCLRuntime.cpp:149
clang::CodeGen::CGOpenCLRuntime::getInvokeFunction
llvm::Function * getInvokeFunction(const Expr *E)
Definition: CGOpenCLRuntime.cpp:162
clang::CodeGen::CodeGenFunction
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
Definition: CodeGenFunction.h:231
clang::CodeGen::CodeGenModule
This class organizes the cross-function state that is used while generating LLVM code.
Definition: CodeGenModule.h:279
clang::BlockExpr
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition: Expr.h:5970
clang::CodeGen::CGOpenCLRuntime::EnqueuedBlockInfo
Structure for enqueued block information.
Definition: CGOpenCLRuntime.h:45
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:84
clang
Definition: CalledOnceCheck.h:17
clang::CodeGen::CGOpenCLRuntime::CachedTys
llvm::StringMap< llvm::PointerType * > CachedTys
Definition: CGOpenCLRuntime.h:42
clang::CodeGen::CGOpenCLRuntime::CGOpenCLRuntime
CGOpenCLRuntime(CodeGenModule &CGM)
Definition: CGOpenCLRuntime.h:59
clang::CodeGen::CGOpenCLRuntime::getPointerType
llvm::PointerType * getPointerType(const Type *T, StringRef Name)
Definition: CGOpenCLRuntime.cpp:62
clang::CodeGen::CGOpenCLRuntime::EnqueuedBlockInfo::BlockArg
llvm::Value * BlockArg
Enqueued block kernel.
Definition: CGOpenCLRuntime.h:48
clang::CodeGen::CGOpenCLRuntime::getGenericVoidPointerType
llvm::PointerType * getGenericVoidPointerType()
Definition: CGOpenCLRuntime.cpp:123
clang::Expr
This represents one expression.
Definition: Expr.h:109
clang::CodeGen::CGOpenCLRuntime::CGM
CodeGenModule & CGM
Definition: CGOpenCLRuntime.h:38