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 | namespace llvm { |
19 | class Function; |
20 | class GlobalVariable; |
21 | } |
22 | |
23 | namespace clang { |
24 | |
25 | class CUDAKernelCallExpr; |
26 | class VarDecl; |
27 | |
28 | namespace CodeGen { |
29 | |
30 | class CodeGenFunction; |
31 | class CodeGenModule; |
32 | class FunctionArgList; |
33 | class ReturnValueSlot; |
34 | class RValue; |
35 | |
36 | class CGCUDARuntime { |
37 | protected: |
38 | CodeGenModule &CGM; |
39 | |
40 | public: |
41 | // Global variable properties that must be passed to CUDA runtime. |
42 | enum DeviceVarFlags { |
43 | ExternDeviceVar = 0x01, // extern |
44 | ConstantDeviceVar = 0x02, // __constant__ |
45 | }; |
46 | |
47 | CGCUDARuntime(CodeGenModule &CGM) : CGM(CGM) {} |
48 | virtual ~CGCUDARuntime(); |
49 | |
50 | virtual RValue EmitCUDAKernelCallExpr(CodeGenFunction &CGF, |
51 | const CUDAKernelCallExpr *E, |
52 | ReturnValueSlot ReturnValue); |
53 | |
54 | /// Emits a kernel launch stub. |
55 | virtual void emitDeviceStub(CodeGenFunction &CGF, FunctionArgList &Args) = 0; |
56 | virtual void registerDeviceVar(const VarDecl *VD, llvm::GlobalVariable &Var, |
57 | unsigned Flags) = 0; |
58 | |
59 | /// Constructs and returns a module initialization function or nullptr if it's |
60 | /// not needed. Must be called after all kernels have been emitted. |
61 | virtual llvm::Function *makeModuleCtorFunction() = 0; |
62 | |
63 | /// Returns a module cleanup function or nullptr if it's not needed. |
64 | /// Must be called after ModuleCtorFunction |
65 | virtual llvm::Function *makeModuleDtorFunction() = 0; |
66 | }; |
67 | |
68 | /// Creates an instance of a CUDA runtime class. |
69 | CGCUDARuntime *CreateNVCUDARuntime(CodeGenModule &CGM); |
70 | |
71 | } |
72 | } |
73 | |
74 | #endif |
75 |