xref: /aosp_15_r20/external/clang/lib/CodeGen/CGCUDARuntime.h (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li //===----- CGCUDARuntime.h - Interface to CUDA Runtimes ---------*- C++ -*-===//
2*67e74705SXin Li //
3*67e74705SXin Li //                     The LLVM Compiler Infrastructure
4*67e74705SXin Li //
5*67e74705SXin Li // This file is distributed under the University of Illinois Open Source
6*67e74705SXin Li // License. See LICENSE.TXT for details.
7*67e74705SXin Li //
8*67e74705SXin Li //===----------------------------------------------------------------------===//
9*67e74705SXin Li //
10*67e74705SXin Li // This provides an abstract class for CUDA code generation.  Concrete
11*67e74705SXin Li // subclasses of this implement code generation for specific CUDA
12*67e74705SXin Li // runtime libraries.
13*67e74705SXin Li //
14*67e74705SXin Li //===----------------------------------------------------------------------===//
15*67e74705SXin Li 
16*67e74705SXin Li #ifndef LLVM_CLANG_LIB_CODEGEN_CGCUDARUNTIME_H
17*67e74705SXin Li #define LLVM_CLANG_LIB_CODEGEN_CGCUDARUNTIME_H
18*67e74705SXin Li 
19*67e74705SXin Li namespace llvm {
20*67e74705SXin Li class Function;
21*67e74705SXin Li class GlobalVariable;
22*67e74705SXin Li }
23*67e74705SXin Li 
24*67e74705SXin Li namespace clang {
25*67e74705SXin Li 
26*67e74705SXin Li class CUDAKernelCallExpr;
27*67e74705SXin Li 
28*67e74705SXin Li namespace CodeGen {
29*67e74705SXin Li 
30*67e74705SXin Li class CodeGenFunction;
31*67e74705SXin Li class CodeGenModule;
32*67e74705SXin Li class FunctionArgList;
33*67e74705SXin Li class ReturnValueSlot;
34*67e74705SXin Li class RValue;
35*67e74705SXin Li 
36*67e74705SXin Li class CGCUDARuntime {
37*67e74705SXin Li protected:
38*67e74705SXin Li   CodeGenModule &CGM;
39*67e74705SXin Li 
40*67e74705SXin Li public:
41*67e74705SXin Li   // Global variable properties that must be passed to CUDA runtime.
42*67e74705SXin Li   enum DeviceVarFlags {
43*67e74705SXin Li     ExternDeviceVar = 0x01,   // extern
44*67e74705SXin Li     ConstantDeviceVar = 0x02, // __constant__
45*67e74705SXin Li   };
46*67e74705SXin Li 
CGCUDARuntime(CodeGenModule & CGM)47*67e74705SXin Li   CGCUDARuntime(CodeGenModule &CGM) : CGM(CGM) {}
48*67e74705SXin Li   virtual ~CGCUDARuntime();
49*67e74705SXin Li 
50*67e74705SXin Li   virtual RValue EmitCUDAKernelCallExpr(CodeGenFunction &CGF,
51*67e74705SXin Li                                         const CUDAKernelCallExpr *E,
52*67e74705SXin Li                                         ReturnValueSlot ReturnValue);
53*67e74705SXin Li 
54*67e74705SXin Li   /// Emits a kernel launch stub.
55*67e74705SXin Li   virtual void emitDeviceStub(CodeGenFunction &CGF, FunctionArgList &Args) = 0;
56*67e74705SXin Li   virtual void registerDeviceVar(llvm::GlobalVariable &Var, unsigned Flags) = 0;
57*67e74705SXin Li 
58*67e74705SXin Li   /// Constructs and returns a module initialization function or nullptr if it's
59*67e74705SXin Li   /// not needed. Must be called after all kernels have been emitted.
60*67e74705SXin Li   virtual llvm::Function *makeModuleCtorFunction() = 0;
61*67e74705SXin Li 
62*67e74705SXin Li   /// Returns a module cleanup function or nullptr if it's not needed.
63*67e74705SXin Li   /// Must be called after ModuleCtorFunction
64*67e74705SXin Li   virtual llvm::Function *makeModuleDtorFunction() = 0;
65*67e74705SXin Li };
66*67e74705SXin Li 
67*67e74705SXin Li /// Creates an instance of a CUDA runtime class.
68*67e74705SXin Li CGCUDARuntime *CreateNVCUDARuntime(CodeGenModule &CGM);
69*67e74705SXin Li 
70*67e74705SXin Li }
71*67e74705SXin Li }
72*67e74705SXin Li 
73*67e74705SXin Li #endif
74