blob: 0168f4f9e942ff96a0e02b1663679bee753edd8f [file] [log] [blame]
Peter Collingbournefe883422011-10-06 18:29:37 +00001//===----- 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 Kramer2f5db8b2014-08-13 16:25:19 +000016#ifndef LLVM_CLANG_LIB_CODEGEN_CGCUDARUNTIME_H
17#define LLVM_CLANG_LIB_CODEGEN_CGCUDARUNTIME_H
Peter Collingbournefe883422011-10-06 18:29:37 +000018
Artem Belevich52cc4872015-05-07 19:34:16 +000019namespace llvm {
20class Function;
Artem Belevich42e19492016-03-02 18:28:50 +000021class GlobalVariable;
Artem Belevich52cc4872015-05-07 19:34:16 +000022}
23
Peter Collingbournefe883422011-10-06 18:29:37 +000024namespace clang {
25
26class CUDAKernelCallExpr;
27
28namespace CodeGen {
29
30class CodeGenFunction;
31class CodeGenModule;
Peter Collingbournefa4d6032011-10-06 18:51:56 +000032class FunctionArgList;
Peter Collingbournefe883422011-10-06 18:29:37 +000033class ReturnValueSlot;
34class RValue;
35
36class CGCUDARuntime {
37protected:
38 CodeGenModule &CGM;
39
40public:
Artem Belevich42e19492016-03-02 18:28:50 +000041 // Global variable properties that must be passed to CUDA runtime.
42 enum DeviceVarFlags {
43 ExternDeviceVar = 0x01, // extern
44 ConstantDeviceVar = 0x02, // __constant__
45 };
46
Peter Collingbournefe883422011-10-06 18:29:37 +000047 CGCUDARuntime(CodeGenModule &CGM) : CGM(CGM) {}
48 virtual ~CGCUDARuntime();
49
50 virtual RValue EmitCUDAKernelCallExpr(CodeGenFunction &CGF,
51 const CUDAKernelCallExpr *E,
52 ReturnValueSlot ReturnValue);
Peter Collingbournefa4d6032011-10-06 18:51:56 +000053
Artem Belevich52cc4872015-05-07 19:34:16 +000054 /// Emits a kernel launch stub.
55 virtual void emitDeviceStub(CodeGenFunction &CGF, FunctionArgList &Args) = 0;
Artem Belevich42e19492016-03-02 18:28:50 +000056 virtual void registerDeviceVar(llvm::GlobalVariable &Var, unsigned Flags) = 0;
Artem Belevich52cc4872015-05-07 19:34:16 +000057
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 Collingbournefe883422011-10-06 18:29:37 +000065};
66
67/// Creates an instance of a CUDA runtime class.
68CGCUDARuntime *CreateNVCUDARuntime(CodeGenModule &CGM);
69
Alexander Kornienkoab9db512015-06-22 23:07:51 +000070}
71}
Peter Collingbournefe883422011-10-06 18:29:37 +000072
73#endif