xref: /openbsd-src/gnu/llvm/clang/lib/CodeGen/CGOpenCLRuntime.h (revision 12c855180aad702bbcca06e0398d774beeafb155)
1e5dd7070Spatrick //===----- CGOpenCLRuntime.h - Interface to OpenCL Runtimes -----*- C++ -*-===//
2e5dd7070Spatrick //
3e5dd7070Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e5dd7070Spatrick // See https://llvm.org/LICENSE.txt for license information.
5e5dd7070Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6e5dd7070Spatrick //
7e5dd7070Spatrick //===----------------------------------------------------------------------===//
8e5dd7070Spatrick //
9e5dd7070Spatrick // This provides an abstract class for OpenCL code generation.  Concrete
10e5dd7070Spatrick // subclasses of this implement code generation for specific OpenCL
11e5dd7070Spatrick // runtime libraries.
12e5dd7070Spatrick //
13e5dd7070Spatrick //===----------------------------------------------------------------------===//
14e5dd7070Spatrick 
15e5dd7070Spatrick #ifndef LLVM_CLANG_LIB_CODEGEN_CGOPENCLRUNTIME_H
16e5dd7070Spatrick #define LLVM_CLANG_LIB_CODEGEN_CGOPENCLRUNTIME_H
17e5dd7070Spatrick 
18e5dd7070Spatrick #include "clang/AST/Expr.h"
19e5dd7070Spatrick #include "clang/AST/Type.h"
20e5dd7070Spatrick #include "llvm/ADT/DenseMap.h"
21*12c85518Srobert #include "llvm/ADT/StringMap.h"
22e5dd7070Spatrick #include "llvm/IR/Type.h"
23e5dd7070Spatrick #include "llvm/IR/Value.h"
24e5dd7070Spatrick 
25e5dd7070Spatrick namespace clang {
26e5dd7070Spatrick 
27e5dd7070Spatrick class BlockExpr;
28e5dd7070Spatrick class Expr;
29e5dd7070Spatrick class VarDecl;
30e5dd7070Spatrick 
31e5dd7070Spatrick namespace CodeGen {
32e5dd7070Spatrick 
33e5dd7070Spatrick class CodeGenFunction;
34e5dd7070Spatrick class CodeGenModule;
35e5dd7070Spatrick 
36e5dd7070Spatrick class CGOpenCLRuntime {
37e5dd7070Spatrick protected:
38e5dd7070Spatrick   CodeGenModule &CGM;
39e5dd7070Spatrick   llvm::Type *PipeROTy;
40e5dd7070Spatrick   llvm::Type *PipeWOTy;
41e5dd7070Spatrick   llvm::PointerType *SamplerTy;
42*12c85518Srobert   llvm::StringMap<llvm::PointerType *> CachedTys;
43e5dd7070Spatrick 
44e5dd7070Spatrick   /// Structure for enqueued block information.
45e5dd7070Spatrick   struct EnqueuedBlockInfo {
46e5dd7070Spatrick     llvm::Function *InvokeFunc; /// Block invoke function.
47e5dd7070Spatrick     llvm::Function *Kernel;     /// Enqueued block kernel.
48e5dd7070Spatrick     llvm::Value *BlockArg;      /// The first argument to enqueued block kernel.
49*12c85518Srobert     llvm::Type *BlockTy;        /// Type of the block argument.
50e5dd7070Spatrick   };
51e5dd7070Spatrick   /// Maps block expression to block information.
52e5dd7070Spatrick   llvm::DenseMap<const Expr *, EnqueuedBlockInfo> EnqueuedBlockMap;
53e5dd7070Spatrick 
54e5dd7070Spatrick   virtual llvm::Type *getPipeType(const PipeType *T, StringRef Name,
55e5dd7070Spatrick                                   llvm::Type *&PipeTy);
56*12c85518Srobert   llvm::PointerType *getPointerType(const Type *T, StringRef Name);
57e5dd7070Spatrick 
58e5dd7070Spatrick public:
CGOpenCLRuntime(CodeGenModule & CGM)59e5dd7070Spatrick   CGOpenCLRuntime(CodeGenModule &CGM) : CGM(CGM),
60e5dd7070Spatrick     PipeROTy(nullptr), PipeWOTy(nullptr), SamplerTy(nullptr) {}
61e5dd7070Spatrick   virtual ~CGOpenCLRuntime();
62e5dd7070Spatrick 
63e5dd7070Spatrick   /// Emit the IR required for a work-group-local variable declaration, and add
64e5dd7070Spatrick   /// an entry to CGF's LocalDeclMap for D.  The base class does this using
65e5dd7070Spatrick   /// CodeGenFunction::EmitStaticVarDecl to emit an internal global for D.
66e5dd7070Spatrick   virtual void EmitWorkGroupLocalVarDecl(CodeGenFunction &CGF,
67e5dd7070Spatrick                                          const VarDecl &D);
68e5dd7070Spatrick 
69e5dd7070Spatrick   virtual llvm::Type *convertOpenCLSpecificType(const Type *T);
70e5dd7070Spatrick 
71e5dd7070Spatrick   virtual llvm::Type *getPipeType(const PipeType *T);
72e5dd7070Spatrick 
73e5dd7070Spatrick   llvm::PointerType *getSamplerType(const Type *T);
74e5dd7070Spatrick 
75e5dd7070Spatrick   // Returns a value which indicates the size in bytes of the pipe
76e5dd7070Spatrick   // element.
77e5dd7070Spatrick   virtual llvm::Value *getPipeElemSize(const Expr *PipeArg);
78e5dd7070Spatrick 
79e5dd7070Spatrick   // Returns a value which indicates the alignment in bytes of the pipe
80e5dd7070Spatrick   // element.
81e5dd7070Spatrick   virtual llvm::Value *getPipeElemAlign(const Expr *PipeArg);
82e5dd7070Spatrick 
83e5dd7070Spatrick   /// \return __generic void* type.
84e5dd7070Spatrick   llvm::PointerType *getGenericVoidPointerType();
85e5dd7070Spatrick 
86e5dd7070Spatrick   /// \return enqueued block information for enqueued block.
87e5dd7070Spatrick   EnqueuedBlockInfo emitOpenCLEnqueuedBlock(CodeGenFunction &CGF,
88e5dd7070Spatrick                                             const Expr *E);
89e5dd7070Spatrick 
90e5dd7070Spatrick   /// Record invoke function and block literal emitted during normal
91e5dd7070Spatrick   /// codegen for a block expression. The information is used by
92e5dd7070Spatrick   /// emitOpenCLEnqueuedBlock to emit wrapper kernel.
93e5dd7070Spatrick   ///
94e5dd7070Spatrick   /// \param InvokeF invoke function emitted for the block expression.
95e5dd7070Spatrick   /// \param Block block literal emitted for the block expression.
96e5dd7070Spatrick   void recordBlockInfo(const BlockExpr *E, llvm::Function *InvokeF,
97*12c85518Srobert                        llvm::Value *Block, llvm::Type *BlockTy);
98e5dd7070Spatrick 
99e5dd7070Spatrick   /// \return LLVM block invoke function emitted for an expression derived from
100e5dd7070Spatrick   /// the block expression.
101e5dd7070Spatrick   llvm::Function *getInvokeFunction(const Expr *E);
102e5dd7070Spatrick };
103e5dd7070Spatrick 
104e5dd7070Spatrick }
105e5dd7070Spatrick }
106e5dd7070Spatrick 
107e5dd7070Spatrick #endif
108