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