clang  14.0.0git
CGCUDARuntime.h
Go to the documentation of this file.
1 //===----- CGCUDARuntime.h - Interface to CUDA 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 CUDA code generation. Concrete
10 // subclasses of this implement code generation for specific CUDA
11 // runtime libraries.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CLANG_LIB_CODEGEN_CGCUDARUNTIME_H
16 #define LLVM_CLANG_LIB_CODEGEN_CGCUDARUNTIME_H
17 
18 #include "clang/AST/GlobalDecl.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/IR/GlobalValue.h"
21 
22 namespace llvm {
23 class Function;
24 class GlobalVariable;
25 }
26 
27 namespace clang {
28 
29 class CUDAKernelCallExpr;
30 class NamedDecl;
31 class VarDecl;
32 
33 namespace CodeGen {
34 
35 class CodeGenFunction;
36 class CodeGenModule;
37 class FunctionArgList;
38 class ReturnValueSlot;
39 class RValue;
40 
42 protected:
44 
45 public:
46  // Global variable properties that must be passed to CUDA runtime.
48  public:
50  Variable, // Variable
51  Surface, // Builtin surface
52  Texture, // Builtin texture
53  };
54 
55  private:
56  unsigned Kind : 2;
57  unsigned Extern : 1;
58  unsigned Constant : 1; // Constant variable.
59  unsigned Managed : 1; // Managed variable.
60  unsigned Normalized : 1; // Normalized texture.
61  int SurfTexType; // Type of surface/texutre.
62 
63  public:
64  DeviceVarFlags(DeviceVarKind K, bool E, bool C, bool M, bool N, int T)
65  : Kind(K), Extern(E), Constant(C), Managed(M), Normalized(N),
66  SurfTexType(T) {}
67 
68  DeviceVarKind getKind() const { return static_cast<DeviceVarKind>(Kind); }
69  bool isExtern() const { return Extern; }
70  bool isConstant() const { return Constant; }
71  bool isManaged() const { return Managed; }
72  bool isNormalized() const { return Normalized; }
73  int getSurfTexType() const { return SurfTexType; }
74  };
75 
77  virtual ~CGCUDARuntime();
78 
80  const CUDAKernelCallExpr *E,
81  ReturnValueSlot ReturnValue);
82 
83  /// Emits a kernel launch stub.
84  virtual void emitDeviceStub(CodeGenFunction &CGF, FunctionArgList &Args) = 0;
85 
86  /// Check whether a variable is a device variable and register it if true.
87  virtual void handleVarRegistration(const VarDecl *VD,
88  llvm::GlobalVariable &Var) = 0;
89 
90  /// Finalize generated LLVM module. Returns a module constructor function
91  /// to be added or a null pointer.
92  virtual llvm::Function *finalizeModule() = 0;
93 
94  /// Returns function or variable name on device side even if the current
95  /// compilation is for host.
96  virtual std::string getDeviceSideName(const NamedDecl *ND) = 0;
97 
98  /// Get kernel handle by stub function.
99  virtual llvm::GlobalValue *getKernelHandle(llvm::Function *Stub,
100  GlobalDecl GD) = 0;
101 
102  /// Get kernel stub by kernel handle.
103  virtual llvm::Function *getKernelStub(llvm::GlobalValue *Handle) = 0;
104 
105  /// Adjust linkage of shadow variables in host compilation.
106  virtual void
108  llvm::GlobalValue::LinkageTypes &Linkage) = 0;
109 };
110 
111 /// Creates an instance of a CUDA runtime class.
112 CGCUDARuntime *CreateNVCUDARuntime(CodeGenModule &CGM);
113 
114 }
115 }
116 
117 #endif
clang::CodeGen::CGCUDARuntime::finalizeModule
virtual llvm::Function * finalizeModule()=0
Finalize generated LLVM module.
clang::CodeGen::CGCUDARuntime::CGM
CodeGenModule & CGM
Definition: CGCUDARuntime.h:43
llvm
Definition: Dominators.h:30
clang::CodeGen::CGCUDARuntime
Definition: CGCUDARuntime.h:41
clang::CodeGen::RValue
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
Definition: CGValue.h:39
clang::CodeGen::CGCUDARuntime::DeviceVarFlags::isConstant
bool isConstant() const
Definition: CGCUDARuntime.h:70
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:249
clang::CodeGen::CGCUDARuntime::DeviceVarFlags::Surface
@ Surface
Definition: CGCUDARuntime.h:51
clang::CodeGen::CGCUDARuntime::getKernelHandle
virtual llvm::GlobalValue * getKernelHandle(llvm::Function *Stub, GlobalDecl GD)=0
Get kernel handle by stub function.
clang::CodeGen::CGCUDARuntime::handleVarRegistration
virtual void handleVarRegistration(const VarDecl *VD, llvm::GlobalVariable &Var)=0
Check whether a variable is a device variable and register it if true.
clang::CodeGen::CGCUDARuntime::DeviceVarFlags::Variable
@ Variable
Definition: CGCUDARuntime.h:50
clang::GlobalDecl
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:55
clang::CodeGen::ReturnValueSlot
ReturnValueSlot - Contains the address where the return value of a function can be stored,...
Definition: CGCall.h:362
clang::CodeGen::CGCUDARuntime::DeviceVarFlags
Definition: CGCUDARuntime.h:47
clang::CodeGen::CGCUDARuntime::getDeviceSideName
virtual std::string getDeviceSideName(const NamedDecl *ND)=0
Returns function or variable name on device side even if the current compilation is for host.
clang::Linkage
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.
Definition: Linkage.h:23
clang::CodeGen::CreateNVCUDARuntime
CGCUDARuntime * CreateNVCUDARuntime(CodeGenModule &CGM)
Creates an instance of a CUDA runtime class.
Definition: CGCUDANV.cpp:987
clang::CodeGen::CGCUDARuntime::EmitCUDAKernelCallExpr
virtual RValue EmitCUDAKernelCallExpr(CodeGenFunction &CGF, const CUDAKernelCallExpr *E, ReturnValueSlot ReturnValue)
Definition: CGCUDARuntime.cpp:26
clang::VarDecl
Represents a variable declaration or definition.
Definition: Decl.h:876
clang::CodeGen::CGCUDARuntime::DeviceVarFlags::isManaged
bool isManaged() const
Definition: CGCUDARuntime.h:71
clang::CodeGen::CGCUDARuntime::internalizeDeviceSideVar
virtual void internalizeDeviceSideVar(const VarDecl *D, llvm::GlobalValue::LinkageTypes &Linkage)=0
Adjust linkage of shadow variables in host compilation.
clang::CodeGen::CodeGenFunction
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
Definition: CodeGenFunction.h:235
clang::CodeGen::CGCUDARuntime::DeviceVarFlags::DeviceVarKind
DeviceVarKind
Definition: CGCUDARuntime.h:49
clang::CodeGen::CGCUDARuntime::DeviceVarFlags::getSurfTexType
int getSurfTexType() const
Definition: CGCUDARuntime.h:73
clang::CodeGen::CodeGenModule
This class organizes the cross-function state that is used while generating LLVM code.
Definition: CodeGenModule.h:284
clang::CodeGen::FunctionArgList
FunctionArgList - Type for representing both the decl and type of parameters to a function.
Definition: CGCall.h:358
clang::CodeGen::CGCUDARuntime::CGCUDARuntime
CGCUDARuntime(CodeGenModule &CGM)
Definition: CGCUDARuntime.h:76
clang::CodeGen::CGCUDARuntime::getKernelStub
virtual llvm::Function * getKernelStub(llvm::GlobalValue *Handle)=0
Get kernel stub by kernel handle.
clang::CodeGen::CGCUDARuntime::DeviceVarFlags::isExtern
bool isExtern() const
Definition: CGCUDARuntime.h:69
clang::CUDAKernelCallExpr
Represents a call to a CUDA kernel function.
Definition: ExprCXX.h:232
clang
Definition: CalledOnceCheck.h:17
clang::CodeGen::CGCUDARuntime::~CGCUDARuntime
virtual ~CGCUDARuntime()
Definition: CGCUDARuntime.cpp:24
clang::CodeGen::CGCUDARuntime::DeviceVarFlags::Texture
@ Texture
Definition: CGCUDARuntime.h:52
GlobalDecl.h
clang::index::SymbolKind::Function
@ Function
clang::CodeGen::CGCUDARuntime::DeviceVarFlags::DeviceVarFlags
DeviceVarFlags(DeviceVarKind K, bool E, bool C, bool M, bool N, int T)
Definition: CGCUDARuntime.h:64
clang::CodeGen::CGCUDARuntime::emitDeviceStub
virtual void emitDeviceStub(CodeGenFunction &CGF, FunctionArgList &Args)=0
Emits a kernel launch stub.
clang::CodeGen::CGCUDARuntime::DeviceVarFlags::isNormalized
bool isNormalized() const
Definition: CGCUDARuntime.h:72
clang::CodeGen::CGCUDARuntime::DeviceVarFlags::getKind
DeviceVarKind getKind() const
Definition: CGCUDARuntime.h:68