blob: e0e096bdcf9af997234eb320667c3e2318e10bdc [file] [log] [blame]
Peter Collingbournefe883422011-10-06 18:29:37 +00001//===----- CGCUDARuntime.h - Interface to CUDA Runtimes ---------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Collingbournefe883422011-10-06 18:29:37 +00006//
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 Kramer2f5db8b2014-08-13 16:25:19 +000015#ifndef LLVM_CLANG_LIB_CODEGEN_CGCUDARUNTIME_H
16#define LLVM_CLANG_LIB_CODEGEN_CGCUDARUNTIME_H
Peter Collingbournefe883422011-10-06 18:29:37 +000017
Artem Belevich52cc4872015-05-07 19:34:16 +000018namespace llvm {
19class Function;
Artem Belevich42e19492016-03-02 18:28:50 +000020class GlobalVariable;
Artem Belevich52cc4872015-05-07 19:34:16 +000021}
22
Peter Collingbournefe883422011-10-06 18:29:37 +000023namespace clang {
24
25class CUDAKernelCallExpr;
26
27namespace CodeGen {
28
29class CodeGenFunction;
30class CodeGenModule;
Peter Collingbournefa4d6032011-10-06 18:51:56 +000031class FunctionArgList;
Peter Collingbournefe883422011-10-06 18:29:37 +000032class ReturnValueSlot;
33class RValue;
34
35class CGCUDARuntime {
36protected:
37 CodeGenModule &CGM;
38
39public:
Artem Belevich42e19492016-03-02 18:28:50 +000040 // Global variable properties that must be passed to CUDA runtime.
41 enum DeviceVarFlags {
42 ExternDeviceVar = 0x01, // extern
43 ConstantDeviceVar = 0x02, // __constant__
44 };
45
Peter Collingbournefe883422011-10-06 18:29:37 +000046 CGCUDARuntime(CodeGenModule &CGM) : CGM(CGM) {}
47 virtual ~CGCUDARuntime();
48
49 virtual RValue EmitCUDAKernelCallExpr(CodeGenFunction &CGF,
50 const CUDAKernelCallExpr *E,
51 ReturnValueSlot ReturnValue);
Peter Collingbournefa4d6032011-10-06 18:51:56 +000052
Artem Belevich52cc4872015-05-07 19:34:16 +000053 /// Emits a kernel launch stub.
54 virtual void emitDeviceStub(CodeGenFunction &CGF, FunctionArgList &Args) = 0;
Artem Belevich42e19492016-03-02 18:28:50 +000055 virtual void registerDeviceVar(llvm::GlobalVariable &Var, unsigned Flags) = 0;
Artem Belevich52cc4872015-05-07 19:34:16 +000056
57 /// Constructs and returns a module initialization function or nullptr if it's
58 /// not needed. Must be called after all kernels have been emitted.
59 virtual llvm::Function *makeModuleCtorFunction() = 0;
60
61 /// Returns a module cleanup function or nullptr if it's not needed.
62 /// Must be called after ModuleCtorFunction
63 virtual llvm::Function *makeModuleDtorFunction() = 0;
Peter Collingbournefe883422011-10-06 18:29:37 +000064};
65
66/// Creates an instance of a CUDA runtime class.
67CGCUDARuntime *CreateNVCUDARuntime(CodeGenModule &CGM);
68
Alexander Kornienkoab9db512015-06-22 23:07:51 +000069}
70}
Peter Collingbournefe883422011-10-06 18:29:37 +000071
72#endif