2011-10-07 02:29:37 +08:00
|
|
|
//===----- CGCUDARuntime.h - Interface to CUDA Runtimes ---------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2011-10-07 02:29:37 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This provides an abstract class for CUDA code generation. Concrete
|
|
|
|
// subclasses of this implement code generation for specific CUDA
|
|
|
|
// runtime libraries.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:25:19 +08:00
|
|
|
#ifndef LLVM_CLANG_LIB_CODEGEN_CGCUDARUNTIME_H
|
|
|
|
#define LLVM_CLANG_LIB_CODEGEN_CGCUDARUNTIME_H
|
2011-10-07 02:29:37 +08:00
|
|
|
|
2019-06-17 20:51:36 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
|
2015-05-08 03:34:16 +08:00
|
|
|
namespace llvm {
|
|
|
|
class Function;
|
2016-03-03 02:28:50 +08:00
|
|
|
class GlobalVariable;
|
2015-05-08 03:34:16 +08:00
|
|
|
}
|
|
|
|
|
2011-10-07 02:29:37 +08:00
|
|
|
namespace clang {
|
|
|
|
|
|
|
|
class CUDAKernelCallExpr;
|
2019-02-14 10:00:09 +08:00
|
|
|
class VarDecl;
|
2011-10-07 02:29:37 +08:00
|
|
|
|
|
|
|
namespace CodeGen {
|
|
|
|
|
|
|
|
class CodeGenFunction;
|
|
|
|
class CodeGenModule;
|
2011-10-07 02:51:56 +08:00
|
|
|
class FunctionArgList;
|
2011-10-07 02:29:37 +08:00
|
|
|
class ReturnValueSlot;
|
|
|
|
class RValue;
|
|
|
|
|
|
|
|
class CGCUDARuntime {
|
|
|
|
protected:
|
|
|
|
CodeGenModule &CGM;
|
|
|
|
|
|
|
|
public:
|
2016-03-03 02:28:50 +08:00
|
|
|
// Global variable properties that must be passed to CUDA runtime.
|
|
|
|
enum DeviceVarFlags {
|
|
|
|
ExternDeviceVar = 0x01, // extern
|
|
|
|
ConstantDeviceVar = 0x02, // __constant__
|
|
|
|
};
|
|
|
|
|
2011-10-07 02:29:37 +08:00
|
|
|
CGCUDARuntime(CodeGenModule &CGM) : CGM(CGM) {}
|
|
|
|
virtual ~CGCUDARuntime();
|
|
|
|
|
|
|
|
virtual RValue EmitCUDAKernelCallExpr(CodeGenFunction &CGF,
|
|
|
|
const CUDAKernelCallExpr *E,
|
|
|
|
ReturnValueSlot ReturnValue);
|
2011-10-07 02:51:56 +08:00
|
|
|
|
2015-05-08 03:34:16 +08:00
|
|
|
/// Emits a kernel launch stub.
|
|
|
|
virtual void emitDeviceStub(CodeGenFunction &CGF, FunctionArgList &Args) = 0;
|
2019-02-14 10:00:09 +08:00
|
|
|
virtual void registerDeviceVar(const VarDecl *VD, llvm::GlobalVariable &Var,
|
|
|
|
unsigned Flags) = 0;
|
2015-05-08 03:34:16 +08:00
|
|
|
|
|
|
|
/// Constructs and returns a module initialization function or nullptr if it's
|
|
|
|
/// not needed. Must be called after all kernels have been emitted.
|
|
|
|
virtual llvm::Function *makeModuleCtorFunction() = 0;
|
|
|
|
|
|
|
|
/// Returns a module cleanup function or nullptr if it's not needed.
|
|
|
|
/// Must be called after ModuleCtorFunction
|
|
|
|
virtual llvm::Function *makeModuleDtorFunction() = 0;
|
2019-06-17 20:51:36 +08:00
|
|
|
|
|
|
|
/// Construct and return the stub name of a kernel.
|
|
|
|
virtual std::string getDeviceStubName(llvm::StringRef Name) const = 0;
|
2011-10-07 02:29:37 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Creates an instance of a CUDA runtime class.
|
|
|
|
CGCUDARuntime *CreateNVCUDARuntime(CodeGenModule &CGM);
|
|
|
|
|
2015-06-23 07:07:51 +08:00
|
|
|
}
|
|
|
|
}
|
2011-10-07 02:29:37 +08:00
|
|
|
|
|
|
|
#endif
|