clang  19.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/Frontend/Offloading/Utility.h"
21 #include "llvm/IR/GlobalValue.h"
22 
23 namespace llvm {
24 class Function;
25 class GlobalVariable;
26 }
27 
28 namespace clang {
29 
30 class CUDAKernelCallExpr;
31 class NamedDecl;
32 class VarDecl;
33 
34 namespace CodeGen {
35 
36 class CodeGenFunction;
37 class CodeGenModule;
38 class FunctionArgList;
39 class ReturnValueSlot;
40 class RValue;
41 
43 protected:
45 
46 public:
47  // Global variable properties that must be passed to CUDA runtime.
49  public:
51  Variable, // Variable
52  Surface, // Builtin surface
53  Texture, // Builtin texture
54  };
55 
56  private:
57  LLVM_PREFERRED_TYPE(DeviceVarKind)
58  unsigned Kind : 2;
59  LLVM_PREFERRED_TYPE(bool)
60  unsigned Extern : 1;
61  LLVM_PREFERRED_TYPE(bool)
62  unsigned Constant : 1; // Constant variable.
63  LLVM_PREFERRED_TYPE(bool)
64  unsigned Managed : 1; // Managed variable.
65  LLVM_PREFERRED_TYPE(bool)
66  unsigned Normalized : 1; // Normalized texture.
67  int SurfTexType; // Type of surface/texutre.
68 
69  public:
70  DeviceVarFlags(DeviceVarKind K, bool E, bool C, bool M, bool N, int T)
71  : Kind(K), Extern(E), Constant(C), Managed(M), Normalized(N),
72  SurfTexType(T) {}
73 
74  DeviceVarKind getKind() const { return static_cast<DeviceVarKind>(Kind); }
75  bool isExtern() const { return Extern; }
76  bool isConstant() const { return Constant; }
77  bool isManaged() const { return Managed; }
78  bool isNormalized() const { return Normalized; }
79  int getSurfTexType() const { return SurfTexType; }
80  };
81 
83  virtual ~CGCUDARuntime();
84 
86  const CUDAKernelCallExpr *E,
87  ReturnValueSlot ReturnValue);
88 
89  /// Emits a kernel launch stub.
90  virtual void emitDeviceStub(CodeGenFunction &CGF, FunctionArgList &Args) = 0;
91 
92  /// Check whether a variable is a device variable and register it if true.
93  virtual void handleVarRegistration(const VarDecl *VD,
94  llvm::GlobalVariable &Var) = 0;
95 
96  /// Finalize generated LLVM module. Returns a module constructor function
97  /// to be added or a null pointer.
98  virtual llvm::Function *finalizeModule() = 0;
99 
100  /// Returns function or variable name on device side even if the current
101  /// compilation is for host.
102  virtual std::string getDeviceSideName(const NamedDecl *ND) = 0;
103 
104  /// Get kernel handle by stub function.
105  virtual llvm::GlobalValue *getKernelHandle(llvm::Function *Stub,
106  GlobalDecl GD) = 0;
107 
108  /// Get kernel stub by kernel handle.
109  virtual llvm::Function *getKernelStub(llvm::GlobalValue *Handle) = 0;
110 
111  /// Adjust linkage of shadow variables in host compilation.
112  virtual void
114  llvm::GlobalValue::LinkageTypes &Linkage) = 0;
115 };
116 
117 /// Creates an instance of a CUDA runtime class.
119 
120 }
121 }
122 
123 #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:70
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::GlobalValue * getKernelHandle(llvm::Function *Stub, GlobalDecl GD)=0
Get kernel handle by stub function.
virtual void handleVarRegistration(const VarDecl *VD, llvm::GlobalVariable &Var)=0
Check whether a variable is a device variable and register it if true.
virtual RValue EmitCUDAKernelCallExpr(CodeGenFunction &CGF, const CUDAKernelCallExpr *E, ReturnValueSlot ReturnValue)
virtual llvm::Function * finalizeModule()=0
Finalize generated LLVM module.
CGCUDARuntime(CodeGenModule &CGM)
Definition: CGCUDARuntime.h:82
virtual void internalizeDeviceSideVar(const VarDecl *D, llvm::GlobalValue::LinkageTypes &Linkage)=0
Adjust linkage of shadow variables in host compilation.
virtual llvm::Function * getKernelStub(llvm::GlobalValue *Handle)=0
Get kernel stub by kernel handle.
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:41
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:249
Represents a variable declaration or definition.
Definition: Decl.h:919
CGCUDARuntime * CreateNVCUDARuntime(CodeGenModule &CGM)
Creates an instance of a CUDA runtime class.
Definition: CGCUDANV.cpp:1021
The JSON file list parser is used to communicate input to InstallAPI.
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.
Definition: Linkage.h:24
const FunctionProtoType * T
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30