clang 18.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
19#include "llvm/ADT/StringRef.h"
20#include "llvm/IR/GlobalValue.h"
21
22namespace llvm {
23class Function;
24class GlobalVariable;
25}
26
27namespace clang {
28
29class CUDAKernelCallExpr;
30class NamedDecl;
31class VarDecl;
32
33namespace CodeGen {
34
35class CodeGenFunction;
36class CodeGenModule;
37class FunctionArgList;
38class ReturnValueSlot;
39class RValue;
40
42protected:
44
45public:
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 /// The kind flag for an offloading entry.
56 enum OffloadEntryKindFlag : uint32_t {
57 /// Mark the entry as a global entry. This indicates the presense of a
58 /// kernel if the size field is zero and a variable otherwise.
60 /// Mark the entry as a managed global variable.
62 /// Mark the entry as a surface variable.
64 /// Mark the entry as a texture variable.
66 };
67
68 private:
69 unsigned Kind : 2;
70 unsigned Extern : 1;
71 unsigned Constant : 1; // Constant variable.
72 unsigned Managed : 1; // Managed variable.
73 unsigned Normalized : 1; // Normalized texture.
74 int SurfTexType; // Type of surface/texutre.
75
76 public:
77 DeviceVarFlags(DeviceVarKind K, bool E, bool C, bool M, bool N, int T)
78 : Kind(K), Extern(E), Constant(C), Managed(M), Normalized(N),
79 SurfTexType(T) {}
80
81 DeviceVarKind getKind() const { return static_cast<DeviceVarKind>(Kind); }
82 bool isExtern() const { return Extern; }
83 bool isConstant() const { return Constant; }
84 bool isManaged() const { return Managed; }
85 bool isNormalized() const { return Normalized; }
86 int getSurfTexType() const { return SurfTexType; }
87 };
88
90 virtual ~CGCUDARuntime();
91
93 const CUDAKernelCallExpr *E,
94 ReturnValueSlot ReturnValue);
95
96 /// Emits a kernel launch stub.
97 virtual void emitDeviceStub(CodeGenFunction &CGF, FunctionArgList &Args) = 0;
98
99 /// Check whether a variable is a device variable and register it if true.
100 virtual void handleVarRegistration(const VarDecl *VD,
101 llvm::GlobalVariable &Var) = 0;
102
103 /// Finalize generated LLVM module. Returns a module constructor function
104 /// to be added or a null pointer.
105 virtual llvm::Function *finalizeModule() = 0;
106
107 /// Returns function or variable name on device side even if the current
108 /// compilation is for host.
109 virtual std::string getDeviceSideName(const NamedDecl *ND) = 0;
110
111 /// Get kernel handle by stub function.
112 virtual llvm::GlobalValue *getKernelHandle(llvm::Function *Stub,
113 GlobalDecl GD) = 0;
114
115 /// Get kernel stub by kernel handle.
116 virtual llvm::Function *getKernelStub(llvm::GlobalValue *Handle) = 0;
117
118 /// Adjust linkage of shadow variables in host compilation.
119 virtual void
121 llvm::GlobalValue::LinkageTypes &Linkage) = 0;
122};
123
124/// Creates an instance of a CUDA runtime class.
126
127}
128}
129
130#endif
Represents a call to a CUDA kernel function.
Definition: ExprCXX.h:231
DeviceVarFlags(DeviceVarKind K, bool E, bool C, bool M, bool N, int T)
Definition: CGCUDARuntime.h:77
OffloadEntryKindFlag
The kind flag for an offloading entry.
Definition: CGCUDARuntime.h:56
@ OffloadGlobalSurfaceEntry
Mark the entry as a surface variable.
Definition: CGCUDARuntime.h:63
@ OffloadGlobalTextureEntry
Mark the entry as a texture variable.
Definition: CGCUDARuntime.h:65
@ OffloadGlobalEntry
Mark the entry as a global entry.
Definition: CGCUDARuntime.h:59
@ OffloadGlobalManagedEntry
Mark the entry as a managed global variable.
Definition: CGCUDARuntime.h:61
virtual std::string getDeviceSideName(const NamedDecl *ND)=0
Returns function or variable name on device side even if the current compilation is for host.
virtual void emitDeviceStub(CodeGenFunction &CGF, FunctionArgList &Args)=0
Emits a kernel launch stub.
virtual llvm::Function * getKernelStub(llvm::GlobalValue *Handle)=0
Get kernel stub by kernel handle.
virtual void handleVarRegistration(const VarDecl *VD, llvm::GlobalVariable &Var)=0
Check whether a variable is a device variable and register it if true.
virtual llvm::Function * finalizeModule()=0
Finalize generated LLVM module.
virtual llvm::GlobalValue * getKernelHandle(llvm::Function *Stub, GlobalDecl GD)=0
Get kernel handle by stub function.
virtual RValue EmitCUDAKernelCallExpr(CodeGenFunction &CGF, const CUDAKernelCallExpr *E, ReturnValueSlot ReturnValue)
CGCUDARuntime(CodeGenModule &CGM)
Definition: CGCUDARuntime.h:89
virtual void internalizeDeviceSideVar(const VarDecl *D, llvm::GlobalValue::LinkageTypes &Linkage)=0
Adjust linkage of shadow variables in host compilation.
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
This class organizes the cross-function state that is used while generating LLVM code.
FunctionArgList - Type for representing both the decl and type of parameters to a function.
Definition: CGCall.h:351
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
Definition: CGValue.h:39
ReturnValueSlot - Contains the address where the return value of a function can be stored,...
Definition: CGCall.h:355
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:56
This represents a decl that may have a name.
Definition: Decl.h:248
Represents a variable declaration or definition.
Definition: Decl.h:916
CGCUDARuntime * CreateNVCUDARuntime(CodeGenModule &CGM)
Creates an instance of a CUDA runtime class.
Definition: CGCUDANV.cpp:1012
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.
Definition: Linkage.h:24
YAML serialization mapping.
Definition: Dominators.h:30