Path: blob/main/contrib/llvm-project/clang/lib/CodeGen/CGCUDARuntime.h
35233 views
//===----- CGCUDARuntime.h - Interface to CUDA Runtimes ---------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This provides an abstract class for CUDA code generation. Concrete9// subclasses of this implement code generation for specific CUDA10// runtime libraries.11//12//===----------------------------------------------------------------------===//1314#ifndef LLVM_CLANG_LIB_CODEGEN_CGCUDARUNTIME_H15#define LLVM_CLANG_LIB_CODEGEN_CGCUDARUNTIME_H1617#include "clang/AST/GlobalDecl.h"18#include "llvm/ADT/StringRef.h"19#include "llvm/Frontend/Offloading/Utility.h"20#include "llvm/IR/GlobalValue.h"2122namespace llvm {23class Function;24class GlobalVariable;25}2627namespace clang {2829class CUDAKernelCallExpr;30class NamedDecl;31class VarDecl;3233namespace CodeGen {3435class CodeGenFunction;36class CodeGenModule;37class FunctionArgList;38class ReturnValueSlot;39class RValue;4041class CGCUDARuntime {42protected:43CodeGenModule &CGM;4445public:46// Global variable properties that must be passed to CUDA runtime.47class DeviceVarFlags {48public:49enum DeviceVarKind {50Variable, // Variable51Surface, // Builtin surface52Texture, // Builtin texture53};5455private:56LLVM_PREFERRED_TYPE(DeviceVarKind)57unsigned Kind : 2;58LLVM_PREFERRED_TYPE(bool)59unsigned Extern : 1;60LLVM_PREFERRED_TYPE(bool)61unsigned Constant : 1; // Constant variable.62LLVM_PREFERRED_TYPE(bool)63unsigned Managed : 1; // Managed variable.64LLVM_PREFERRED_TYPE(bool)65unsigned Normalized : 1; // Normalized texture.66int SurfTexType; // Type of surface/texutre.6768public:69DeviceVarFlags(DeviceVarKind K, bool E, bool C, bool M, bool N, int T)70: Kind(K), Extern(E), Constant(C), Managed(M), Normalized(N),71SurfTexType(T) {}7273DeviceVarKind getKind() const { return static_cast<DeviceVarKind>(Kind); }74bool isExtern() const { return Extern; }75bool isConstant() const { return Constant; }76bool isManaged() const { return Managed; }77bool isNormalized() const { return Normalized; }78int getSurfTexType() const { return SurfTexType; }79};8081CGCUDARuntime(CodeGenModule &CGM) : CGM(CGM) {}82virtual ~CGCUDARuntime();8384virtual RValue EmitCUDAKernelCallExpr(CodeGenFunction &CGF,85const CUDAKernelCallExpr *E,86ReturnValueSlot ReturnValue);8788/// Emits a kernel launch stub.89virtual void emitDeviceStub(CodeGenFunction &CGF, FunctionArgList &Args) = 0;9091/// Check whether a variable is a device variable and register it if true.92virtual void handleVarRegistration(const VarDecl *VD,93llvm::GlobalVariable &Var) = 0;9495/// Finalize generated LLVM module. Returns a module constructor function96/// to be added or a null pointer.97virtual llvm::Function *finalizeModule() = 0;9899/// Returns function or variable name on device side even if the current100/// compilation is for host.101virtual std::string getDeviceSideName(const NamedDecl *ND) = 0;102103/// Get kernel handle by stub function.104virtual llvm::GlobalValue *getKernelHandle(llvm::Function *Stub,105GlobalDecl GD) = 0;106107/// Get kernel stub by kernel handle.108virtual llvm::Function *getKernelStub(llvm::GlobalValue *Handle) = 0;109110/// Adjust linkage of shadow variables in host compilation.111virtual void112internalizeDeviceSideVar(const VarDecl *D,113llvm::GlobalValue::LinkageTypes &Linkage) = 0;114};115116/// Creates an instance of a CUDA runtime class.117CGCUDARuntime *CreateNVCUDARuntime(CodeGenModule &CGM);118119}120}121122#endif123124125