blob: e548a3a546d4412da03fe4f4992387e62b4a63bb [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
Michael Liaoe40f8792019-06-17 12:51:36 +000018#include "llvm/ADT/StringRef.h"
19
Artem Belevich52cc4872015-05-07 19:34:16 +000020namespace llvm {
21class Function;
Artem Belevich42e19492016-03-02 18:28:50 +000022class GlobalVariable;
Artem Belevich52cc4872015-05-07 19:34:16 +000023}
24
Peter Collingbournefe883422011-10-06 18:29:37 +000025namespace clang {
26
27class CUDAKernelCallExpr;
Yaxun Liuc18e9ec2019-02-14 02:00:09 +000028class VarDecl;
Peter Collingbournefe883422011-10-06 18:29:37 +000029
30namespace CodeGen {
31
32class CodeGenFunction;
33class CodeGenModule;
Peter Collingbournefa4d6032011-10-06 18:51:56 +000034class FunctionArgList;
Peter Collingbournefe883422011-10-06 18:29:37 +000035class ReturnValueSlot;
36class RValue;
37
38class CGCUDARuntime {
39protected:
40 CodeGenModule &CGM;
41
42public:
Artem Belevich42e19492016-03-02 18:28:50 +000043 // Global variable properties that must be passed to CUDA runtime.
44 enum DeviceVarFlags {
45 ExternDeviceVar = 0x01, // extern
46 ConstantDeviceVar = 0x02, // __constant__
47 };
48
Peter Collingbournefe883422011-10-06 18:29:37 +000049 CGCUDARuntime(CodeGenModule &CGM) : CGM(CGM) {}
50 virtual ~CGCUDARuntime();
51
52 virtual RValue EmitCUDAKernelCallExpr(CodeGenFunction &CGF,
53 const CUDAKernelCallExpr *E,
54 ReturnValueSlot ReturnValue);
Peter Collingbournefa4d6032011-10-06 18:51:56 +000055
Artem Belevich52cc4872015-05-07 19:34:16 +000056 /// Emits a kernel launch stub.
57 virtual void emitDeviceStub(CodeGenFunction &CGF, FunctionArgList &Args) = 0;
Yaxun Liuc18e9ec2019-02-14 02:00:09 +000058 virtual void registerDeviceVar(const VarDecl *VD, llvm::GlobalVariable &Var,
59 unsigned Flags) = 0;
Artem Belevich52cc4872015-05-07 19:34:16 +000060
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 Liaoe40f8792019-06-17 12:51:36 +000068
69 /// Construct and return the stub name of a kernel.
70 virtual std::string getDeviceStubName(llvm::StringRef Name) const = 0;
Peter Collingbournefe883422011-10-06 18:29:37 +000071};
72
73/// Creates an instance of a CUDA runtime class.
74CGCUDARuntime *CreateNVCUDARuntime(CodeGenModule &CGM);
75
Alexander Kornienkoab9db512015-06-22 23:07:51 +000076}
77}
Peter Collingbournefe883422011-10-06 18:29:37 +000078
79#endif