| 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 (Sam) Liu | 22c457a | 2020-03-05 12:59:33 -0500 | [diff] [blame] | 28 | class NamedDecl; |
| Yaxun Liu | c18e9ec | 2019-02-14 02:00:09 +0000 | [diff] [blame] | 29 | class VarDecl; |
| Peter Collingbourne | fe88342 | 2011-10-06 18:29:37 +0000 | [diff] [blame] | 30 | |
| 31 | namespace CodeGen { |
| 32 | |
| 33 | class CodeGenFunction; |
| 34 | class CodeGenModule; |
| Peter Collingbourne | fa4d603 | 2011-10-06 18:51:56 +0000 | [diff] [blame] | 35 | class FunctionArgList; |
| Peter Collingbourne | fe88342 | 2011-10-06 18:29:37 +0000 | [diff] [blame] | 36 | class ReturnValueSlot; |
| 37 | class RValue; |
| 38 | |
| 39 | class CGCUDARuntime { |
| 40 | protected: |
| 41 | CodeGenModule &CGM; |
| 42 | |
| 43 | public: |
| Artem Belevich | 42e1949 | 2016-03-02 18:28:50 +0000 | [diff] [blame] | 44 | // Global variable properties that must be passed to CUDA runtime. |
| 45 | enum DeviceVarFlags { |
| 46 | ExternDeviceVar = 0x01, // extern |
| 47 | ConstantDeviceVar = 0x02, // __constant__ |
| 48 | }; |
| 49 | |
| Peter Collingbourne | fe88342 | 2011-10-06 18:29:37 +0000 | [diff] [blame] | 50 | CGCUDARuntime(CodeGenModule &CGM) : CGM(CGM) {} |
| 51 | virtual ~CGCUDARuntime(); |
| 52 | |
| 53 | virtual RValue EmitCUDAKernelCallExpr(CodeGenFunction &CGF, |
| 54 | const CUDAKernelCallExpr *E, |
| 55 | ReturnValueSlot ReturnValue); |
| Peter Collingbourne | fa4d603 | 2011-10-06 18:51:56 +0000 | [diff] [blame] | 56 | |
| Artem Belevich | 52cc487 | 2015-05-07 19:34:16 +0000 | [diff] [blame] | 57 | /// Emits a kernel launch stub. |
| 58 | virtual void emitDeviceStub(CodeGenFunction &CGF, FunctionArgList &Args) = 0; |
| Yaxun Liu | c18e9ec | 2019-02-14 02:00:09 +0000 | [diff] [blame] | 59 | virtual void registerDeviceVar(const VarDecl *VD, llvm::GlobalVariable &Var, |
| 60 | unsigned Flags) = 0; |
| Artem Belevich | 52cc487 | 2015-05-07 19:34:16 +0000 | [diff] [blame] | 61 | |
| 62 | /// Constructs and returns a module initialization function or nullptr if it's |
| 63 | /// not needed. Must be called after all kernels have been emitted. |
| 64 | virtual llvm::Function *makeModuleCtorFunction() = 0; |
| 65 | |
| 66 | /// Returns a module cleanup function or nullptr if it's not needed. |
| 67 | /// Must be called after ModuleCtorFunction |
| 68 | virtual llvm::Function *makeModuleDtorFunction() = 0; |
| Michael Liao | e40f879 | 2019-06-17 12:51:36 +0000 | [diff] [blame] | 69 | |
| Yaxun (Sam) Liu | 22c457a | 2020-03-05 12:59:33 -0500 | [diff] [blame] | 70 | /// Returns function or variable name on device side even if the current |
| 71 | /// compilation is for host. |
| 72 | virtual std::string getDeviceSideName(const NamedDecl *ND) = 0; |
| Peter Collingbourne | fe88342 | 2011-10-06 18:29:37 +0000 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | /// Creates an instance of a CUDA runtime class. |
| 76 | CGCUDARuntime *CreateNVCUDARuntime(CodeGenModule &CGM); |
| 77 | |
| Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 78 | } |
| 79 | } |
| Peter Collingbourne | fe88342 | 2011-10-06 18:29:37 +0000 | [diff] [blame] | 80 | |
| 81 | #endif |