Peter Collingbourne | fe88342 | 2011-10-06 18:29:37 +0000 | [diff] [blame] | 1 | //===----- CGCUDARuntime.h - Interface to CUDA Runtimes ---------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Peter Collingbourne | fe88342 | 2011-10-06 18:29:37 +0000 | [diff] [blame] | 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 | |
Benjamin Kramer | 2f5db8b | 2014-08-13 16:25:19 +0000 | [diff] [blame] | 15 | #ifndef LLVM_CLANG_LIB_CODEGEN_CGCUDARUNTIME_H |
| 16 | #define LLVM_CLANG_LIB_CODEGEN_CGCUDARUNTIME_H |
Peter Collingbourne | fe88342 | 2011-10-06 18:29:37 +0000 | [diff] [blame] | 17 | |
Michael Liao | e40f879 | 2019-06-17 12:51:36 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/StringRef.h" |
| 19 | |
Artem Belevich | 52cc487 | 2015-05-07 19:34:16 +0000 | [diff] [blame] | 20 | namespace llvm { |
| 21 | class Function; |
Artem Belevich | 42e1949 | 2016-03-02 18:28:50 +0000 | [diff] [blame] | 22 | class GlobalVariable; |
Artem Belevich | 52cc487 | 2015-05-07 19:34:16 +0000 | [diff] [blame] | 23 | } |
| 24 | |
Peter Collingbourne | fe88342 | 2011-10-06 18:29:37 +0000 | [diff] [blame] | 25 | namespace clang { |
| 26 | |
| 27 | class CUDAKernelCallExpr; |
Yaxun Liu | c18e9ec | 2019-02-14 02:00:09 +0000 | [diff] [blame] | 28 | class VarDecl; |
Peter Collingbourne | fe88342 | 2011-10-06 18:29:37 +0000 | [diff] [blame] | 29 | |
| 30 | namespace CodeGen { |
| 31 | |
| 32 | class CodeGenFunction; |
| 33 | class CodeGenModule; |
Peter Collingbourne | fa4d603 | 2011-10-06 18:51:56 +0000 | [diff] [blame] | 34 | class FunctionArgList; |
Peter Collingbourne | fe88342 | 2011-10-06 18:29:37 +0000 | [diff] [blame] | 35 | class ReturnValueSlot; |
| 36 | class RValue; |
| 37 | |
| 38 | class CGCUDARuntime { |
| 39 | protected: |
| 40 | CodeGenModule &CGM; |
| 41 | |
| 42 | public: |
Artem Belevich | 42e1949 | 2016-03-02 18:28:50 +0000 | [diff] [blame] | 43 | // Global variable properties that must be passed to CUDA runtime. |
| 44 | enum DeviceVarFlags { |
| 45 | ExternDeviceVar = 0x01, // extern |
| 46 | ConstantDeviceVar = 0x02, // __constant__ |
| 47 | }; |
| 48 | |
Peter Collingbourne | fe88342 | 2011-10-06 18:29:37 +0000 | [diff] [blame] | 49 | CGCUDARuntime(CodeGenModule &CGM) : CGM(CGM) {} |
| 50 | virtual ~CGCUDARuntime(); |
| 51 | |
| 52 | virtual RValue EmitCUDAKernelCallExpr(CodeGenFunction &CGF, |
| 53 | const CUDAKernelCallExpr *E, |
| 54 | ReturnValueSlot ReturnValue); |
Peter Collingbourne | fa4d603 | 2011-10-06 18:51:56 +0000 | [diff] [blame] | 55 | |
Artem Belevich | 52cc487 | 2015-05-07 19:34:16 +0000 | [diff] [blame] | 56 | /// Emits a kernel launch stub. |
| 57 | virtual void emitDeviceStub(CodeGenFunction &CGF, FunctionArgList &Args) = 0; |
Yaxun Liu | c18e9ec | 2019-02-14 02:00:09 +0000 | [diff] [blame] | 58 | virtual void registerDeviceVar(const VarDecl *VD, llvm::GlobalVariable &Var, |
| 59 | unsigned Flags) = 0; |
Artem Belevich | 52cc487 | 2015-05-07 19:34:16 +0000 | [diff] [blame] | 60 | |
| 61 | /// Constructs and returns a module initialization function or nullptr if it's |
| 62 | /// not needed. Must be called after all kernels have been emitted. |
| 63 | virtual llvm::Function *makeModuleCtorFunction() = 0; |
| 64 | |
| 65 | /// Returns a module cleanup function or nullptr if it's not needed. |
| 66 | /// Must be called after ModuleCtorFunction |
| 67 | virtual llvm::Function *makeModuleDtorFunction() = 0; |
Michael Liao | e40f879 | 2019-06-17 12:51:36 +0000 | [diff] [blame] | 68 | |
| 69 | /// Construct and return the stub name of a kernel. |
| 70 | virtual std::string getDeviceStubName(llvm::StringRef Name) const = 0; |
Peter Collingbourne | fe88342 | 2011-10-06 18:29:37 +0000 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | /// Creates an instance of a CUDA runtime class. |
| 74 | CGCUDARuntime *CreateNVCUDARuntime(CodeGenModule &CGM); |
| 75 | |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 76 | } |
| 77 | } |
Peter Collingbourne | fe88342 | 2011-10-06 18:29:37 +0000 | [diff] [blame] | 78 | |
| 79 | #endif |