1 //===----- CGCUDARuntime.h - Interface to CUDA Runtimes ---------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This provides an abstract class for CUDA code generation. Concrete
10 // subclasses of this implement code generation for specific CUDA
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_LIB_CODEGEN_CGCUDARUNTIME_H
16 #define LLVM_CLANG_LIB_CODEGEN_CGCUDARUNTIME_H
18 #include "llvm/ADT/StringRef.h"
27 class CUDAKernelCallExpr;
32 class CodeGenFunction;
34 class FunctionArgList;
35 class ReturnValueSlot;
43 // Global variable properties that must be passed to CUDA runtime.
45 ExternDeviceVar = 0x01, // extern
46 ConstantDeviceVar = 0x02, // __constant__
49 CGCUDARuntime(CodeGenModule &CGM) : CGM(CGM) {}
50 virtual ~CGCUDARuntime();
52 virtual RValue EmitCUDAKernelCallExpr(CodeGenFunction &CGF,
53 const CUDAKernelCallExpr *E,
54 ReturnValueSlot ReturnValue);
56 /// Emits a kernel launch stub.
57 virtual void emitDeviceStub(CodeGenFunction &CGF, FunctionArgList &Args) = 0;
58 virtual void registerDeviceVar(const VarDecl *VD, llvm::GlobalVariable &Var,
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;
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;
69 /// Construct and return the stub name of a kernel.
70 virtual std::string getDeviceStubName(llvm::StringRef Name) const = 0;
73 /// Creates an instance of a CUDA runtime class.
74 CGCUDARuntime *CreateNVCUDARuntime(CodeGenModule &CGM);