1*0b57cec5SDimitry Andric //===----- CGCUDARuntime.h - Interface to CUDA Runtimes ---------*- C++ -*-===// 2*0b57cec5SDimitry Andric // 3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*0b57cec5SDimitry Andric // 7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 8*0b57cec5SDimitry Andric // 9*0b57cec5SDimitry Andric // This provides an abstract class for CUDA code generation. Concrete 10*0b57cec5SDimitry Andric // subclasses of this implement code generation for specific CUDA 11*0b57cec5SDimitry Andric // runtime libraries. 12*0b57cec5SDimitry Andric // 13*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 14*0b57cec5SDimitry Andric 15*0b57cec5SDimitry Andric #ifndef LLVM_CLANG_LIB_CODEGEN_CGCUDARUNTIME_H 16*0b57cec5SDimitry Andric #define LLVM_CLANG_LIB_CODEGEN_CGCUDARUNTIME_H 17*0b57cec5SDimitry Andric 18*0b57cec5SDimitry Andric #include "llvm/ADT/StringRef.h" 19*0b57cec5SDimitry Andric 20*0b57cec5SDimitry Andric namespace llvm { 21*0b57cec5SDimitry Andric class Function; 22*0b57cec5SDimitry Andric class GlobalVariable; 23*0b57cec5SDimitry Andric } 24*0b57cec5SDimitry Andric 25*0b57cec5SDimitry Andric namespace clang { 26*0b57cec5SDimitry Andric 27*0b57cec5SDimitry Andric class CUDAKernelCallExpr; 28*0b57cec5SDimitry Andric class VarDecl; 29*0b57cec5SDimitry Andric 30*0b57cec5SDimitry Andric namespace CodeGen { 31*0b57cec5SDimitry Andric 32*0b57cec5SDimitry Andric class CodeGenFunction; 33*0b57cec5SDimitry Andric class CodeGenModule; 34*0b57cec5SDimitry Andric class FunctionArgList; 35*0b57cec5SDimitry Andric class ReturnValueSlot; 36*0b57cec5SDimitry Andric class RValue; 37*0b57cec5SDimitry Andric 38*0b57cec5SDimitry Andric class CGCUDARuntime { 39*0b57cec5SDimitry Andric protected: 40*0b57cec5SDimitry Andric CodeGenModule &CGM; 41*0b57cec5SDimitry Andric 42*0b57cec5SDimitry Andric public: 43*0b57cec5SDimitry Andric // Global variable properties that must be passed to CUDA runtime. 44*0b57cec5SDimitry Andric enum DeviceVarFlags { 45*0b57cec5SDimitry Andric ExternDeviceVar = 0x01, // extern 46*0b57cec5SDimitry Andric ConstantDeviceVar = 0x02, // __constant__ 47*0b57cec5SDimitry Andric }; 48*0b57cec5SDimitry Andric 49*0b57cec5SDimitry Andric CGCUDARuntime(CodeGenModule &CGM) : CGM(CGM) {} 50*0b57cec5SDimitry Andric virtual ~CGCUDARuntime(); 51*0b57cec5SDimitry Andric 52*0b57cec5SDimitry Andric virtual RValue EmitCUDAKernelCallExpr(CodeGenFunction &CGF, 53*0b57cec5SDimitry Andric const CUDAKernelCallExpr *E, 54*0b57cec5SDimitry Andric ReturnValueSlot ReturnValue); 55*0b57cec5SDimitry Andric 56*0b57cec5SDimitry Andric /// Emits a kernel launch stub. 57*0b57cec5SDimitry Andric virtual void emitDeviceStub(CodeGenFunction &CGF, FunctionArgList &Args) = 0; 58*0b57cec5SDimitry Andric virtual void registerDeviceVar(const VarDecl *VD, llvm::GlobalVariable &Var, 59*0b57cec5SDimitry Andric unsigned Flags) = 0; 60*0b57cec5SDimitry Andric 61*0b57cec5SDimitry Andric /// Constructs and returns a module initialization function or nullptr if it's 62*0b57cec5SDimitry Andric /// not needed. Must be called after all kernels have been emitted. 63*0b57cec5SDimitry Andric virtual llvm::Function *makeModuleCtorFunction() = 0; 64*0b57cec5SDimitry Andric 65*0b57cec5SDimitry Andric /// Returns a module cleanup function or nullptr if it's not needed. 66*0b57cec5SDimitry Andric /// Must be called after ModuleCtorFunction 67*0b57cec5SDimitry Andric virtual llvm::Function *makeModuleDtorFunction() = 0; 68*0b57cec5SDimitry Andric 69*0b57cec5SDimitry Andric /// Construct and return the stub name of a kernel. 70*0b57cec5SDimitry Andric virtual std::string getDeviceStubName(llvm::StringRef Name) const = 0; 71*0b57cec5SDimitry Andric }; 72*0b57cec5SDimitry Andric 73*0b57cec5SDimitry Andric /// Creates an instance of a CUDA runtime class. 74*0b57cec5SDimitry Andric CGCUDARuntime *CreateNVCUDARuntime(CodeGenModule &CGM); 75*0b57cec5SDimitry Andric 76*0b57cec5SDimitry Andric } 77*0b57cec5SDimitry Andric } 78*0b57cec5SDimitry Andric 79*0b57cec5SDimitry Andric #endif 80